[SOLVED] lags the server
#1

Hey,
Here's my code for vehicles respawn:
pawn Код:
if (strcmp(cmdtext, "/respawnvehicles", true) == 0 && pAdminLvl[playerid] >= 3)
    {
      SystemMsg(playerid,"Respawning all vehicles in server.. Please wait..");
    for(new v = 0; v < MAX_VEHICLES; v++)
        {
          for(new i = 0; i <MAX_PLAYERS; i++)
          {
            if(!IsPlayerInAnyVehicle(i))
            {
                SetVehicleToRespawn(v);
                }
            }
        }
        SystemMsg(playerid,"All vehicles has been respawned!");
        return 1;
    }
Earlier it respawned vehicles like in 5 - 10 seconds.. (The code was without IsPlayerInAnyVehicle check) EDIT: But IsPlayerInAnyVehicle doesn't help cause even if player is in vehicle, his vehicle gets respawned..
But now it takes about 25-35 seconds to respawn (vehicle count is almost same as it was before) and it lags the server... Why?


And BTW Why vehicles usually spawn in wrong place? I save them to spawn in parking lot but they spawn in front of the road... After /respawnvehicles, they spawn correctly

And I do not use any vehicle streamer!
Reply
#2

Use GetPlayerState with PLAYER_STATE_DRIVER, because IsPlayerInAnyVehicle lags a little, since it needs to check through ~200 vehicles times MAX_PLAYERS which is 40000 times
Reply
#3

Quote:
Originally Posted by dice7
Use GetPlayerState with PLAYER_STATE_DRIVER, because IsPlayerInAnyVehicle lags a little, since it needs to check through ~200 vehicles times MAX_PLAYERS which is 40000 times
I just saw that maybe IsPlayerInVehicle(i,v) would be ok.. I'll try that and then try yours and tell which was better.

EDIT: This code:
pawn Код:
if (strcmp(cmdtext, "/respawnvehicles", true) == 0 && pAdminLvl[playerid] >= 3)
    {
      SystemMsg(playerid,"Respawning all vehicles in server.. Please wait..");
    for(new v = 0; v < MAX_VEHICLES; v++)
        {
          for(new i = 0; i <MAX_PLAYERS; i++)
          {
            if(GetPlayerState(i) != PLAYER_STATE_DRIVER)
            {
                SetVehicleToRespawn(v);
                }
            }
        }
        SystemMsg(playerid,"All vehicles has been respawned!");
        return 1;
    }
Respawned vehicle I was in, and took about 30 seconds..
My code with IsPlayerInVehicle(i,v) Took about 10-15 seconds :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)