Count the days?
#1

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??
Reply
#2

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

Can I still do it to an offline user without mysql?
Reply
#4

You could but it would be annoying and difficult.
Reply
#5

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

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

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

How do I loop the files in my userfolder? Both those who are off and online??
I don't understand that part.
Reply
#9

Bump
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)