toptional Posted April 2, 2013 Share Posted April 2, 2013 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
Ludo Posted April 2, 2013 Share Posted April 2, 2013 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
toptional Posted April 2, 2013 Author Share Posted April 2, 2013 The i'm pretty sure that dxrectangle is not a GUI element, or is it? Link to comment
Ludo Posted April 2, 2013 Share Posted April 2, 2013 The i'm pretty sure that dxrectangle is not a GUI element, or is it? I think it isn't at all, anyway try it and let me know Link to comment
Castillo Posted April 2, 2013 Share Posted April 2, 2013 No, that won't work, obviously, you'll have to check cursor position with onClientClick. Link to comment
toptional Posted April 2, 2013 Author Share Posted April 2, 2013 Can you give me an example? Link to comment
xXMADEXx Posted April 2, 2013 Share Posted April 2, 2013 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
DiSaMe Posted April 3, 2013 Share Posted April 3, 2013 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
Jesseunit Posted April 3, 2013 Share Posted April 3, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now