UnG//Macaus Posted December 20, 2014 Posted December 20, 2014 (edited) I have a problem with my code, everything is working, but the function is executed 2 times when I click on a button. Can someone help me? for id,element_r in ipairs(getElementChildren(dxRootElement)) do for id, element in ipairs(getElementChildren(element_r)) do if getElementData(element,"visible") == true then local g_height = getElementData(element,"height") or 0 local g_width = getElementData(element,"width") or 0 local px, py = dxGetPosition(element) if (button == "left" and state == "up") then if x >= px and x <= (px+g_width) and y >= py and y <= (py + g_height) then triggerEvent("onClientDXClick",element) end end end end end Edited December 31, 2014 by Guest
Anubhav Posted December 20, 2014 Posted December 20, 2014 Use getTickCount method. When you click just make a variable setting to getTickCount( ) then when you loop before that, check: if getTickCount() - yourVariables > 1000 then -- easier method is a setTimer
Dealman Posted December 21, 2014 Posted December 21, 2014 Is that the entire function? What if you move this part to the very top of the function? if (button == "left" and state == "up") then
UnG//Macaus Posted December 21, 2014 Author Posted December 21, 2014 Yes, this is the full function I put this line at the top and still have the same problem
MTA Team 0xCiBeR Posted December 21, 2014 MTA Team Posted December 21, 2014 That's because your for-loop executes more than one time before you release/press your key. Just break the loop using: break Example: ( Tho i don't know how your script works as you are not showing it entierly ): triggerEvent("onClientDXClick",element) break That will prevent your for-loop to continue looping after you triggered the event
UnG//Macaus Posted December 22, 2014 Author Posted December 22, 2014 now is not repeating more, except for triggerEvents Example: addEventHandler("onClientDXClick",getRootElement(), function() if (source == button) then triggerServerEvent("test",localPlayer) end end) --server addEvent("test",true) addEventHandler("test",getRootElement(), function() outputChatBox ( "TEST", source, 0, 255, 0) end)
UnG//Macaus Posted December 22, 2014 Author Posted December 22, 2014 Only triggerServerEvent is executed 2 times
Castillo Posted December 22, 2014 Posted December 22, 2014 I guess "onClientDXClick" is being triggered twice then.
Anubhav Posted December 22, 2014 Posted December 22, 2014 Use getTickCount method. When you click just make a variable setting to getTickCount( ) then when you loop before that, check: if getTickCount() - yourVariables > 1000 then -- easier method is a setTimer This is it, then.
UnG//Macaus Posted December 22, 2014 Author Posted December 22, 2014 I think you have misunderstood the problem I have now addEventHandler("onClientDXClick",getRootElement(), function() if (source == button) then triggerServerEvent("test",localPlayer) --run 2 times (2 outputChatBox) outputChatBox("test") --run 1 time (1 outputChatBox) end end)
Castillo Posted December 22, 2014 Posted December 22, 2014 Something else is triggering that event then.
3B00DG4MER Posted December 23, 2014 Posted December 23, 2014 You can use that function : function isMouseWithinRangeOf(posX, posY, sizeX, sizeY) if isCursorShowing() == false then return false end local cx,cy = getCursorPosition() cx,cy = cx*sW,cy*sH if cx >= posX and cx <= posX+sizeX and cy >= posY and cy <= posY+sizeY then return true,cx,cy else return false end end
UnG//Macaus Posted December 23, 2014 Author Posted December 23, 2014 As i Know , there is nothing that is triggering the event, does someone have a idea or solution how to solve this problem ?
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