GetVehicleRespawnPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Useful Function}}
{{Server function}}
<lowercasetitle/>
__NOTOC__
__NOTOC__
This function allows you to get the respawn position of a specific [[vehicle]] element.
{{New feature/item|3.0156|1.5.5|14053|This function retrieves the respawn coordinates of a [[vehicle]].}}
'''Note:''' Please insert this code in a file that stands on the top of your meta.xml file to work correctly.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">float, float, float, float, float, float getVehicleRespawnPosition( element theVehicle )</syntaxhighlight>
<syntaxhighlight lang="lua">
float float float getVehicleRespawnPosition ( vehicle theVehicle )
</syntaxhighlight>
{{OOP||[[vehicle]]:getRespawnPosition|respawnPosition|setVehicleRespawnPosition}}


===Required Arguments===
===Required Arguments===
* '''theVehicle''': A vehicle that have been created using [[createVehicle]].
*'''theVehicle:''' The [[vehicle]] which you'd like to retrieve the respawn coordinates of.


===Returns===
===Returns===
Returns 6 variables representing the vehicle's respawn position. (x, y, z, rotx, roty, rotz)
Returns three [[float|floats]] indicating the respawn coordinates of the [[vehicle]], ''x'', ''y'' and ''z'' respectively.
If the vehicle is incorrect or the table is missing, it returns false.


==Code==
==Example==
<section name="Server and Clientside script" class="both" show="true">
This example outputs the player's current vehicle respawn position.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local vehSpawn = {}
function getRespawnPosition(player)
 
    local veh = getPedOccupiedVehicle(player)  
_createVehicle = createVehicle
    if veh then  
_setVehicleRespawnPosition = setVehicleRespawnPosition
        local x,y,z = getVehicleRespawnPosition(veh)
 
        local rx,ry,rz = getVehicleRespawnRotation(veh)
-- Overwrite the existing functions --
        outputChatBox("this car respawn in x = "..x.." y = "..y.." z = "..z.." rx = "..rx.." ry = "..rz,player,0,255,0)
function createVehicle(id, x, y, z, rx, ry, rz, ...)
    else
local veh = _createVehicle(id, x, y, z, rx, ry, rz, ...)
        outputChatBox("you are not in the car",player,255,0,0)
if(veh) then
    end
vehSpawn[veh] = {x, y, z, rx, ry, rz}
end  
return veh
addCommandHandler("getRespawnPos",getRespawnPosition)
else
return false
end
end
 
 
function setVehicleRespawnPosition(theVehicle, ...)
assert(vehSpawn[theVehicle], "Bad Argument @ setVehicleRespawnPosition (Vehicle respawn position does not exists)")
vehSpawn[theVehicle] = {...}
return _setVehicleRespawnPosition(theVehicle, ...)
end
 
-- Add's the new function --
function getVehicleRespawnPosition(theVehicle)
if(vehSpawn[theVehicle]) then
return vehSpawn[theVehicle][1], vehSpawn[theVehicle][2], vehSpawn[theVehicle][3], vehSpawn[theVehicle][4], vehSpawn[theVehicle][5], vehSpawn[theVehicle][6]
else
return false
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
Author: Noneatme


==See Also==
==See Also==
{{Useful_Functions}}
{{Vehicle_functions|server}}

Latest revision as of 23:03, 6 September 2024

This function retrieves the respawn coordinates of a vehicle.

Syntax

float float float getVehicleRespawnPosition ( vehicle 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.

Click to collapse [-]
Server
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