GetGroundPosition and UpdateElementRpHAnim: Difference between pages

From Multi Theft Auto: Wiki
(Difference between pages)
Jump to navigation Jump to search
m (Fixed typo; improved example)
 
(Remove obsolete Requirements section)
 
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
This function gets the Z level of the highest ground below a point.  
{{Added feature/item|1.5.9|1.5.8|20704|This function updates GTA bone animation for a given [[element]]. Currently the [[Element/Player|Player]] and [[Element/Ped|Ped]] element types are accepted. It must be called after [[setElementBoneRotation]] for changes to take effect. It should only be called once per frame, after you are done rotating bones on that element, as it is quite heavy.}}
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]].}}


It is required that the point is near enough to the local player so that it's within the area where collision data is loaded. If this is not the case, an incorrect position will be returned.
==Syntax==
 
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float getGroundPosition ( float x, float y, float z )
bool updateElementRpHAnim ( element theElement )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===
*'''x:''' A floating point number representing the X world coordinate of the point.
*'''theElement:''' the [[element]] to update the bone animations.
*'''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===
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.
Returns ''true'' if successful, ''false'' otherwise.
 
==Example==
This clientside function determines if a player is under a ceiling or not.
<syntaxhighlight lang="lua">
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,
return getGroundPosition ( px, py, pz ) ~= getGroundPosition ( px, py, pz + 530 )
end
</syntaxhighlight>


==Another example==  
==Example==
This clientside function returns the distance between you and the ground (if there is)
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function getGroundDistance( thePlayer, zHeight  )
addEventHandler("onClientPedsProcessed",root,function()
local x,y,z = getElementPosition(thePlayer) -- get position
     for i,v in ipairs(getElementsByType('player',root,true)) do  -- loop all players
     local groundPosition = getGroundPosition(x,y,z) -- get default ground pos
       
local hit, x1, y1, groundPosition = processLineOfSight(x,y,z+1,x,y,z-(zHeight+0.7)) -- using zHeight get a better ground position
        -- just an exmaple anim
local distance = getDistanceBetweenPoints3D(x, y, z, x,y, (groundPosition or z))  -- get distance between both positions
        setElementBoneRotation(v, 33, 0, 295.2, 0)
return distance -- return the distance
        setElementBoneRotation(v, 23, 0, 298.8, 0)
end
        setElementBoneRotation(v, 4, 0, 46.8, 0)
        setElementBoneRotation(v, 2, 0, 0, 32.4)


-- Some cool examples: 
        updateElementRpHAnim(v) -- Update ped bones animations
addCommandHandler("gdistance",function(_, amount)
    local distance = getGroundDistance(localPlayer, tonumber(amount))
    outputChatBox("The distance to reach ground is: " .. distance)
end)


addCommandHandler("do_im_flying",function()
    local distance = getGroundDistance(localPlayer, 20)
    if distance > 1 then
        outputChatBox("Superman!! the distance between you and ground is: " .. distance)
    else
        outputChatBox("naah")
     end  
     end  
end)
end)
Line 58: Line 33:


==See Also==
==See Also==
{{Client_world_functions}}
{{Client_element_functions}}
 
[[ru:getGroundPosition]]

Latest revision as of 17:23, 7 November 2024

This function updates GTA bone animation for a given element. Currently the Player and Ped element types are accepted. It must be called after setElementBoneRotation for changes to take effect. It should only be called once per frame, after you are done rotating bones on that element, as it is quite heavy.

[[{{{image}}}|link=|]] Tip: If you want to attach an element to a bone, see attachElementToBone.

Syntax

bool updateElementRpHAnim ( element theElement )

Required Arguments

  • theElement: the element to update the bone animations.

Returns

Returns true if successful, false otherwise.

Example

addEventHandler("onClientPedsProcessed",root,function()
    for i,v in ipairs(getElementsByType('player',root,true)) do  -- loop all players
        
        -- just an exmaple anim
        setElementBoneRotation(v, 33, 0, 295.2, 0)
        setElementBoneRotation(v, 23, 0, 298.8, 0)
        setElementBoneRotation(v, 4, 0, 46.8, 0)
        setElementBoneRotation(v, 2, 0, 0, 32.4)

        updateElementRpHAnim(v) -- Update ped bones animations

    end 
end)

See Also