SA-MP Forums Archive
Teleport-Car wont come - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Teleport-Car wont come (/showthread.php?tid=313582)



Teleport-Car wont come - RubM - 26.01.2012

I just made my own first teleport! I was werry happy with it until i found out cars is at the same position as when i typed the cmd. Here are the scripts

cmd = strtok(cmdtext, idx);

if(strcmp(cmd, "/nascar", true) == 0)
{
SetPlayerPos(playerid,1433.4521,1504.1399,10.8203) ;
return 1;
}
if(strcmp(cmd, "/sf", true) == 0)
{
SetPlayerPos(playerid,-1898.6420,243.1353,41.0469);
return 1;


Re: Teleport-Car wont come - T0pAz - 26.01.2012

Can you please elaborate? It would help alot.


Re: Teleport-Car wont come - RubM - 26.01.2012

elaborate? :P sry for bad english


Re: Teleport-Car wont come - [XST]O_x - 26.01.2012

That means you need to explain more about your situation.
Anyway I guess you meant the car isn't teleporting with the player, am I right?

Try this:
pawn Код:
new Vehicle;
if(strcmp(cmd,"/nascar", true) == 0)
{
    SetPlayerPos(playerid,1433.4521,1504.1399,10.8203);
    if(IsPlayerInAnyVehicle(playerid)) {
    Vehicle = GetPlayerVehicleID(playerid); SetVehiclePos(Vehicle,1433.4521,1504.1399,10.8203);
    PutPlayerInVehicle(Vehicle); }
    return 1;
}

if(strcmp(cmd,"/sf", true) == 0)
{
    SetPlayerPos(playerid,-1898.6420,243.1353,41.0469);
    if(IsPlayerInAnyVehicle(playerid)) {
    Vehicle = GetPlayerVehicleID(playerid); SetVehiclePos(Vehicle,-1898.6420,243.1353,41.0469);
    PutPlayerInVehicle(Vehicle); }
    return 1;
}



Re: Teleport-Car wont come - MP2 - 26.01.2012

https://sampwiki.blast.hk/wiki/GetPlayerState
https://sampwiki.blast.hk/wiki/GetPlayerVehicleID
https://sampwiki.blast.hk/wiki/SetVehiclePos

[XST]O_x, your example isn't great. Here's a better solution:

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) SetPlayerPos(playerid, x, y, z);
else SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);



Re: Teleport-Car wont come - RubM - 26.01.2012

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
That means you need to explain more about your situation.
Anyway I guess you meant the car isn't teleporting with the player, am I right?

Try this:
pawn Код:
new Vehicle;
if(strcmp(cmd,"/nascar", true) == 0)
{
    SetPlayerPos(playerid,1433.4521,1504.1399,10.8203);
    if(IsPlayerInAnyVehicle(playerid)) {
    Vehicle = GetPlayerVehicleID(playerid); SetVehiclePos(Vehicle,1433.4521,1504.1399,10.8203);
    PutPlayerInVehicle(Vehicle); }
    return 1;
}

if(strcmp(cmd,"/sf", true) == 0)
{
    SetPlayerPos(playerid,-1898.6420,243.1353,41.0469);
    if(IsPlayerInAnyVehicle(playerid)) {
    Vehicle = GetPlayerVehicleID(playerid); SetVehiclePos(Vehicle,-1898.6420,243.1353,41.0469);
    PutPlayerInVehicle(Vehicle); }
    return 1;
}
Yes you are right. Thanks, i will try this I appriciate your help


Re: Teleport-Car wont come - [XST]O_x - 26.01.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/GetPlayerState
https://sampwiki.blast.hk/wiki/GetPlayerVehicleID
https://sampwiki.blast.hk/wiki/SetVehiclePos

[XST]O_x, your example isn't great. Here's a better solution:

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) SetPlayerPos(playerid, x, y, z);
else SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
My example isn't great indeed, but your example will send the player to X Y Z if he's a driver, else, it will send the vehicle to X Y Z.


Re: Teleport-Car wont come - Twix[KDZ] - 26.01.2012

Yeah, that one will work thanks btw! im his accociate ^^,


Re: Teleport-Car wont come - MP2 - 26.01.2012

Okay so I messed the order up :/

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
else SetPlayerPos(playerid, x, y, z);
The reason I use GetPlayerState instead of IsPlayerInAnyVehicle is because passengers shouldn't have control over a vehicle's teleports - only the driver should.


Re: Teleport-Car wont come - [XST]O_x - 26.01.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
Okay so I messed the order up :/

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
else SetPlayerPos(playerid, x, y, z);
The reason I use GetPlayerState instead of IsPlayerInAnyVehicle is because passengers shouldn't have control over a vehicle's teleports - only the driver should.
I haven't been using teleportations for very long time now, so tell me, will SetVehiclePos set both vehicle and player's position to X Y Z?
Because if so, 60% of my code was indeed useless.