SA-MP Forums Archive
VIP system help - 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: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: VIP system help (/showthread.php?tid=139849)



VIP system help - Jokerstyle - 06.04.2010

Hello!
I'm working on a VIP system right now, my problem is, I don't know how to script a function which automatically removes the VIP from the player after 1 month

Would be cool if you could help me =)


Re: VIP system help - Jay. - 06.04.2010

Why can't u just remove it urself saves time :P


Re: VIP system help - lolumadd - 06.04.2010

Create a file named viptime.ini inside the scriptfiles folder then copy this code:

BTW: This may not be an efficient way; just the first thing that came to my head :P

Код:
forward GiveVIPTime(playerid);
forward CheckVIPTime(playerid);

public GiveVIPTime(playerid) //use when he gets vip
{
new hour, minute, second, day,month,year;
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
new string[128];
format(string, sizeof(string), "%s", PlayerName);
mktime(hour,minute,second,day,month,year);
dini_Set("viptime.ini", string, month);
return 1;
}

public CheckVIPTime(playerid)
{
new hour, minute, second, day,month,year;
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
new string[128];
format(string, sizeof(string), "%s", PlayerName);
new result[64];
result = dini_Get("viptime.ini", string);
mktime(hour,minute,second,day,month,year);
if(strcmp(result, month, true) != 0)
{
dini_Unset("viptime.ini", string); //vip time ran out
}
return 1;
}

public OnPlayerConnect(playerid)
{
CheckVIPTime(playerid);
return 1;
}


stock mktime(hour,minute,second,day,month,year) {
	new timestamp2;

	timestamp2 = second + (minute * 60) + (hour * 3600);

	new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

	if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
			days_of_month[1] = 29; // Schaltjahr
		} else {
			days_of_month[1] = 28; // keins
		}
	
	new days_this_year = 0;
	days_this_year = --day;
	if(month > 1) { // No January Calculation, because its always the 0 past months
		for(new i=0; i<month-1;i++) {
			days_this_year += days_of_month[i];
		}
	}
	timestamp2 += days_this_year * 86400;

	for(new j=1970;j<year;j++) {
		timestamp2 += 31536000;
		if ( ((j % 4 == 0) && (j % 100 != 0)) || (j % 400 == 0) ) timestamp2 += 86400; // Schaltjahr + 1 Tag
	}

	return timestamp2;
}
Have fun!

Quote:
Originally Posted by ("GгNSTг")
Why can't u just remove it urself saves time :P
It doesnt save time, this is actually easier and this is a good help thread that he made because many other people will probably have the same question.


Re: VIP system help - Jokerstyle - 06.04.2010

Quote:
Originally Posted by lolumadd [cod5server.tk
]
Create a file named viptime.ini inside the scriptfiles folder then copy this code:

BTW: This may not be an efficient way; just the first thing that came to my head :P

Код:
forward GiveVIPTime(playerid);
forward CheckVIPTime(playerid);

public GiveVIPTime(playerid) //use when he gets vip
{
new hour, minute, second, day,month,year;
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
new string[128];
format(string, sizeof(string), "%s", PlayerName);
mktime(hour,minute,second,day,month,year);
dini_Set("viptime.ini", string, month);
return 1;
}

public CheckVIPTime(playerid)
{
new hour, minute, second, day,month,year;
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
new string[128];
format(string, sizeof(string), "%s", PlayerName);
new result[64];
result = dini_Get("viptime.ini", string);
mktime(hour,minute,second,day,month,year);
if(strcmp(result, month, true) != 0)
{
dini_Unset("viptime.ini", string); //vip time ran out
}
return 1;
}

public OnPlayerConnect(playerid)
{
CheckVIPTime(playerid);
return 1;
}


