Jump to content

function is already handled?


Bean666

Recommended Posts

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 by Bean666
Link to comment
  • Moderators
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

 

 

 

 

  • Like 1
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...