SA-MP Forums Archive
help with car spawning - 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: help with car spawning (/showthread.php?tid=349103)



help with car spawning - San1 - 07.06.2012

i made a car spawn in my gamemode with like car name /greenwood
it spawns but how i make it where when i spawn another the vehicle destoys ur last one
also how to destroy that spawned vehicle OnVehicleDeath
using strcmp command processer


Re: help with car spawning - kaisersouse - 07.06.2012

So CreateVehicle returns a value. You need to assign that value to something like playercar[playerid]

Код:
playercar[playerid] = CreateVehicle(etc so forth);
To destroy it:

Код:
if(playercar[playerid] != INVALID_VEHICLE_ID)
{
    DestroyVehicle(playercar[playerid]);
    playercar[playerid] = INVALID_VEHICLE_ID;
}
You can add the destroy code to the beginning of your command, and in OnVehicleDeath (sort-of)

OnVehicleDeath:
Код:
for(new i; i < MAX_PLAYERS; i++)
{
    if(playercar[i] == vehicleid)
    {
        DestroyVehicle(playercar[i]);
        playercar[i] = INVALID_VEHICLE_ID;
        break; //(or would return be better?)
    }
}
EDIT: make sure you are destroying the vehicle in OnPlayerDisconnect too, or you'll have orphans.