Lag calculation
#1

I want to create some time function with unix timestamp, Lets say time is in regard to hours, So i need to do sumthing like if the time limit give to a player i 1 hour, Instead of checking time onplayerconnect (coz they can exploit time limit by never logging off atleast some time) can i use the function onplayerupdate , but im afraid it may cause some lag (not sure) will it cause? any solution? And how many timers can be used without server being lagged
Reply
#2

Depends on your server spec and network.
Reply
#3

No just take it as some average common server
Reply
#4

So you want to check a variable, every update for every player?

If its just a single if statement, it probally wouldn't cause lagg, but you'd have to think for yourself, "is the check nessercary to be done every update?" the server updates a player approximately 32 times in a second. You're probally better off, storing the current time in a variable when the player logs on, and then have a timer running that checks every player every hour.

I mean a timer, that starts when the gamemode starts, it just compares the stored time for every player, against a maximum online time, you set before.
Reply
#5

@Playbox, I use unix timestamp , So if calculate the time left and set a timer for it, Then naturally the timerwould stop when player logs off, Thats the problem , it was okay if it is matter of days, but it is in terms of hours so thats where i have a problem, Got any idea for this?
Reply
#6

Use gettime(); when a player logs in. Then the timer that started at OnGameModeInit().

What this does, is get the unix timestamp, which is the ammount of seconds since June 1970.

It will compare the current ammount of seconds, with the one stored before, then the difference is the online time in seconds, compare that to 3600 which is one hour, and there you go.

pawn Код:
//Addition to your OnPlayerConnect
OnPlayerConnect(playerid)
{
   TheStoredTime[playerid] = gettime();
}

//That you put at OnGameModeInit.
SetTimer("TheTimer", 3600, true);
//--------

//This you put at the top for example
new TheStoredTime[MAX_PLAYERS];
//------------


//The timer
public TheTimer()
{
    foreach(Player, i)
    {
        if(gettime() - TheStoredTime[i] >= 3600) //3600 is one hour in seconds
        {
            // do something when he is online for a certain time
        }
    }
}
Reply
#7

You didn't get my point, I already knew how to do that but, When the players disconnects before the period of 1 hr the timer naturally is stopped. So its possible to exploit

P.S:- How can i get the time left in a timer? So that i can substract it from the storedtime and save it to a file
Reply
#8

The timer keeps running, considering its not bound to a player..

You can store the time when the player logs of, you just do the same thing as you do inside the timer, you store the amount of seconds in a variable and save that to a file. Then you use that the next time a player logs in.
Reply
#9

Yah it is supposed to bound to playerid, And how can get time left in a timer?
Reply
#10

Why would you bound it to a player? The timer just checks if a player is online for 3600 seconds every hour.

When the player disconnects you just use, gettime again, you compare it against the time you stored when he logged in, and there you have the online seconds. You store it somewhere, and use it when he logs in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)