Jump to content

[Help] show dxmenu when player clicks


Artenos

Recommended Posts

so basically the same as creating a gui menu whenever a player clicks on a ped but this time whenever the player clicks on himself/herself it would display a dxrectangle

here is what I got so far:

function onPlayerClick(button, state, absX, absY, wx, wy, wz, element) 
    if (element and getElementType(element) == "player" and state=="down") then 
        local x, y, z = getElementPosition(localPlayer) 
        if (getDistanceBetweenPoints3D(x, y, z, wx, wy, wz) <=3) then 
            RenderHolo() 
        end 
    end 
end 
addEventHandler("onClientClick", getRootElement(), onPlayerClick) 

function RenderHolo

function RenderHolo( startedRes) 
    local thePlayer = getLocalPlayer () 
    local x, y, z = getElementPosition ( thePlayer ) 
    local r = getPedRotation ( thePlayer ) 
    x = x - math.sin ( math.rad(r) ) * 1 
    y = y + math.cos ( math.rad(r) ) * 1 
    local holoscreen,RT_ID,RTE = createHoloScreen(x,y,z,-2,0,r,1.35,2) --Create our holoscreen 
    setElementData(holoscreen,"interactive","aim") -- Make it interactive on user aim 
    if RTE then -- If we got the render Target of the screen then 
        RTE_Demo = RTE 
        RTE_Holo = holoscreen 
        addEventHandler ( "onHoloScrenRender", RTE_Holo,drawHoloDemo) -- Event handler for every render of the holo screen 
    end 
end 

Link to comment
so basically the same as creating a gui menu whenever a player clicks on a ped but this time whenever the player clicks on himself/herself it would display a dxrectangle

here is what I got so far:

function onPlayerClick(button, state, absX, absY, wx, wy, wz, element) 
    if (element and getElementType(element) == "player" and state=="down") then 
        local x, y, z = getElementPosition(localPlayer) 
        if (getDistanceBetweenPoints3D(x, y, z, wx, wy, wz) <=3) then 
            RenderHolo() 
        end 
    end 
end 
addEventHandler("onClientClick", getRootElement(), onPlayerClick) 

function RenderHolo

function RenderHolo( startedRes) 
    local thePlayer = getLocalPlayer () 
    local x, y, z = getElementPosition ( thePlayer ) 
    local r = getPedRotation ( thePlayer ) 
    x = x - math.sin ( math.rad(r) ) * 1 
    y = y + math.cos ( math.rad(r) ) * 1 
    local holoscreen,RT_ID,RTE = createHoloScreen(x,y,z,-2,0,r,1.35,2) --Create our holoscreen 
    setElementData(holoscreen,"interactive","aim") -- Make it interactive on user aim 
    if RTE then -- If we got the render Target of the screen then 
        RTE_Demo = RTE 
        RTE_Holo = holoscreen 
        addEventHandler ( "onHoloScrenRender", RTE_Holo,drawHoloDemo) -- Event handler for every render of the holo screen 
    end 
end 

Well , if i didnt get you wrong , what you want to say is that if you click on a player or ped the window should show. If you click on yourself , it shouldnt show.

Well , its easy. You just need to write an "if " statement to check that the clicked element is not the local player himself.

Replace your first function with this ->

function onPlayerClick(button, state, absX, absY, wx, wy, wz, element) 
    if (element and getElementType(element) == "player" and state=="down") then 
if element == getLocalPlayer() then return end 
        local x, y, z = getElementPosition(localPlayer) 
        if (getDistanceBetweenPoints3D(x, y, z, wx, wy, wz) <=3) then 
            RenderHolo() 
        end 
    end 
end 
addEventHandler("onClientClick", getRootElement(), onPlayerClick) 

Also , i would prefer not to use "element" as a parameter.

Use "theelement" or something.

Link to comment

No xD, sorry if you misunderstood what I said, here let me rephrase it: Basically what I want to accomplish is whenever a player clicks on themself the function should show the window. The window should NOT show if the player clicks on a ped or another player, so basically the opposite of what you said :P.

Link to comment
function onPlayerClick(button, state, absX, absY, wx, wy, wz, element) 
    if (element and getElementType(element) == "player" and state=="down") then 
if element ~= getLocalPlayer() then return end 
        local x, y, z = getElementPosition(localPlayer) 
        if (getDistanceBetweenPoints3D(x, y, z, wx, wy, wz) <=3) then 
            RenderHolo() 
        end 
    end 
end 
addEventHandler("onClientClick", getRootElement(), onPlayerClick) 
  
  
  

Sorry , my bad. Try the above code . It should work.

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...