GetVehicleRespawnPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(There are no commas in return types in other function syntax section)
Line 17: Line 17:
==Example==
==Example==
This example outputs the player's current vehicle respawn position.
This example outputs the player's current vehicle respawn position.
<syntaxhighlight lang="lua">
<syntaxhighlight name="Server" class="server" show="true">
function getRespawnPosition(plr)
function getRespawnPosition(player)
     if (not plr) then
    local veh = getPedOccupiedVehicle(player)  
         return false
     if veh then
        local x,y,z = getVehicleRespawnPosition(veh)
        local rx,ry,rz = getVehicleRespawnRotation(veh)
        outputChatBox("this car respawn in x = "..x.." y = "..y.." z = "..z.." rx = "..rx.." ry = "..rz,player,0,255,0)
    else
         outputChatBox("you are not in the car",player,255,0,0)
     end
     end
    local veh = getPedOccupiedVehicle(plr)
end
    if (not veh) then
addCommandHandler("getRespawnPos",getRespawnPosition)
        return false
    end
    local x, y, z = getVehicleRespawnPosition(veh)
    return x, y, z
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Vehicle_functions}}
{{Vehicle_functions}}

Revision as of 01:16, 29 September 2022

This function retrieves the respawn coordinates of a vehicle.

Syntax

float float float getVehicleRespawnPosition ( element theVehicle )

OOP Syntax Help! I don't understand this!

Method: vehicle:getRespawnPosition(...)
Variable: .respawnPosition
Counterpart: setVehicleRespawnPosition


Required Arguments

  • theVehicle: The vehicle which you'd like to retrieve the respawn coordinates of.

Returns

Returns three floats indicating the respawn coordinates of the vehicle, x, y and z respectively.

Example

This example outputs the player's current vehicle respawn position.

function getRespawnPosition(player)
    local veh = getPedOccupiedVehicle(player) 
    if veh then 
        local x,y,z = getVehicleRespawnPosition(veh)
        local rx,ry,rz = getVehicleRespawnRotation(veh)
        outputChatBox("this car respawn in x = "..x.." y = "..y.." z = "..z.." rx = "..rx.." ry = "..rz,player,0,255,0)
    else
        outputChatBox("you are not in the car",player,255,0,0)
    end
end 
addCommandHandler("getRespawnPos",getRespawnPosition)

See Also