GetGroundPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(Example fixed)
Line 1: Line 1:
{{Needs_Checking|what's the maximum distance from the player we can check?}}
{{Needs_Checking|what's the maximum distance from the player we can check?}}
__NOTOC__
__NOTOC__
This function gets the ground level of the nearest floor level below a point. It is required that the point is near enough to the player so that it's within the area where world map data is loaded.
This function gets the Z level of the highest ground below a point. It is required that the point is near enough to the local player so that it's within the area where world map data is loaded.


==Syntax==  
==Syntax==  
Line 9: Line 9:


===Required Arguments===  
===Required Arguments===  
*'''x:''' A floating point number representing the X coordinate on the map.
*'''x:''' A floating point number representing the X world coordinate of the point.
*'''y:''' A floating point number representing the Y coordinate on the map.
*'''y:''' A floating point number representing the Y world coordinate of the point.
*'''z:''' A floating point number representing the Z coordinate on the map.
*'''z:''' A floating point number representing the Z world coordinate of the point.


===Returns===
===Returns===
Returns a float with the highest floor-level Z coord if parameters are valid, ''false'' otherwise.
Returns a float with the highest ground-level Z coord if parameters are valid, ''0'' if the point you tried to test is outside the loaded world map, ''false'' otherwise.


==Example==  
==Example==  
This clientside function determines if a player is under a ceiling.
This clientside function determines if a player is under a ceiling or not.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function isPlayerUndercover ( player )
function isPlayerUnderCover ( thePlayer )
--we get the player's position and store it in three variables
--we get the player's position
local px, py, pz = getPlayerPosition ( player )
local px, py, pz = getElementPosition ( thePlayer )
--if the floor level for the player is the same when we measure it way up (let's say 200 units),
--we'll check for ground level at the player's position, and also 500 units over him.
--it must mean there are no obstacles (ceilings) over the player: the function returns false (not undercover)
--if these ground levels match, it must mean there were no obstacles (such as a ceiling) over the player,
if getGroundPosition ( px, py, pz ) == getGroundPosition ( px, py, pz + 200 ) then return false
if getGroundPosition ( px, py, pz ) == getGroundPosition ( px, py, pz + 500 ) then
--otherwise, there must be an object over him: the function returns true (undercover)
-- so the player is not under cover
else return true
return false
--otherwise, there was an object over him,
else
-- so the player is under cover
return true
end
end
end
end

Revision as of 12:32, 2 August 2007

Dialog-information.png This article needs checking.

Reason(s): what's the maximum distance from the player we can check?

This function gets the Z level of the highest ground below a point. It is required that the point is near enough to the local player so that it's within the area where world map data is loaded.

Syntax

float getGroundPosition ( float x, float y, float z )

Required Arguments

  • x: A floating point number representing the X world coordinate of the point.
  • y: A floating point number representing the Y world coordinate of the point.
  • z: A floating point number representing the Z world coordinate of the point.

Returns

Returns a float with the highest ground-level Z coord if parameters are valid, 0 if the point you tried to test is outside the loaded world map, false otherwise.

Example

This clientside function determines if a player is under a ceiling or not.

function isPlayerUnderCover ( thePlayer )
	--we get the player's position
	local px, py, pz = getElementPosition ( thePlayer )
	--we'll check for ground level at the player's position, and also 500 units over him.
	--if these ground levels match, it must mean there were no obstacles (such as a ceiling) over the player,
	if getGroundPosition ( px, py, pz ) == getGroundPosition ( px, py, pz + 500 ) then
		-- so the player is not under cover
		return false
	--otherwise, there was an object over him,
	else
		-- so the player is under cover
		return true
	end
end

See Also