SA-MP Forums Archive
[Tutorial] Automatic Expiry VIP Packages - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Automatic Expiry VIP Packages (/showthread.php?tid=597335)



Automatic Expiry VIP Packages - Tamy - 29.12.2015

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 VIP Variable:
Код:
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;
}
OnPlayerConnect
Код:
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;
	}
	
}
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;
}



Re: Automatic Expiry VIP Packages - Leopards - 29.12.2015

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


Re: Automatic Expiry VIP Packages - Tamy - 30.12.2015

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.


Re: Automatic Expiry VIP Packages - PuN1Sh3r - 30.01.2016

for gamemodes or Filterscript


Re: Automatic Expiry VIP Packages - Tamy - 30.01.2016

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.


Re: Automatic Expiry VIP Packages - biker122 - 30.01.2016

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..


Re: Automatic Expiry VIP Packages - TwinkiDaBoss - 30.01.2016

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;