stock mktime(hour,minute,second,day,month,year) {
	new timestamp2;

	timestamp2 = second + (minute * 60) + (hour * 3600);

	new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

	if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
			days_of_month[1] = 29; // Schaltjahr
		} else {
			days_of_month[1] = 28; // keins
		}
	
	new days_this_year = 0;
	days_this_year = --day;
	if(month > 1) { // No January Calculation, because its always the 0 past months
		for(new i=0; i<month-1;i++) {
			days_this_year += days_of_month[i];
		}
	}
	timestamp2 += days_this_year * 86400;

	for(new j=1970;j<year;j++) {
		timestamp2 += 31536000;
		if ( ((j % 4 == 0) && (j % 100 != 0)) || (j % 400 == 0) ) timestamp2 += 86400; // Schaltjahr + 1 Tag
	}

	return timestamp2;
}
Have fun!

Quote:
Originally Posted by ("GгNSTг")
Why can't u just remove it urself saves time :P
It doesnt save time, this is actually easier and this is a good help thread that he made because many other people will probably have the same question.
I like the way you did it, but I got the following errors and warnings:
Код:
C:\Dokumente und Einstellungen\Dani\Desktop\GU\Server\sa-mp\GUDM\gamemodes\GUDM.pwn(6636) : error 035: argument type mismatch (argument 3)
C:\Dokumente und Einstellungen\Dani\Desktop\GU\Server\sa-mp\GUDM\gamemodes\GUDM.pwn(6648) : error 047: array sizes do not match, or destination array is too small
C:\Dokumente und Einstellungen\Dani\Desktop\GU\Server\sa-mp\GUDM\gamemodes\GUDM.pwn(6650) : error 035: argument type mismatch (argument 2)
C:\Dokumente und Einstellungen\Dani\Desktop\GU\Server\sa-mp\GUDM\gamemodes\GUDM.pwn(6659) : error 021: symbol already defined: "mktime"
The Lines:
Код:
Line 6636
dini_Set("viptime.ini", string, month);
Код:
Line 6648
result = dini_Get("viptime.ini", string);
Код:
Line 6650
mktime(hour,minute,second,day,month,year);
Код:
Line 6659
stock mktime(hour,minute,second,day,month,year) {



Re: VIP system help - lolumadd - 06.04.2010

Change:

Код:
dini_Set to dini_IntSet
Код:
dini_Get to dini_Int
Код:
new result[64]; to new result;



Re: VIP system help - Jokerstyle - 06.04.2010

Quote:
Originally Posted by lolumadd [cod5server.tk
]
Change:

Код:
dini_Set to dini_IntSet
Код:
dini_Get to dini_Int
Код:
new result[64]; to new result;
Thanks, but now I get this error:
C:\Dokumente und Einstellungen\Dani\Desktop\GU\Server\sa-mp\GUDM\gamemodes\GUDM.pwn(6651) : error 035: argument type mismatch (argument 1)

Line:
Код:
	if(strcmp(result, month, true) != 0)



Re: VIP system help - lolumadd - 07.04.2010

Change that to:

Код:
if(result != month)



Re: VIP system help - Jokerstyle - 07.04.2010

I fixed the errors, but If I give someone VIP status, it just writes down this in the viptime.ini file:

Код:
Name: 0
It's always 0.
Would be cool if you know how to fix it =)


Re: VIP system help - Jokerstyle - 11.04.2010

Sorry for the bump but it's really important!


Re: VIP system help - lolumadd - 11.04.2010

Search for the function "GetDate()" then replace the "mktime" function with the "GetDate()" function.


EDIT: The GetDate function is default: Do this:

Код:
new year, month, day;
getdate(year, month, day);
Replace that for the "mktime" function.

This is the complete code:

Код:
forward GiveVIPTime(playerid);
forward CheckVIPTime(playerid);

public GiveVIPTime(playerid) //use when he gets vip
{
new year, month, day;
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
new string[128];
format(string, sizeof(string), "%s", PlayerName);
getdate(year, month, day);
dini_IntSet("viptime.ini", string, month);
return 1;
}

public CheckVIPTime(playerid)
{
new year, month, day;
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
new string[128];
format(string, sizeof(string), "%s", PlayerName);
new result;
result = dini_Int("viptime.ini", string);
getdate(year, month, day);
if(result != month)
{
dini_Unset("viptime.ini", string); //vip time ran out
}
return 1;
}

public OnPlayerConnect(playerid)
{
CheckVIPTime(playerid);
return 1;
}