Bean666 Posted March 1, 2021 Posted March 1, 2021 (edited) so this script shows if u enter marker a DX text shows up, but when two of us enter the market, an error shows up: addEventHandler("onClientPreRender" with this function is already handled. line 142, how to fix this? line 142 is: function draw() for i, c in ipairs(bombteams) do if getPlayerTeam ( localPlayer ) and getPlayerTeam ( localPlayer ) == getTeamFromName(c[1]) then dxDrawText("Protect and escort the bomb truck", (700/1920)*sx, (71/1080)*sy, (1278/1920)*sx, (103/1080)*sy, tocolor(200, 200, 0, 255), (1.00/1920)*sx, "bankgothic", "left", "top", false, false, false, false, false) end end for i, c in ipairs(alliedteams) do if getPlayerTeam ( localPlayer ) and getPlayerTeam ( localPlayer ) == getTeamFromName(c[1]) then dxDrawText("Stop and defuse the bomb truck", (700/1920)*sx, (71/1080)*sy, (1278/1920)*sx, (103/1080)*sy, tocolor(110, 208, 30, 255), (1.00/1920)*sx, "bankgothic", "left", "top", false, false, false, false, false) end end end function drawprotect(localPlayer) addEventHandler("onClientPreRender", getRootElement(), draw) -- THIS IS 142 end addEvent("drawprotect", true) addEventHandler("drawprotect", root, drawprotect) function markerHit(localPlayer) if source == attachedmarker then if ( localPlayer == getLocalPlayer() and getElementType ( localPlayer ) == "player" ) then if isTimer(datatimer) then killTimer(datatimer) end if Bombstart == false then return end local playerTeam = getPlayerTeam ( localPlayer ) setElementData(localPlayer , "participated", true) drawprotect(localPlayer) end end end addEventHandler("onClientMarkerHit", resourceRoot, markerHit) Edited March 1, 2021 by Bean666 Aftermath
Moderators IIYAMA Posted March 1, 2021 Moderators Posted March 1, 2021 8 minutes ago, Bean666 said: addEventHandler("onClientPreRender" with this function is already handled. line 142, how to fix this? This warning appears when you try to add an event handler, which is already attached to that function. You can either use a variable: local drawingStatus = false if not drawingStatus then addEventHandler("onClientPreRender", getRootElement(), draw) drawingStatus = true end if drawingStatus then removeEventHandler("onClientPreRender", getRootElement(), draw) drawingStatus = false end Or you can use the following utility function isEventHandlerAdded, which you can copy out of the example: https://wiki.multitheftauto.com/wiki/GetEventHandlers 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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