Count the days? - 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)
+--- Thread: Count the days? (
/showthread.php?tid=524056)
Count the days? -
Don_Cage - 05.07.2014
Hi, I want to make it so if you've been offline for x ammount of days your stuff like house and vehicles will be automaticlly sold.
I was thinking it should work with just make a variable in the user account that will go ++ each day and be resetted too 0 everytime he login. How can I count the days and add ++ to the user's offline days once a new day comes??
Re: Count the days? -
Jack_Leslie - 05.07.2014
It would be pretty simple if you're using mysql, as mysql allows you to easily update a player's account whilst their offline. You'd need to have a timer in the script, that starts when the gamemode starts, and if the gamemode ever exits, save the current time, and reload from that time, in case of server crashes or server restarts. Then decide how often you want to add to the users offline time, and go from there.
Re: Count the days? -
Don_Cage - 05.07.2014
Can I still do it to an offline user without mysql?
Re: Count the days? -
Jack_Leslie - 05.07.2014
You could but it would be annoying and difficult.
Re: Count the days? -
BroZeus - 05.07.2014
here is an example
pawn Код:
LastLogin[MAX_PLAYERS];//on top
forward CheckLastLogin();//on top
OnPlayerDisconnect(playerid)
{
LastLogin[playerid] = gettime();
//now save variable LastLogin[playerid] into database
return 1;
}
OnGameModeInit()
{
SetTimer("CheckLastLogin",1000*60*5/*5 mins*/, true);//the timer
return 1;
}
public CheckLastLogin()
{
new var;//to store player's last login inside the loop
new store;//for calculation inside the loop
new c_time = gettime();// this is necessary now
//now here gt num of rows in players database
//run a loop line for(new i=0; i<=num_of_rows ; i++)
//now inside the loop load the LastLogin inside "var" variable
store= c_time - var;//insideloop
if(store >=(60*60*24*7)/*1 week*/)//inside loop
{
//the code to sell his stuff here
}
return 1;
}
you could learn about unix timestamps here
https://sampforum.blast.hk/showthread.php?tid=254915
this way may caz lag
there is one more way of doing it and that is to just do the similar thing in a php file which can be called with a timer inside game or outside game which would not caz possible lags
Re: Count the days? -
Don_Cage - 06.07.2014
What do you mean with "now here gt num of rows in players database" ?
EDIT: I allready have it saved in pinfo enum when the player last where online. Can I use that and just check it when the player login?
Re: Count the days? -
BroZeus - 06.07.2014
Quote:
Originally Posted by Don_Cage
What do you mean with "now here gt num of rows in players database" ?
EDIT: I allready have it saved in pinfo enum when the player last where online. Can I use that and just check it when the player login?
|
in pinfo enum only data of online player will be there there will be no data for an offline player that is offline of many days
so you will need to load data of all players in a loop checking there LastLogin varaible
Re: Count the days? -
Don_Cage - 06.07.2014
How do I loop the files in my userfolder? Both those who are off and online??
I don't understand that part.
Re: Count the days? -
Don_Cage - 06.07.2014
Bump
Re: Count the days? -
Don_Cage - 08.07.2014
Quote:
Originally Posted by Don_Cage
How do I loop the files in my userfolder? Both those who are off and online??
I don't understand that part.
|
bump