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 Code:
OnPlayerCommandText
, or any of your other commands add this:

pawn Code:
if (strcmp("/teleport", cmdtext, true) == 0)
{

return 1;
}

Okay, this will trigger the command, when you type,
Code:
/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 Code:
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 Code:
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 Code:
else

pawn Code:
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 Code:
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 Code:
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 Code:
getv = GetPlayerVehicleID(playerid)
add:

pawn Code:
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 Code:
PutPlayerInVehicle

Under the
pawn Code:
SetPlayerPos and SetVehiclePos
add:

pawn Code:
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 Code:
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 ed, please say so |: