[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


Messages In This Thread
Stop conflict with cars on teleport. - by captainjohn - 23.02.2011, 16:36
Re: Stop conflict with cars on teleport. - by alpha500delta - 23.02.2011, 18:12
Re: Stop conflict with cars on teleport. - by captainjohn - 25.02.2011, 15:11
Re: Stop conflict with cars on teleport. - by Kerlan - 15.06.2012, 16:20
Respuesta: Stop conflict with cars on teleport. - by [DOG]irinel1996 - 23.06.2012, 15:54

Forum Jump:


Users browsing this thread: 1 Guest(s)