[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
#2

Any comments? ;(

It's been since last night i wrote this and still no replys :/
Reply
#3

Very nice tutorial SparkZ_!
Reply
#4

Quote:
Originally Posted by Julian12345
Посмотреть сообщение
Very nice tutorial SparkZ_!
Thanks, glad you liked it!
Reply
#5

nice!!!! I always had problems with it!

thankx!!!
Reply
#6

Man, no new replies? :S
Great tutorial
Will be helpful
Cause i got an area where you find the car you want, but its on top of a skyscraper :P
Thanks
Reply
#7

No problem guys
Reply
#8

epic
Reply
#9

Very useful and nice i could not figure it out and its so simple.

I was thinking deleting the vehicle and creating a new one when the player gets teleported.
Reply
#10

That's cool! Thanks =]!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)