Jump to content

onClientRender - removeEventHandler


keymetaphore

Recommended Posts

Alright, hi.

So, I'm creating a small DX HUD that opens when you switch a weapon and closes after some time (indicating the current weapon and the other ones, but that's not so important here).

I did create most of it, but I am having trouble with removing it. 

So here goes the code.

function prepareInfo ()
  -- here is the info that prepares everything, mostly not nesesscary
  dxValue = 100
  -- this is the value (one of the possible ones) that would get defined above and is correct
  local callfunction = function () weaponfunc(dxCount) end
  addEventHandler("onClientRender", root, callfunction) -- you may see this weird, but it's just so I can pass the variable
  setTimer(function () if removeEventHandler( "onClientRender", root, function () weaponfunc(dxCount) end ) then outputChatBox("Handler Removed") end end, 3000, 1)

-- So right here we set the timer to remove the onClientRender event (and also outputChatBox just to see that the function gets called
end
	
function weaponfunc (dxCount) 
   -- here would be the dxDrawRectangle(), not needed here, function works, it just doesn't remove
    
end

 

Link to comment
  • Scripting Moderators
function testRender()
	print("render~")
end

addEventHandler("onClientRender",root,testRender)

setTimer(function()
	removeEventHandler("onClientRender",root,testRender)
	print("Handler Removed")
end,5000,1)

removeEventHandler means to detach the function from the handler.

Edited by thisdp
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...