Will this cause lagg?
#1

Since having big code in OnPlayerUpdate will cause your server to lagg, I decided to make my own with a timer and a function.
But the problem is, I want to use playerid in it so I have to use settimerex. But I can only put that under onplayerconnect (gamemodeinit doesnt have playerid)
My question is: Will it cause lagg? Because it creates a new timer for every player in the server?
And if it causes lagg, what can I do to make it better?

My code:
pawn Код:
//On top:
new playerupdatetimer[MAX_PLAYERS];
forward PlayerUpdate(playerid);


// OnPlayerConnect:
playerupdatetimer[playerid] = SetTimerEx("PlayerUpdate", 450, 1, "i", playerid);

//OnPlayerDisconnect:
KillTimer(playerupdatetimer[playerid]);

//The UpdatePlayer function
public PlayerUpdate(playerid)
{
return 1;
}
Thanks!
Reply
#2

Depends what you are doing in that timer, and yes, it probably will.
Reply
#3

pawn Код:
public PlayerUpdate(playerid)
{
  if(IsPlayerInAnyVehicle(playerid))
    {
      new Float:VehHP;
      new veh;
      veh = GetPlayerVehicleID(playerid);
        GetVehicleHealth(veh, VehHP);
        if(VehHP < 500)
        {
            SetVehicleHealth(GetPlayerVehicleID(playerid), 2000);
        }
    }
    return 1;
}
Example of something I would put in.
And things for some kind of checkpoint streamer.
Reply
#4

why not just run this under onplayerupdate or run it like 2000 instead of 450 it wouldnt make much diffrent but would save lag
Reply
#5

Because if I make a big function (and I will) under onplayerupdate, It will cause a lot of lagg, so I made a custom one that doesnt check as often as the normal onplayerupdate. But I think ill have to run it higher then 450, yea
Reply
#6

OnPlayerUpdate won't cause lag if you're going to use simple functions in it, but if you're going to use file functions (let's take saving for example) then it will cause lag.
Reply
#7

If you're going to be making frequent timers, then I suggest you use global temporary variables.

pawn Код:
new Float:gTempFloat[3];
public frequenttimer(playerid)
{
  GetPlayerPos(playerid,gTempFloat[0],gTempFloat[1],gTempFloat[2]);
}
That way you're not creating the variable, you're just re-using it.
Reply
#8

@ Don Corelli:
If i'll use it to make a checkpoint streamer and vehicle fix and lots of other things (but no filesaving) will onplayerupdate not cause lag? cause in that case i will use the default onplayerupdate.

@ Joe Staff:
i will do that, thanks.
Reply
#9

Quote:
Originally Posted by [ST
∂υтўнвαѕ ]
@ Don Corelli:
If i'll use it to make a checkpoint streamer and vehicle fix and lots of other things (but no filesaving) will onplayerupdate not cause lag? cause in that case i will use the default onplayerupdate.
Depends what kind of vehicle fix are you going to use? Don't use big loops inside this callback!
Reply
#10

like the one I posted above. I think i will just try out what works best sometime tomorrow. im going to sleep now. thanks for your help guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)