Jump to content

Remove an Event Handler


Z4Zy

Recommended Posts

Hello !

when there's an event handler like below,

function vehicleEnter(vehicle,seat)
    if seat == 0 then
        outputChatBox("You have entered a "..getVehicleName(vehicle),source,255,255,0)
	end
end

addEventHandler("onPlayerVehicleEnter",root,vehicleEnter)

we can remove it from one line code like below,

removeEventHandler("onPlayerVehicleEnter",root,vehicleEnter)

So that's all. BUT !,

when there's an event handler like below,

addEventHandler("onPlayerVehicleEnter",root,
function (vehicle,seat)
    if seat == 0 then
        outputChatBox("You have entered a "..getVehicleName(vehicle),source,255,255,0)
    end
end
)

How to remove that event handler ? are there any way ?

Link to comment
4 minutes ago, MIKI785 said:

You can't remove that. It's an anonymous function, so you don't have the pointer to it (its name). You can't reference anonymous functions, therefore you can't reference it in removeEventHandler.

so, aren't there  any why to remove that type of event handlers ?

Link to comment
  • Moderators
local handlers = {}
do
 local _addEventHandler = addEventHandler
 function addEventHandler (...)
  local result = _addEventHandler(...)
  if result then
   handlers[#handlers + 1] = {...}
   return result
  end
 end
end

Wrap it.

Just make sure to clean the table once in while. ?

 

Or get the attached function with this function, if you know the event and the element.

https://wiki.multitheftauto.com/wiki/GetEventHandlers

 

____

 

 

Yet, you can better name your a dogs. If it is called fluffy, then you only have to call 'fluffy, your dinner is ready' and it will surely come back to you.

If you didn't name him, then you have call out like this 'fluffy-dinner is ready'. After that I am not sure how many streetdogs will come back to you. (Not even sure if fluffy would survive that...)

 

 

 

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