[Tutorial] Teleporting vehicles when you teleport
#1

Special Teleports



Hey, Well i found this really useful for my server, I thought I'd share it with you ^^

Know how annoying it is when you teleport to a location and your vehicle doesn't come with you?,
Even worse, When your passenger can teleport you.

Well, This tutorial will teach you exactly how to make a teleport, which teleports your vehicle and doesn't allow
Passengers to teleport while they're in your vehicle.

Lets begin.

First we need to create the body of the command

So under
pawn Код:
OnPlayerCommandText
, or any of your other commands add this:

pawn Код:
if (strcmp("/teleport", cmdtext, true) == 0)
    {
       
        return 1;
    }
Okay, this will trigger the command, when you type,
Код:
/teleport
, or whatever you named it.

Now lets create the command.

Right, we must now check if the player is a passenger.

Add this under your command:

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
This will check if the player is a passenger of a vehicle.

Now, lets add something, if he is the passenger.

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)[/code]
{
    SendClientMessage(playerid,color,"You must be the driver!");//Make sure you've defined your chosen colour
 
}
You can change your message if you want.

Now that we've checked if the player is a passenger.
We can now check if he is the driver or on foot, will do this by using
pawn Код:
else
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)[/code]
{
    SendClientMessage(playerid,color,"You must be the driver!");//Make sure you've defined your chosen colour
 
}
else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || PLAYER_STATE_ONFOOT)
{


}
Okay, we just checked if the player was the driver or on foot, Again will return something, this time the teleport!.

We must now create a variable, to store the players vehicle in.

Add this between the brackets:

pawn Код:
else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || PLAYER_STATE_ONFOOT)
{
   new getv;
   
}
You can name that variable anything you want.

Okay, now that we have created are variable, lets get the players vehicle!

Add this under new getv;

pawn Код:
else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || PLAYER_STATE_ONFOOT)
{
   new getv;
   getv = GetPlayerVehicleID(playerid);
   
}
Now we just used getv to get the players vehicle, the variable we created earlier in the tutorial.

Will now move on to the actual teleport.

under
pawn Код:
getv = GetPlayerVehicleID(playerid)
add:

pawn Код:
else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || PLAYER_STATE_ONFOOT)
{
   new getv;
   getv = GetPlayerVehicleID(playerid);
   SetPlayerPos(playerid,x,y,z)//Change x,y,z to your teleport coords.
   SetVehiclePos(getv,x,y,z)//Again change x,y,z to your teleport coords, must be the same as SetPlayerPos!
   
}
Okay, we just set the players and vehicles pos, YOU MUST CHANGE THE X,Y,X TO YOUR COORDS, ELSE IT WONT WORK!

Now, to finish off, lets put the player in his vehicle, using
pawn Код:
PutPlayerInVehicle
Under the
pawn Код:
SetPlayerPos and SetVehiclePos
add:

pawn Код:
PutPlayerInVehicle(playerid,getv,0);
This will put the player in his vehicle when he teleports

Done!, If you done this correctly, your command should look similar to this:


pawn Код:
if (strcmp("/teleport", cmdtext, true) == 0)
    {  if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
       {
          SendClientMessage(playerid,color,"You must be the driver");
       }
       else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT || PLAYER_STATE_DRIVER)
       {
       new getv = GetPlayerVehicleID(playerid);
       SetVehiclePos(getv,-2337.2236,-1650.2164,483.7031);
       SetPlayerPos(playerid,-2337.2236,-1650.2164,483.7031);
       PutPlayerInVehicle(playerid,getv,0);
       }
       return 1;
    }

Hope this helped and if i failed, please say so |:

SparkZ_
Reply


Messages In This Thread
[TUT]Teleports - My special way - by SparkZ_ - 03.12.2010, 18:15
Re: Teleporting vehicles when you teleport - by SparkZ_ - 04.12.2010, 08:43
Re: Teleporting vehicles when you teleport - by Julian12345 - 04.12.2010, 17:40
Re: Teleporting vehicles when you teleport - by SparkZ_ - 04.12.2010, 17:41
Re: Teleporting vehicles when you teleport - by Jantjuh - 07.12.2010, 17:39
Re: Teleporting vehicles when you teleport - by Hiukuss - 08.12.2010, 14:36
Re: Teleporting vehicles when you teleport - by SparkZ_ - 08.12.2010, 18:25
Re: Teleporting vehicles when you teleport - by olabv - 14.12.2010, 22:01
Re: Teleporting vehicles when you teleport - by Tee - 15.12.2010, 03:39
Re: Teleporting vehicles when you teleport - by Ehab1911 - 15.12.2010, 10:52

Forum Jump:


Users browsing this thread: 1 Guest(s)