SA-MP Forums Archive
[Tutorial] Stop conflict with cars on teleport. - 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: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Stop conflict with cars on teleport. (/showthread.php?tid=230467)



Stop conflict with cars on teleport. - captainjohn - 23.02.2011

Hi, I found this useful so I thought I would share it with you.

If you are a beginner you won't know all these useful tips.
So on this small tutorial I am going to show you how to not have cars spamming your map when you teleport to the location.

Take a look at this command,

pawn Code:
if((strcmp("/blueberry", cmdtext, true) == 0) || (strcmp("/bb", cmdtext, true) == 0))
    {    
        SendClientMessage(playerid, 0x00FFFFAA, "You've been teleported to Blueberry.");      
        new vehicleid = CreateVehicle(415,-12.69693,1481.717,12.75, 180.0, -1, -1, -1);
        PutPlayerInVehicle(playerid,vehicleid, 0);
        return 1;
    }
This will put the player in a Cheetah when the player types /blueberry. When the player types it again, the car he got when he teleported there the first time, will just be sat laying there.
So if the player types /blueberry 10 times, there will be 10 cars there (in my case a cheetah)

So to fix that we do this.

First we start off with the variables.
This variable detects if the player has already made a vehicle or not already.
pawn Code:
//Put this varible near the top of your script, with all other variables - you can delete this green line after
new iSpawnedCar[MAX_PLAYERS] = -1;
Now for the new code.

pawn Code:
//Put this under OnPlayerCommandText - Delete this green line after.
if ((strcmp("/blueberry", cmdtext, true) == 0) || (strcmp("/bb", cmdtext, true) == 0))
    {
        if(iSpawnedCar[playerid] != -1) DestroyVehicle(iSpawnedCar[playerid]);
        SendClientMessage(playerid, 0x00FFFFAA, "You've been teleported to Blueberry.");
        iSpawnedCar[playerid] = CreateVehicle(415,-12.69693,1481.717,12.75, 180.0, -1, -1, -1);
        PutPlayerInVehicle(playerid,iSpawnedCar[playerid], 0);
        return 1;
    }
A few ID to know.
The 415 found on this line here, is the ID of the car.
You can find the ID's here https://sampwiki.blast.hk/wiki/Category:Vehicle
pawn Code:
iSpawnedCar[playerid] = CreateVehicle(415,-12.69693,1481.717,12.75, 180.0, -1, -1, -1);
Wasn't much of a tutorial.
Hope I helped.


Re: Stop conflict with cars on teleport. - alpha500delta - 23.02.2011

Or you can just do

pawn Code:
new vehicle;
vehicle = GetPlayerVehicleID(playerid);
DestroyVehicle(vehicle);
Instead of that code for just one car


Re: Stop conflict with cars on teleport. - captainjohn - 25.02.2011

Ok thanks.
I will just leave it how it is.


Re: Stop conflict with cars on teleport. - Kerlan - 15.06.2012

Simple but useful thou


Respuesta: Stop conflict with cars on teleport. - [DOG]irinel1996 - 23.06.2012

Or don't create vehicle and SetVehiclePos.
If you want give him a vehicle yes or yes, yes it's a good way.