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 Macaus ~ / Ravel Pires / Macaus
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 See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
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 If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
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 Macaus ~ / Ravel Pires / Macaus
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 DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp
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) Macaus ~ / Ravel Pires / Macaus
UnG//Macaus Posted December 22, 2014 Author Posted December 22, 2014 anyone? Macaus ~ / Ravel Pires / Macaus
Castillo Posted December 22, 2014 Posted December 22, 2014 What is the problem? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
UnG//Macaus Posted December 22, 2014 Author Posted December 22, 2014 Only triggerServerEvent is executed 2 times Macaus ~ / Ravel Pires / Macaus
Castillo Posted December 22, 2014 Posted December 22, 2014 I guess "onClientDXClick" is being triggered twice then. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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. See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
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) Macaus ~ / Ravel Pires / Macaus
Castillo Posted December 22, 2014 Posted December 22, 2014 Something else is triggering that event then. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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 SAF/SAO - 30% Skype: Themerzoug2020 in-game name:3B00DG4MER
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 ? Macaus ~ / Ravel Pires / Macaus
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