Jump to content

Get ground position by mouse click problem.


hxv

Recommended Posts

How to get ground position by mouse click, my scripts:

Client-side:

addEvent("getGroundPosition", true) 
function getGround(player) 
local x,y,z = getElementPosition(source) 
local worldposition = getGroundPosition(x,y,z) 
outputChatBox("Ground position: " .. x .. " , " .. y .. " , " .. z .. " ") 
end 
addEventHandler("getGroundPosition", getRootElement(), getGround) 

Server-side:

addEvent("getGroundPosition", true) 
function worldClicked( button, state, player ) 
    if button == "left" and state == "down" then 
    if isPedOnGround ( player ) then 
        triggerClientEvent ("getGroundPosition", player) 
    end 
    end 
end 
addEventHandler( "onElementClicked", getRootElement(), worldClicked ) 

It doesn't work ;x what is the problem?

Link to comment

you're not passing any coordinates of the click, and getting ground position at player position. and ground is not an element, so it will not trigger onElementClicked event.

you can try using onPlayerClick event, though i really dont see a point in involving server in something that can be done clientside entirely.

Link to comment
you're not passing any coordinates of the click, and getting ground position at player position. and ground is not an element, so it will not trigger onElementClicked event.

you can try using onPlayerClick event, though i really dont see a point in involving server in something that can be done clientside entirely.

Thank's onPlayerClick event very helped me.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...