Lag problem - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Lag problem (
/showthread.php?tid=170009)
Lag problem -
vection - 21.08.2010
i have this command:
pawn Код:
stock GetClosestVehicle(playerid) //
{
new car, Float:ang;
car = -1;
ang = 9999.9999;
for(new i = 0; i < MAX_PLAYERS; i++)
for(new v = 0; v < MAX_VEHICLES; v++)
{
#define INVALID_ID (0xFFFF) //65535
if(!IsPlayerConnected(i) && v == INVALID_ID) continue;
if(!IsPlayerInVehicle(i, v))
{
new Float:X, Float:Y, Float:Z;
GetVehiclePos(v, X, Y, Z);
if(ang > GetDistanceBetwinPoint(playerid, X, Y, Z))
{
ang = GetDistanceBetwinPoint(playerid, X, Y, Z);
car = v;
}
}
}
return car;
}
When i use this command for example to /lock, the server just lagged for 10 seconds .
[ i got only 30 vehicles in the server.]
how i can fix it?
Re: Lag problem -
papagei9 - 21.08.2010
pawn Код:
for(new v = 0; v < MAX_VEHICLES; v++)
{
That's the shit...
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
and that's the shit too
MAX_VEHICLES is defined as 2000...
on the top of your script:
#undef MAX_VEHICLES
#define MAX_VEHICLES 200 //new max-amount of vehicles.
#undef MAX_PLAYERS
#define MAX_PLAYERS 100 // new max-amount of players
Re: Lag problem -
Mike Garber - 21.08.2010
WTF :S You're running a loop б 2000 in a loop б 500?? WTF? Ofcourse It lags...
The loop will run 500*2000=1000000 times.... -_-
Re: Lag problem -
vection - 21.08.2010
thanks, thats help.