SA-MP Forums Archive
Server 'freezes' when using a specific command - 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: Server 'freezes' when using a specific command (/showthread.php?tid=307719)



Server 'freezes' when using a specific command - Giovanni - 31.12.2011

I have created a command to unlock a vehicle. Here is what I got so far:

pawn Код:
CMD:unlock(playerid,params[])
{
    new Float:vx,Float:vy,Float:vz;
   
    foreach(SpawnedVehicle,i)
    {
        GetVehiclePos(VehicleInfo[i][vID],vx,vy,vz);
   
        if(IsPlayerInRangeOfPoint(playerid,4.0,vx,vy,vz))
        {
            if(VehicleInfo[i][vHasOwner] == true && strcmp(VehicleInfo[i][vOwner],PName(playerid),false) == 0)
            {
               
                if(VehicleInfo[i][vLocked] == 1)
                {
                    VehicleInfo[i][vLocked] = 0;
                    SetVehicleParamsEx(VehicleInfo[i][vID],MotorOn[i],0,0,VehicleInfo[i][vLocked],0,0,0);
                    GameTextForPlayer(playerid,"~w~Vehicle: ~g~Unlocked",2500,3);
                }else{
                    SendError(playerid,"This vehicle is already unlocked.");
                }
            }
        }
    }
    return 1;
}
I am using y_iteratek (newest version) and the iterators are getting filled up properly. But after I use this command the server freezes. That means I can not use any commands, or restart the server (over the console). I guess that's because it has to loop through all vehicles (MAX_VEHICLES), but I don't really know how to do it, so that it works.

(And I am pretty sure that this command causes the error, since the server only freezes when using it)


Re: Server 'freezes' when using a specific command - Dark_Kostas - 31.12.2011

pawn Код:
CMD:unlock(playerid,params[])
{
    new Float:vx,Float:vy,Float:vz;
   
    foreach(SpawnedVehicle,i)
    {
        printf("Looping at /unlock cmd. i = %d", i);

        GetVehiclePos(VehicleInfo[i][vID],vx,vy,vz);
   
        if(IsPlayerInRangeOfPoint(playerid,4.0,vx,vy,vz))
        {
            if(VehicleInfo[i][vHasOwner] == true && strcmp(VehicleInfo[i][vOwner],PName(playerid),false) == 0)
            {
               
                if(VehicleInfo[i][vLocked] == 1)
                {
                    VehicleInfo[i][vLocked] = 0;
                    SetVehicleParamsEx(VehicleInfo[i][vID],MotorOn[i],0,0,VehicleInfo[i][vLocked],0,0,0);
                    GameTextForPlayer(playerid,"~w~Vehicle: ~g~Unlocked",2500,3);
                }else{
                    SendError(playerid,"This vehicle is already unlocked.");
                }
                return 1;
            }
        }
    }
    SendError(playerid,"You are not close to any vehicle.");
    return 1;
}
Type /unlock and check console what happens with the "i" value. I think the problem is an endless loop that's why take a look what values "i" get.

BTW I also added you a "You are not close to any vehicle" message in case you want it.


AW: Server 'freezes' when using a specific command - Giovanni - 31.12.2011

Yes, it is indeed an endless loop. But how to stop that? Shall I add a break somewhere or what? And in the iterator are only 2 elements, I checked that with another printf.


Re: Server 'freezes' when using a specific command - Dark_Kostas - 31.12.2011

How do you create and then add to the iterator? And is the "i" going over MAX_VEHICLES(2000) value when using printf?


AW: Re: Server 'freezes' when using a specific command - Giovanni - 31.12.2011

Quote:
Originally Posted by Dark_Kostas
Посмотреть сообщение
How do you create and then add to the iterator? And is the "i" going over MAX_VEHICLES(2000) value when using printf?
It always stays on 0, that's what I don't understand.

This is how I add to it:

pawn Код:
for(new idx = 0; idx < sizeof(VehicleInfo) ; idx++)
{
    if(fexist(VehicleFile(idx)))
    {
        INI_ParseFile(VehicleFile(idx), "LoadVehicle_%s", .bExtra = true, .extra = idx);
       
        VehicleInfo[idx][vID] = CreateVehicle( ... );
        SetVehicleParamsEx(VehicleInfo[idx][vID],0,0,0,VehicleInfo[idx][vLocked],0,0,0);
        Iter_Add(SpawnedVehicle,VehicleInfo[idx][vID]);
        printf("[log] Spawned Vehicles: %d",Iter_Count(SpawnedVehicle));
    }
}
(@ OnGameModeInit)

pawn Код:
new Iterator:SpawnedVehicle<MAX_VEHICLES>;
pawn Код:
new VehicleInfo[MAX_VEHICLES][E_VEHICLE_DATA];




Note: When I use a normal for-loop for the unlock command it works, but foreach is faster so I prefere using it.


Re: Server 'freezes' when using a specific command - iPeanut - 31.12.2011

um....what kostas said


Re: Server 'freezes' when using a specific command - Kar - 31.12.2011

pawn Код:
for(new idx = 0; idx < sizeof(VehicleInfo) ; idx++)
{
    if(fexist(VehicleFile(idx)))
    {
        INI_ParseFile(VehicleFile(idx), "LoadVehicle_%s", .bExtra = true, .extra = idx);

        VehicleInfo[idx][vID] = CreateVehicle( ... );
        SetVehicleParamsEx(VehicleInfo[idx][vID],0,0,0,VehicleInfo[idx][vLocked],0,0,0);
        if(!Iter_IsIn(SpawnedVehicle, VehicleInfo[idx][vID]))
        {
            Iter_Add(SpawnedVehicle,VehicleInfo[idx][vID]);
        }
        printf("[log] Spawned Vehicles: %d",Iter_Count(SpawnedVehicle));
    }
}

//

#define Iter_IsIn(%0,%1) Iter_IsInInternal(YSI_gS%0,YSI_gA%0,(%1))
#define Itter_IsIn Iter_IsIn // Because I got the spelling of iterator wrong originally.

stock Iter_IsInInternal(start, array[], value)
{
    while (start != -1)
    {
        if (start == value)
        {
            return true;
        }
        start = array[start];
    }
    return false;
}



AW: Server 'freezes' when using a specific command - Giovanni - 31.12.2011

When I use your example code I get following error:

Код:
undefined symbol "YSI_gSSpawnedVehicle"
But the Iterator is defined, if I understood the error right. (The function is used after I create the Iterator)