[Tutorial] Stop conflict with cars on teleport.
#1

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.
Reply
#2

Or you can just do

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

Ok thanks.
I will just leave it how it is.
Reply
#4

Simple but useful thou
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)