Teleport vehicle with play help
#1

I want to teleport a vehicle with a player
so if he in any vehicle it teleport with him
if not just he teleport only
here my code

Код:
CMD:sfa(playerid, params[])
{
	new string[256];
	new tele[MAX_PLAYERS];



	SetPlayerPos(playerid,-1657.6793, -165.2959, 14.1484);
	GameTextForPlayer(playerid, "~w~San Fierro Airport", 1500, 4);
	GetPlayerName(playerid, tele, sizeof(tele));
	format(string, sizeof(string), "%s Has Just Teleported To San Fierro Airport", tele, playerid);
 	return SendClientMessageToAll(COLOR_GREEN, string);
	}
Reply
#2

pawn Код:
CMD:sfa(playerid, params[])
{
    new string[256];
    new tele[MAX_PLAYERS];
    if(IsPlayerInAnyVehicle(playerid))
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        SetPlayerPos(playerid,-1657.6793, -165.2959, 14.1484);
        SetVehiclePos(vehicleid,-1657.6793, -165.2959, 14.1484);
        PutPlayerInVehicle(playerid,vehicleid,0);
        GameTextForPlayer(playerid, "~w~San Fierro Airport", 1500, 4);
        GetPlayerName(playerid, tele, sizeof(tele));
        format(string, sizeof(string), "%s Has Just Teleported To San Fierro Airport", tele, playerid);
        SendClientMessageToAll(COLOR_GREEN, string);
    }
    else
    {
        SetPlayerPos(playerid,-1657.6793, -165.2959, 14.1484);
        GameTextForPlayer(playerid, "~w~San Fierro Airport", 1500, 4);
        GetPlayerName(playerid, tele, sizeof(tele));
        format(string, sizeof(string), "%s Has Just Teleported To San Fierro Airport", tele, playerid);
        SendClientMessageToAll(COLOR_GREEN, string);
    }
    return 1;
}
Reply
#3

PHP код:
CMD:sfa(playeridparams[]) {
    new 
string[256], tele[MAX_PLAYERS],  seat GetPlayerVehicleSeat(playerid);
    if(
seat != -1) {
        if(
seat == 0) {
            
SetVehiclePos(GetPlayerVehicleID(playerid),-1657.6793, -165.295914.1484);
        }
        else
            
SendClientMessage(playerid, -1"You must be the driver to teleport you and the vehicle.");
    }    
    else
        
SetPlayerPos(playerid,-1657.6793, -165.295914.1484);
    
GameTextForPlayer(playerid"~w~San Fierro Airport"15004);
    
GetPlayerName(playeridtelesizeof(tele));
    
format(stringsizeof(string), "%s Has Just Teleported To San Fierro Airport"teleplayerid);
     return 
SendClientMessageToAll(COLOR_GREENstring);

What I did is optimize the code by gathering the players vehicle seat, this allows me to check if the player is in a car overall, and if his seat is drivers. And if he's the driver, then I actually gather the vehicle id.

Small things like this speeds up the proccess by a few milliseconds which everyone seems to care about in the SAMP community.
Reply
#4

both worked +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)