29.12.2015, 20:03
Hello there. I've seen some threads of people asking about an automatic system which would remove the VIP of a person after expiry date. So here is it.
Requirements:
Making a Command:
First of all, you'll need to create a command which would give out the VIP package like this.
checkPlayerVip:
Requirements:
- sscanf
- zcmd
- Create a VIP variable on top of your script
Код:
new VIP[MAX_PLAYERS];
First of all, you'll need to create a command which would give out the VIP package like this.
Код:
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; }
- It checks if the player is RCON admin.
- Gets the current date from the server (getdate)
- makePlayerVip is a stock function made by myself given below.
Код: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); }
- Stores name of both players in the variables and send them the messages.
- Under OnPlayerConnect, make a checkPlayerVip function so whenever a player connects to the server, system checks for his VIP package and expiry date.
Код:
public OnPlayerConnect(playerid) { checkPlayerVip(playerid); return 1; }
Код:
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; } }
- Gets servers date.
- Matches the servers date with users VIP expiry date.
- Takes away VIP if date > expiry date.
- Keeps the VIP if date < expiry date.
- removePlayerVIP code is given below
Код: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; }
- split function code is given below
Код: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; }
Код:
#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: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; }