· 10 years ago · Sep 08, 2016, 08:50 PM
1/*
2*
3* SQL database
4*
5*/
6
7/*
8
9CREATE TABLE IF NOT EXISTS `VIP` (
10
11 `PlayerID` INT(24) NOT NULL,
12 `Level` INT(24) NOT NULL,
13 `Granted` INT(24) NOT NULL,
14 `Expiry` INT(24) NOT NULL,
15
16 PRIMARY KEY(`PlayerID`)
17);
18ALTER TABLE `VIP` ADD FOREIGN KEY(`PlayerID`) REFERENCES `ID`(`players`) ON UPDATE CASCADE ON DELETE CASCADE;
19
20*/
21
22/*
23*
24* PAWN script
25*
26*/
27
28public OnPlayerConnect(playerid)
29{
30 CheckVIP(playerid);
31}
32
33CheckVIP(playerid)
34{
35 mysql_format(mysql, query, sizeof(query), "SELECT Expiry FROM VIP WHERE PlayerID = %d", pData[playerid][ID]);
36 mysql_tquery(mysql, query, "f_CheckVIP", "i", playerid);
37}
38
39forward f_CheckVIP();
40public f_CheckVIP()
41{
42 if(cache_get_row_count() > 0)
43 {
44 pData[playerid][VIPExpiry] = cache_get_field_content_int(0, "Expiry");
45
46 if(gettime() < pData[playerid][VIPExpiry])
47 {
48 pData[playerid][VIP] = 0;
49 SendClientMessage(playerid, COLOR_WHITE, "{ff387a}[Admin]:{ffffff} Your VIP has expired.");
50
51 new query[40];
52
53 mysql_format(mysql, query, sizeof(query), "DELETE FROM VIP WHERE PlayerID = %d", pData[playerid][ID]);
54 mysql_tquery(mysql, query, "", "");
55 }
56 }
57}
58
59CMD:setvip(playerid, params[])
60{
61
62 if(pData[playerid][Admin] < 6 && !IsPlayerAdmin(playerid))
63 return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]:{ffffff} You are not authorized to use this command.");
64
65 new lookupid, level, days;
66
67 if(sscanf(params, "uii", lookupid, level, days))
68 return SendClientMessage(playerid, COLOR_WHITE, "{ff387a}[Admin]:{ffffff} /setvip [ID | Name] [level]");
69
70 if(pData[lookupid][VIP] > pData[playerid][VIP])
71 return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff}You are not authorized to use this command.");
72
73 if(5 < level < 0)
74 return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]:{ffffff} You can only set levels 1 to 5.");
75
76 if(!IsPlayerConnected(lookupid))
77 return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]{ffffff} This player is not connected.");
78
79 if(days < 1)
80 return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]{ffffff} Invalid amount of days.");
81
82 new str[100];
83
84 if(level < pData[lookupid][VIP])
85 {
86 format(str, sizeof(str), "{ff387a}[Admin]:{ffffff} %s (ID:%d) has demoted you to VIP level %d!", GetName(playerid), playerid, level);
87 SendClientMessage(lookupid, COLOR_WHITE, str);
88
89 format(str, sizeof(str), "{ff387a}[Admin]:{ffffff} You have demoted %s (ID:%d) to VIP level %d!", GetName(lookupid), lookupid, level);
90 SendClientMessage(playerid, COLOR_WHITE, str);
91 }
92 else
93 {
94 format(str, sizeof(str), "{ff387a}[Admin]:{ffffff} %s (ID:%d) has promoted you to VIP level %d!",GetName(playerid), playerid, level);
95 SendClientMessage(lookupid, COLOR_WHITE, str);
96
97 format(str, sizeof(str),"{ff387a}[Admin]:{ffffff} You have promoted %s (ID:%d) to VIP level %d!",GetName(lookupid),lookupid,level);
98 SendClientMessage(playerid, COLOR_WHITE, str);
99 }
100 pData[lookupid][VIP] = level;
101 VIP_SaveData(lookupid, days);
102 return true;
103}
104
105VIP_SaveData(playerid, days)
106{
107 // (days * 24 * 60 * 60) converts the amount of days to seconds
108 // gettime returns the current date in seconds - allows for easy calculations
109 pData[playerid][VIPGranted] = gettime();
110 pData[playerid][VIPExpiry] = (pData[playerid][VIPGranted] + ((((days * 24) * 60) * 60)));
111
112 new query[128];
113
114 mysql_format(mysql, query, sizeof(query), "INSERT INTO VIP (`ID`, `Level`, `Granted`, `Expiry`) VALUES (%d, %d, %d, %d)",
115 pData[playerid][ID], pData[playerid][VIP], pData[playerid][VIPGranted], pData[playerid][VIPExpiry]);
116
117 mysql_tquery(mysql, query, "", "");
118}