timers mysql
#1

what's the chance for server crash by handling many timers at same time ?

It's for an roleplay server and I need to handle timers like

Experience for 1 hour playing
8 hours for leave a job
Time restriction on command's use like /b, /mp
And another ones i can't remember

So, what's the correct way to handle many timers at same time with a low chance for server crash ?
Reply
#2

Second and third ones can be handled with timestamps (gettime()). First one possibly too depending on how accurate it really needs to be. Timers can be avoided in lots of cases and are only really useful if something MUST happen after the set time. Command restrictions work as follows:

PHP код:
CMD:mycommand(playeridparams[])
{
    static 
lastExecutedTime[MAX_PLAYERS]; // static so remembers value

    
if(gettime() - lastExecutedTime[playerid] < 60)
    {
        
// send message about waiting
        
return 1;
    }
    
lastExecutedTime[playerid] = gettime();

    
// rest of command here
    
return 1;

Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Second and third ones can be handled with timestamps (gettime()). First one possibly too depending on how accurate it really needs to be. Timers can be avoided in lots of cases and are only really useful if something MUST happen after the set time. Command restrictions work as follows:

PHP код:
CMD:mycommand(playeridparams[])
{
    static 
lastExecutedTime[MAX_PLAYERS]; // static so remembers value
    
if(gettime() - lastExecutedTime[playerid] < 60)
    {
        
// send message about waiting
        
return 1;
    }
    
lastExecutedTime[playerid] = gettime();
    
// rest of command here
    
return 1;

Use char arrays in this so as the code is more optimised using regular array in this case just displays a bad programming structure and habits in you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)