SA-MP Forums Archive
My command /rac made too big lag on server - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: My command /rac made too big lag on server (/showthread.php?tid=575688)



My command /rac made too big lag on server - ilepopivanov - 29.05.2015

When I type /rac on my server it's freeze server and unfreeze after 2-3 minutes :/. I have around 120 vehicles

PHP код:
YCMD:rac(playeridparams[], help)
{
    if(
PlayerInfo[playerid][pAdmin] >= 1336)
    {
        new 
string[135];
        if(
LoginPanel[playerid] == 0) return SCM(playerid,-1"{970004}GRESKA:{FFFFFF}Nemozete da ja koristete ovaa komanda.");
        new 
PID GetPlayerPoolSize();
        for(new 
i<= PIDi++)
        {
            if(
IsPlayerInAnyVehicle(i))
            {
                new 
vid GetPlayerVehicleID(i);
                
ZARAC[vid] = 1;
            }
        }
        for(new 
vehicleidvehicleid MAX_VEHICLESvehicleid++)
        {
            if(
ZARAC[vehicleid] == 0){ SetVehicleToRespawn(vehicleid);}else ZARAC[vehicleid] = 0;
        }
        
format(stringsizeof(string), "{13A9E1}|ADMINI| %s gi respawn site vozila na serverot."ZemiIme(playerid));
        
AdminGMChat(string);
    }
    return 
1;

Sorry for bad english :!


Re: My command /rac made too big lag on server - Konstantinos - 29.05.2015

It can be improved a lot by using foreach.

"Player" iterator is still much faster than using GetPlayerPoolSize.

About the vehicles, I create/destroy vehicles only in the gamemode so I've created an iterator called "Vehicle" and everytime a vehicle is created, I add it to the iterator and remove it when it's get destroyed. By that, if the server has 5 created vehicles, it will just loop 5 times ONLY instead of 2000.


Re: My command /rac made too big lag on server - ilepopivanov - 09.06.2015

PHP код:
new PVID GetVehiclePoolSize();
    for(new 
vehicleidvehicleid <= PVIDvehicleid++)
    {
         if(
ZARAC[vehicleid] == 0){ SetVehicleToRespawn(vehicleid), print("aa");}else ZARAC[vehicleid] = 0;
    } 



Re: My command /rac made too big lag on server - ilepopivanov - 09.06.2015

WOW Wait a scnd.
I tried like this and not any lag on server and very fast loop!! I see with print
I thnik SetVehicleToRespawn mades the lag..

PHP код:
YCMD:test(playeridparams[], help)
{
        new 
PVID GetVehiclePoolSize();
        for(new 
vehicleidvehicleid <= PVIDvehicleid++)
        {
            print(
"aa");
        }

EDIT: Yap. SetVehicleToRespawn make lag :/