SA-MP Forums Archive
Problem with cars - 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: Problem with cars (/showthread.php?tid=225357)



Problem with cars - Beginnercoder - 13.02.2011

Here is my code.

pawn Код:
if((strcmp("/race", cmdtext, true) == 0) || (strcmp("/race", cmdtext, true) == 0))
    {
        SetPlayerInterior(playerid,7);
        SendClientMessage(playerid, 0x00FFFFAA, "You've been teleported to Race.");
        SetPlayerCheckpoint(playerid, -1394.54,-243.56,1043.20, 13.0);
        new vehicleid = CreateVehicle(415,-1394.54,-243.56,1043.20, 180.0, -1, -1, -1);
        LinkVehicleToInterior(vehicleid,7);
        PutPlayerInVehicle(playerid,vehicleid, 0);
        return 1;
    }
My problem - When the player types /race it doesn't delete the car that was there before (what he used) so if the player types /race 5 times, there will be 5 cars there (in my case 5 cheetahs) so how do I make it so it deletes the current car and spawns you in a new one?


Re: Problem with cars - JaTochNietDan - 13.02.2011

You need to make a variable to track if the player has a made a vehicle or not already, then store the ID of the vehicle in that variable which you can later delete or do whatever you want with it, for example:

pawn Код:
new iSpawnedCar[MAX_PLAYERS] = -1;
pawn Код:
if(strcmp("/race", cmdtext, true) == 0)
{
    if(iSpawnedCar[playerid] != -1) DestroyVehicle(iSpawnedCar[playerid]);
    SetPlayerInterior(playerid,7);
    SendClientMessage(playerid, 0x00FFFFAA, "You've been teleported to Race.");
    SetPlayerCheckpoint(playerid, -1394.54,-243.56,1043.20, 13.0);
    iSpawnedCar[playerid] = CreateVehicle(415,-1394.54,-243.56,1043.20, 180.0, -1, -1, -1);
    LinkVehicleToInterior(iSpawnedCar[playerid],7);
    PutPlayerInVehicle(playerid,iSpawnedCar[playerid], 0);
    return 1;
}
Additionally I removed the completely un-needed additional strcmp check, not sure why you added that!


Re: Problem with cars - Beginnercoder - 13.02.2011

Thank you. That works 100%