[Tutorial] Automatic Expiry VIP Packages
#1

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:
  • sscanf
  • zcmd
Making VIP Variable:
  • Create a VIP variable on top of your script
Код:
new VIP[MAX_PLAYERS];
Making a Command:

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.
OnPlayerConnect
  • 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;
}
checkPlayerVip:
Код:
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;
    }
Full 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: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;
}
Reply
#2

i want this cmd like this /freevip when everyone login than he will type /freevip and than he will get 1 month vip after 1 month it will expire if u help me in it than thankyou i will give you repution i already have /makevip cmd

help me in this topic

https://sampforum.blast.hk/showthread.php?tid=597329
Reply
#3

Quote:
Originally Posted by Leopards
Посмотреть сообщение
i want this cmd like this /freevip when everyone login than he will type /freevip and than he will get 1 month vip after 1 month it will expire if u help me in it than thankyou i will give you repution i already have /makevip cmd

help me in this topic

https://sampforum.blast.hk/showthread.php?tid=597329
I have posted the code in your thread, tell me if you need further help.
Reply
#4

for gamemodes or Filterscript
Reply
#5

Quote:
Originally Posted by PuN1Sh3r
Посмотреть сообщение
for gamemodes or Filterscript
I'd suggest to make something like this in gamemode, but it's a general tutorial on how to make something like this, so it's totally up to you whether you use in your gamemode or filterscript.
Reply
#6

Why not timestamps? They're too awesome, and are also pretty easily usable.. But anyway, good job.

Note: I might create a tutorial with timestamps..
Reply
#7

Good tutorial but use timestamps...

Its 1000x easier and faster.

PHP код:
CMD:setvip(playerid,params[]) {
    new 
sPlayer,Time;
    if(
sscanf(params,"ui",sPlayer,Time)) return Msg(playerid,COLOR_RED,"Usage: /setvip [playerid] [days]");
    
    if(
Time <= 0) return Msg(playerid,COLOR_RED,"Time cannot be equal to 0 or go bellow it");
    if(
sPlayer == INVALID_PLAYER_ID) return Msg(playerid,COLOR_RED,"Invalid player");
    
    new 
finalcalc = (Time*3600)+gettime(); /* 3600 seconds per day + currenttime, it will give us until when they have to be VIP*/
    
PlayerInfo[playerid][VIPTime] = finalcalc//store the variable
    
PlayerInfo[playerid][VIPLevel] = 1//optional, set player VIP level or something
    
return true;
}
public 
OnPlayerConnect(playerid) {
    
//load the PlayerInfo[playerid][VIPTime]
    
new currentTime gettime();
    if(
currentTime >= PlayerInfo[playerid][VIPTime]) { //if current time is bigger than the time they should be VIP for.
        
Msg(playerid,COLOR_RED,"Your VIP has expired. Please consider purchasing more");
        
PlayerInfo[playerid][VIPLevel] = 0;
    }
    return 
true;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)