SetTimer vs SetTimerEx
#1

I need some advices. For example: I have a minigame in my server. When player joins it, variable stores his info, let's call it InMinigame. So, I want to know, whitch way is better:

1) Have timer, whitch were started on gamemode starts, has loop throught all players, checks is player in minigame and doe's some code.
2) Use SetTimerEx, and do some code for that player, while he is in minigame.

I am a little confused about it, because if I'll use first methot, I'll have timer whitch runs everytime and checks all connected players, and if I'll use second - there will be as much timers started as players joined in minigame ( fail english ).
Reply
#2

i think 2 will cause less lagg.

stupid 2 minutes before posting -.-
Reply
#3

Try to avoid loops unless they are needed, I would go for the latter.
Reply
#4

If I want to know how many players are in minigame, increase global variable when player joins and use it when i need total players in minigame is better than loop throught players and count them?
Reply
#5

if your using foreach, then its ok. if not.. well idk
Reply
#6

you gotta think how many functions are going off per player and what they are, I'm sure it'd be fine to have one timer and loop but if you have heaps of functions inside then you should use a timer per player
Reply
#7

Quote:
Originally Posted by cessil
Посмотреть сообщение
you gotta think how many functions are going off per player and what they are, I'm sure it'd be fine to have one timer and loop but if you have heaps of functions inside then you should use a timer per player
More timers cause more lag, even if the functons they call don't retain that much code. I remember in 0.2x I locked up my server when I had 24 timers running simeltanously to move objects, when I was with serverFFS also - before they turned to shit.

I'd recommend option 1, I always use it.
Reply
#8

I disagree, timers hardly do anything, it's whats in the functions they call.
I just tried
pawn Код:
forward nothing();
public nothing()
{
    return 1;
}

public OnGameModeInit()
{
    for(new i=0;i<10000;i++)
    {
        SetTimer("nothing",100 + random(900),1);
    }
and had no noticeable lag on my laptop
Reply
#9

ok, thanks
Reply
#10

cessil, the lag was caused by MoveObject in those timers, because MoveObject had its own timer in itself for the limit it should take to move an object.

But other resource-intensive functions would cause this - just returning 1 would obviously be meaningless.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)