Help with player to vehicle command
#1

Hey, I'm trying to create a command that when you type /ptc <playerid> <vehicleid> it teleports the player into the vehicle specified. I've been at this for hours, asking friends to have a look with no prevail.
pawn Код:
CMD:ptc(playerid, vehicleid, params[])
{
    new vehid,pName[25];
    if(sscanf(params,"ui",pName, vehid)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ptc <playerid> <vehicleid>");
    else if(playerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Player not found");
    else
    {
    GetVehicleModel(vehicleid);
    GetPlayerName(playerid, pName,25);
    PutPlayerInVehicle(playerid, vehid, 0);
    new string[70];

    format(string,sizeof(string),"You moved %s to the vehicle %d",playerid,vehicleid);
    SendClientMessage(playerid, 0x00FF00AA, string);}

    return 1;
}
As you can see I used zcmd + sscanf, both have been defined and all. Any help would be greatly appreciated.
Reply
#2

First of all you need to make sure an invalid vehicle id gets passed trough sscanf so you could do

pawn Код:
else if ( vehid == INVALID_VEHICLE_ID ) return SendClientMessage( playerid, COLOR_RD, "Invalid vehicle ID!");
right after the code that checks if the player is connected.

Second of all why are you using %s in format( where the first parameter is an integer, use pName instead of playerid so it will return name not a strange number.

And why are you using GetVehicleModel? You could easily just do, You moved XYZ to vehicle id XYZ (Cheetah|Model:000) and you could also tell the player the coordinates.

You could use

pawn Код:
new
      vPos[ 3 ],
      vStr[ 129 ];
GetVehiclePos( vehid, vPos[ 0 ], vPos[ 1 ], vPos[ 2 ] );
format( vStr, 129, "The coordinates for the vehicle are: X:%.2f Y:%.2f Z:%.2f", vPos[ 0 ], vPos[ 1 ], vPos[ 2 ] );
SendClientMessage( playerid, ~1, vStr );
Reply
#3

Quote:
Originally Posted by Zh3r0
Посмотреть сообщение
You could use

pawn Код:
new
      vPos[ 3 ],
      vStr[ 129 ];
GetVehiclePos( vehid, vPos[ 0 ], vPos[ 1 ], vPos[ 2 ] );
format( vStr, 129, "The coordinates for the vehicle are: X:%.2f Y:%.2f Z:%.2f", vPos[ 0 ], vPos[ 1 ], vPos[ 2 ] );
SendClientMessage( playerid, ~1, vStr );
Sorry if i'm wrong, but that would only tell me where the vehicle is located, but wouldnt that just tell me where the vehicle is located, not teleport the player to them? Also I don't think i specified the problem well, what happens is if i do /ptc 0 (playerid) 1 (vehicleid) it comes up with Usage: /ptc <playerid> <vehicleid>
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)