Jump to content

I need help Bad argument @ 'removeEventHandler'


DeadReacen

Recommended Posts

function cancel(source)
	local emprego = getElementData(source, "Emprego")
	if emprego == "Carnicero" then
		if isKeyBound(source, "fire", "down", cortarCarne) then
            hits[source] = nil
            tick[source] = nil
            removeEventHandler("onElementClicked", caixa[source], onClick)
			removeEventHandler("onPlayerQuit", source, reset)
			removeEventHandler("onPlayerWasted", source, reset)
			if isElement(carne[source]) then destroyElement(carne[source]) carne[source] = nil end
			if isElement(caixa[source]) then destroyElement(caixa[source]) caixa[source] = nil end
			if isTimer(timerEsteira[source]) then killTimer(timerEsteira[source]) timerEsteira[source] = nil end
			if isTimer(timerEntregar[source]) then killTimer(timerEntregar[source]) timerEntregar[source] = nil end
			toggleAllControls(source, true)
			unbindKey(source, "fire", "down", cortarCarne)
            setPedAnimation(source, "CARRY", "liftup", 0.0, false, false, false, false)
            setElementVisibleTo(empacotar, source, false)
            setElementVisibleTo(entregar, source, false)
		end
	end
end
addCommandHandler("cancelar", cancel)

Do you have any idea why I get this waring, and how to solve it? Thank you very much gentlemen

WARNING: Bad argument @ 'removeEventHandler' [Expected element at argument 2, got nil]

Link to comment
removeEventHandler("onElementClicked", caixa[source], onClick)

The error is potentially at this line. I guess you probably meant:

removeEventHandler("onElementClicked", source, onClick)

But you have to make sure that's exactly what you expect your code to do.

Tell me what does the table caixa do in your code?

 

 

  • Like 1
Link to comment
27 minutes ago, vicisdev said:
removeEventHandler("onElementClicked", caixa[source], onClick)

The error is potentially at this line. I guess you probably meant:

removeEventHandler("onElementClicked", source, onClick)

But you have to make sure that's exactly what you expect your code to do.

Tell me what does the table caixa do in your code?

 

 

Thank you very much for everything you have a lot of skill.

It is a work system, box table, it is the last function of the work itself.
works if meat = box,
The meat is turned into a box, it is a work role.

Link to comment
33 minutes ago, DeadReacen said:

Thank you very much for everything you have a lot of skill.

It is a work system, box table, it is the last function of the work itself.
works if meat = box,
The meat is turned into a box, it is a work role.

I still advise you to cautiously read through your code to understand if it's working properly. I think you were expecting to have a meat element inside the caixa table indexed by the source (a player), but that is not happening. Probably the line that was warning before isn't needed actually because since you are destroying the meat element later on the code all event handlers attached to it will also be deleted anyway.

  • Like 1
Link to comment
22 minutes ago, vicisdev said:

I still advise you to cautiously read through your code to understand if it's working properly. I think you were expecting to have a meat element inside the caixa table indexed by the source (a player), but that is not happening. Probably the line that was warning before isn't needed actually because since you are destroying the meat element later on the code all event handlers attached to it will also be deleted anyway.

I will be aware of that, for now the code is not throwing me any errors but I will do my best to improve it, I thank you for everything.

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