open.mp forum
[Pawn] Need assistance - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Need assistance (/showthread.php?tid=3584)



Need assistance - Cruncher - 2025-10-16

PHP Code:
if(strcmp(cmd"/resfacveh"true) == || strcmp(cmd"/rffv"true) == 0// by Mikkel Reimer
{
    if(IsPlayerConnected(playerid))
    {
        if(!IsACop(playerid))
{
    SendClientMessage(playeridCOLOR_GRAD1"  you are not authorized to use that command!");
    return 1;
}
new 
bool:unwanted[LSPDCars];
for(new 
player=0player<MAX_PLAYERSplayer++)
    {
            if(IsPlayerInAnyVehicle(player)) { unwanted[GetPlayerVehicleID(player)]=true; }
    }
for(new 
LSPDCars 1LSPDCars <= 25LSPDCars++)
{
if(!
unwanted[LSPDCars]) SetVehicleToRespawn(LSPDCars);
}
GetPlayerName(playeridsendernamesizeof(sendername));
format(stringsizeof(string), "SERVER: "COL_WHITE"All unused vehicles were respawned by Administrator %s."sendername);
SendClientMessageToAll(COLOR_YELLOW,string);
}
return 
1;



I keep getting error with the "bool:unwanted" line trying to work out another way to to detect and avoid respawning vehicles that dont have a driver
Any help or advise would be appreciated...


RE: Need assistance - Cappsy - 2025-10-18

Hey :)

I haven’t scripted in Pawn for years but im pretty sure the issue is that youre using a variable (LSPDCars) as an array size  Pawn doesnt allow dynamic array sizes at compile time, even in open.mp

The problem is caused by this line:
    new bool:unwanted[LSPDCars];

In Pawn, array sizes must be constant at compile time. That’s why you’re getting an error there.
To fix it, replace that with a constant or define a fixed size, for example:
    new bool:unwanted[26]; // or MAX_VEHICLES if you want it dynamic

Then adjust your loops accordingly.