Code:
#include <a_samp>
#include <zcmd>
#include <sscanf>
#define COLOR_WHITE 0xFFFFFFFF
new VIP[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
checkPlayerVip(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
SendClientMessage(playerid, COLOR_WHITE, "You are logged in as a VIP.");
return 1;
}
CMD:freevip(playerid, arg[])
{
new dd, mm, yy;
getdate(yy, mm, dd);
if(VIP[playerid] == 1) return SendClientMessage(playerid, COLOR_WHITE, "Error: You are VIP already");
makePlayerVip(playerid, dd, mm+1, yy);
SendClientMessage(playerid, COLOR_GREEN, "Enjoy your free VIP USE /skin for vip commands");
return 1;
}
CMD:makevip(playerid, arg[])
{
new tdd, tmm, tyy, dd, mm, yy, id, str[128], name[32], pname[32];
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
if(sscanf(arg, "uiii", id, dd, mm, yy)) return SendClientMessage(playerid, COLOR_WHITE, "/makevip [playerid] [day of expiry] [month of expiry] [year of expiry]");
getdate(tyy, tmm, tdd);
makePlayerVip(id, dd, mm, yy);
GetPlayerName(playerid, name, 32);
GetPlayerName(playerid, pname, 32);
format(str, 128, "%s has made you VIP until %d/%d/%d", name, dd, mm, yy);
SendClientMessage(id, COLOR_WHITE, str);
format(str, 128, "You have made %s VIP until %d/%d/%d", pname, dd, mm, yy);
SendClientMessage(playerid, COLOR_WHITE, str);
return 1;
}
stock makePlayerVip(playerid, dd, mm, yy)
{
new fil[64], File:file, name[32], str[256];
GetPlayerName(playerid, name, 32);
format(fil, 64, "%s.ini", name);
if(fexist(fil)) fremove(fil);
file = fopen(fil, io_write);
format(str, 256, "%d|%d|%d", dd, mm, yy);
VIP[playerid] = 1;
fwrite(file, str);
fclose(file);
}
stock removePlayerVip(playerid)
{
new fil[64], name[32];
GetPlayerName(playerid, name, 32);
format(fil, 64, "%s.ini", name);
if(fexist(fil)) fremove(fil);
VIP[playerid] = 0;
}
stock checkPlayerVip(playerid)
{
new dd, mm, yy, fil[64], File:file, str[256], name[32], arr[4][32], f=0;
getdate(yy, mm, dd);
GetPlayerName(playerid, name, 32);
format(fil, 64, "%s.ini", name);
if(VIP[playerid] && !fexist(fil)) VIP[playerid] = 0;
if(fexist(fil))
{
file = fopen(fil, io_read);
fread(file, str);
fclose(file);
split(str, arr, '|');
if(dd > strval(arr[0]) && mm >= strval(arr[1]) && yy >= strval(arr[2]))
{
SendClientMessage(playerid, COLOR_WHITE, "Your VIP has been automatically expired.");
removePlayerVip(playerid);
f=1;
}
if(!f) VIP[playerid] = 1;
}
}
stock split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc))
{
if(strsrc[i] == delimiter || i == strlen(strsrc))
{
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}