Lag problem
#1

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?
Reply
#2

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
Reply
#3

WTF :S You're running a loop б 2000 in a loop б 500?? WTF? Ofcourse It lags...

The loop will run 500*2000=1000000 times.... -_-
Reply
#4

thanks, thats help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)