Jump to content

dxrectangle into a button


Recommended Posts

I made this dx rectangle i want when someone press's it it will trigger a server event which i will do later, But i can't figure it out. I tried onClientClick but it doesn't work. I think i got the parameters wrong

I was just experimenting it's probably all wrong.

firstMissionMarker = createMarker ( 1699.88647, -2259.09521, 38.5, "cylinder",  1.5, 255, 255, 0, 125 ) 
setElementInterior ( firstMissionMarker, 2) 
  
  
function Draw () 
     
    spawnbutton =       dxDrawRectangle(569, 538, 144, 53, tocolor(255, 0, 0, 255), true) 
    spawntext =         dxDrawText("Spawn!", 620, 555, 721, 569, tocolor(255, 255, 255, 255), 1, "default", "left", "top", false, false, true, false, false) 
     
end; 
  
addEventHandler("onClientMarkerHit",firstMissionMarker, 
    function (plr) 
        if (getElementType(plr) == "player") and ( plr == localPlayer )then 
            addEventHandler("onClientRender",source,Draw); end; 
        end 
    ); 
  
    addEventHandler("onClientMarkerLeave",firstMissionMarker, 
        function ( plr ) 
        if (getElementType(plr) == "player") and ( plr == localPlayer )then 
        removeEventHandler("onClientRender",source,Draw); end; 
    end 
); 
  
  
    function spawnPlayerOnDXButtonPress ( left, down, 569, 538, 1699.88647, -2259.09521, 38.5, spawnbutton ) 
        if ( spawnbutton ) then 
                outputChatBox ("works!") 
        else 
                outputChatBox ("FAIL!") 
        end 
    end 
    addEventHandler("onClientClick", source, spawnPlayerOnDXButtonPress ) 

Link to comment

At the end, try "onClientGUIClick" instead of "onClientClick", because (wiki): "This event triggers whenever the user clicks his mouse. This is linked to the GTA world, as oppose to GUI for which onClientGUIClick is to be used. This event allows detection of click positions of the 3D world."

Link to comment
addEventHandler("onClientClick",root, 
    function () 
        local screenx, screeny, worldx, worldy, worldz = getCursorPosition() 
        if (screenx==20) and (screeny==50) then -- There is also a few ways to write it to get the position.. 
            -- code -- 
        end 
    end 
) 

Link to comment

DX drawings are not GUI elements. DX drawings do not exist. DX functions do not create anything and because of that, they do not return any element. All what DX functions do is changing the colors of pixels on the screen. Our brains receive the information about these pixels and interpret some areas as distinct objects, creating an illusion of DX drawings' existence :)

Link to comment

Requires some editing to make it work.

EDIT: used onClientRender as event.

  
local clicked = false 
-- Hover-On 
    if not isCursorShowing() then return end 
    local cX, cY = getCursorPosition() 
    for i,v in ipairs(items) do 
        local x, y = v.x, v.y 
        if cX >= x-0.001 and cY >= y and cX <= x + (itemWidth - 0.001) and cY < y + (itemHeight - 0.001) then 
            v.color = { 255, 255, 255, 255 } 
            -- Click 
            if getKeyState('mouse1') and not clicked then 
                -- Trigger event herr 
                clicked = true 
            elseif not getKeyState('mouse1') then 
                clicked = false 
            end 
        else     
            v.color = { 200, 200, 200, 255 } 
        end 
    end 
  

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