Jump to content

[HELP] addEventHandler function is already handled


Maruchan

Recommended Posts

I have this error in the following function:

bad usage@ addeventhandler OnclientRender with this function is already handled

Solution please? =(
function Imagen_al_morir()
		 addEventHandler("onClientRender", root, MuerteSistema) -- ERROR
		 tempo = 30
		 setElementData(localPlayer,'tiempo_de_respawn',tempo)
		 setTimer (function() 
		 tempo = tempo-1 	
		 setElementData(localPlayer,'tiempo_de_respawn',tempo)
		 end,1000,30)	
		 setTimer (function() 
		 removeEventHandler("onClientRender", root, MuerteSistema)
		 end,1000*30,1)
end

 

Link to comment

Hey,

It's more lika a warning than an error. It tells you that this event handler is already existing.
To prevent it use removeEventHandler before the addEventHandler.

PS: You might need better organization of the work of this function cuz it appears that it gets called before the operations in it are done.
The event handler is getting removed after 30 seconds and the function gets called before this time passes.
 

Edited by SpecT
Link to comment
5 hours ago, SpecT said:

Hey,

It's more lika a warning than an error. It tells you that this event handler is already existing.
To prevent it use removeEventHandler before the addEventHandler.

PS: You might need better organization of the work of this function cuz it appears that it gets called before the operations in it are done.
The event handler is getting removed after 30 seconds and the function gets called before this time passes.
 

		 
This is the complete function, I have tried but cannot fix it. Please help :(

		 local startTicking = getTickCount()
		 local rotation = 0
		 --
		 fading = 0
		 fading2 = "up"
		 
function MuerteSistema()

		 local screenW, screenH = guiGetScreenSize()
		 local sX, sY = guiGetScreenSize()
	     --local width, height = sX*(150/1336), sY*(200/768)
		 local width, height = sX*(100/1336), sY*(120/768)
		 rotation = rotation - 2 > 360 and 0 or rotation - 2
		 dxDrawImage(screenW * 0.0000, screenH * 0.0000, screenW * 1.0000, screenH * 1.0000, "Imagenes/muerte.jpg", 0, 0, 0, tocolor(255, 255, 255, 255), true)
		 dxDrawImage(sX/2-width/2, sY/2-height/2, width, height, "Imagenes/cargando.png", rotation, 0, 0, tocolor(255, 255, 255, 255), true)  
		 number = getElementData(localPlayer,"tiempo_de_respawn") or 0
		 
         dxDrawText("¡Has muerto!", 454 - 1, 250 - 1, 924 - 1, 326 - 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("¡Has muerto!", 454 + 1, 250 - 1, 924 + 1, 326 - 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("¡Has muerto!", 454 - 1, 250 + 1, 924 - 1, 326 + 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("¡Has muerto!", 454 + 1, 250 + 1, 924 + 1, 326 + 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("¡Has muerto!", 454, 250, 924, 326, tocolor(0, 0, 0, 255), 1, GroupTeenArg, "center", "center", true, true, true, true, true)

         dxDrawText("Reaparecerás en: "..math.round((number/1),0).." segundos", 456 - 1, 500 - 1, 926 - 1, 463 - 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("Reaparecerás en: "..math.round((number/1),0).." segundos", 456 + 1, 500 - 1, 926 + 1, 463 - 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("Reaparecerás en: "..math.round((number/1),0).." segundos", 456 - 1, 500 + 1, 926 - 1, 463 + 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("Reaparecerás en: "..math.round((number/1),0).." segundos", 456 + 1, 500 + 1, 926 + 1, 463 + 1, tocolor(255, 255, 255, fading), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
         dxDrawText("Reaparecerás en: "..math.round((number/1),0).." segundos", 456, 500, 926, 463, tocolor(0, 0, 0), 1, GroupTeenArg, "center", "center", true, true, true, true, true)
	 
end


function Info_al_morir ()
		 fadeCamera (false, 1.0, 0, 0, 0 ) 
		 setTimer(Imagen_al_morir,2000,1)
		 number = math.random(0,1)
		 if number == 1 then 
		 morir = playSound('Sonidos/Morir/morir.ogg',false)
		 end
end
addEvent("onClientPlayerDeathInfo",true)
addEventHandler("onClientPlayerDeathInfo",getRootElement(),Info_al_morir)

		 SonidoAlMorir = function()
		 if isElement(morir) then 
		 stopSound(morir)
		 end
		 end
		 
function Imagen_al_morir()
		 addEventHandler("onClientRender", root, MuerteSistema)
		 tempo = 30
		 setElementData(localPlayer,'tiempo_de_respawn',tempo)
		 setTimer (function() 
		 tempo = tempo-1 	
		 setElementData(localPlayer,'tiempo_de_respawn',tempo)
		 end,1000,30)	
		 setTimer (function() 
		 removeEventHandler("onClientRender", root, MuerteSistema)
		 end,1000*30,1)
end

		 if fileExists("Sistema-de-muerte-media.lua") == true then
		 fileDelete("Sistema-de-muerte-media.lua")
		 end	

 

Edited by Maruchan
Link to comment
22 hours ago, Maruchan said:

 

bad usage@ addeventhandler OnclientRender with this function is already handled



 

 

Try adding a check so it doesn't repeat itself

local DXShowing = false

function Imagen_al_morir()
	if DXShowing == false then 
		DXShowing = true 
		addEventHandler("onClientRender", root, MuerteSistema)
	end 
	tempo = 30
	setElementData(localPlayer,'tiempo_de_respawn',tempo)
	setTimer (function() 
		tempo = tempo-1 	
		setElementData(localPlayer,'tiempo_de_respawn',tempo)
	end,1000,30)	
	setTimer (function() 
		DXShowing = false 
		removeEventHandler("onClientRender", root, MuerteSistema)
	end,1000*30,1)
end

 

  • Thanks 1
Link to comment
  • Patrick changed the title to [HELP] addEventHandler function is already handled

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