Teleporting with a vehicle
#1

So i've created some teleports for my script but it wont let me teleport and "bring" my vehicle. The vehicle stays where it was when i type the command and i get teleported.

How do i fix this?

Here is the code for the teleport:

Код:
        if (strcmp("/spawn", cmdtext, true, 10) == 0)
	{
	SetPlayerPos(playerid,-50.0743,-274.4324,5.4297); 	// Do something here
	SetPlayerFacingAngle(playerid,180.0);
	SendClientMessage(playerid,0x00FF00FF,"You have teleported to the spawnpoint");
	return 1;
Thanks in advance
Reply
#2

Код:
if (strcmp("/spawn", cmdtext, true, 10) == 0)
{    
    new vehid;
    vehid = GetPlayerVehicleID(playerid);
    SetPlayerPos(playerid,2155.0159,942.3558,10.8203);
    SetVehiclePos(vehid, 2155.0159,942.3558,10.8203);
    PutPlayerInVehicle( playerid, vehid, 0);
}
Reply
#3

Do a check if they are in a vehicle or not and if they are, just teleport the vehicle. Otherwise, just teleport them. For the above code, you can just tele the vehicle and the player will remain.
Reply
#4

Quote:
Originally Posted by Backwardsman97
Посмотреть сообщение
Do a check if they are in a vehicle or not and if they are, just teleport the vehicle. Otherwise, just teleport them. For the above code, you can just tele the vehicle and the player will remain.
Could you give me the code for that?
Reply
#5

Код:
if (strcmp("/spawn", cmdtext, true, 10) == 0)
    {
    if(IsPlayerInAnyVehicle(playerid)) {
        new Float:X;
        new Float:Y;
        new Float:Z;
        new VehicleID;
        GetPlayerPos(playerid, X, Y, Z);
        VehicleID = GetPlayerVehicleID(playerid);
        SetVehiclePos(VehicleID, -50.0743,-274.4324,5.4297);
        } else {
        new Float:X;
        new Float:Y;
        new Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
        SetPlayerPos(playerid, -50.0743,-274.4324,5.4297);
        }
    return 1;
    }
Checking the vehicle
Reply
#6

Quote:
Originally Posted by PRANK
Посмотреть сообщение
Код:
if (strcmp("/spawn", cmdtext, true, 10) == 0)
    {
    if(IsPlayerInAnyVehicle(playerid)) {
        new Float:X;
        new Float:Y;
        new Float:Z;
        new VehicleID;
        GetPlayerPos(playerid, X, Y, Z);
        VehicleID = GetPlayerVehicleID(playerid);
        SetVehiclePos(VehicleID, -50.0743,-274.4324,5.4297);
        } else {
        new Float:X;
        new Float:Y;
        new Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
        SetPlayerPos(playerid, -50.0743,-274.4324,5.4297);
        }
    return 1;
    }
Checking the vehicle
I am confident that code will run beautifully :-/
Reply
#7

Why did you get the player pos?? It seems useless..
Reply
#8

That could could really be cleaned up..:

pawn Код:
if (strcmp("/spawn", cmdtext, true) == 0)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) SetVehiclePos(GetPlayerVehicleID(playerid), -50.0743,-274.4324,5.4297);
    else SetPlayerPos(playerid, -50.0743,-274.4324,5.4297);
    return 1;
}
1. Why did you specify a length in strcmp? It's just un-needed.
2. Why did you create any variables?
3. Why did you store information in variables and never use them?
4. Why the over-complication?
5. Why check if the player is in a vehicle instead of checking if he is a driver? (Do you want passengers to be able to teleport the vehicle?)
6. Why do you use GetPlayerPos at all?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)