VIP system help
#1

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 =)
Reply
#2

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

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.
Reply
#4

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) {
Reply
#5

Change:

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

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)
Reply
#7

Change that to:

Код:
if(result != month)
Reply
#8

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 =)
Reply
#9

Sorry for the bump but it's really important!
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)