f8upd8 Posted July 19, 2017 Share Posted July 19, 2017 I need to create a system, that capable of draw text above elements heads and delete it. And there is my problem Let's assume that i did it via onClientRender.. So... And then i wanted to erase text. How can i remove event handler? I can't send my text arguments direct to onClientRender, so i need to use abstract function () inside onClientRender. And.. Is there way to remove handler? My server has a number of onClientRender handlers and won't delete incorrect handler. That looks like: ClientSide. addEvent("drawTextForElement", true) addEventHandler("drawTextForElement", getRootElement(), function () drawTextAbove(source, dText, dFont, dZize, dColor) end) function drawTextAbove(source, dText, dFont, dZize, dColor) local dText, dFont, dZize, dColor = dText, dFont, dZize, dColor local dElement = source addEventHandler("onClientRender", source, function () dxDrawTextOnElement(dElement ,"Kurisu",1,20,0,0,255,255,1,"arial") end) end ServerSide: triggerClientEvent(getRootElement(), "drawTextForElement", kurisu) Link to comment
Administrators Lpsd Posted July 19, 2017 Administrators Share Posted July 19, 2017 (edited) Store it as so local myFunction function drawTextAbove(source, dText, dFont, dZize, dColor) local dText, dFont, dZize, dColor = dText, dFont, dZize, dColor local dElement = source myFunction = function () dxDrawTextOnElement(dElement ,"Kurisu",1,20,0,0,255,255,1,"arial") end addEventHandler("onClientRender", source, myFunction) end And further to what you're trying to achieve: local myFunction local renderHandler = false addEvent("drawTextForElement", true) addEventHandler("drawTextForElement", getRootElement(), function () if renderHandler then removeEventHandler("onClientRender", source, myFunction) renderHandler = false end drawTextAbove(source, dText, dFont, dZize, dColor) end) function drawTextAbove(source, dText, dFont, dZize, dColor) local dText, dFont, dZize, dColor = dText, dFont, dZize, dColor local dElement = source myFunction = function () dxDrawTextOnElement(dElement ,"Kurisu",1,20,0,0,255,255,1,"arial") end addEventHandler("onClientRender", source, myFunction) renderHandler = true end A better way would be to just make your 'dText' (and such other variables) global, or atleast within the scope of this whole script; then create a named function instead of anonymous one. Edited July 19, 2017 by LopSided_ 1 Link to comment
f8upd8 Posted July 19, 2017 Author Share Posted July 19, 2017 15 minutes ago, LopSided_ said: Store it as so local myFunction function drawTextAbove(source, dText, dFont, dZize, dColor) local dText, dFont, dZize, dColor = dText, dFont, dZize, dColor local dElement = source myFunction = function () dxDrawTextOnElement(dElement ,"Kurisu",1,20,0,0,255,255,1,"arial") end addEventHandler("onClientRender", source, myFunction) end And further to what you're trying to achieve: local myFunction local renderHandler = false addEvent("drawTextForElement", true) addEventHandler("drawTextForElement", getRootElement(), function () if renderHandler then removeEventHandler("onClientRender", source, myFunction) renderHandler = false end drawTextAbove(source, dText, dFont, dZize, dColor) end) function drawTextAbove(source, dText, dFont, dZize, dColor) local dText, dFont, dZize, dColor = dText, dFont, dZize, dColor local dElement = source myFunction = function () dxDrawTextOnElement(dElement ,"Kurisu",1,20,0,0,255,255,1,"arial") end addEventHandler("onClientRender", source, myFunction) renderHandler = true end A better way would be to just make your 'dText' (and such other variables) global, or atleast within the scope of this whole script; then create a named function instead of anonymous one. Oh thank you! Your solution of function deanonymization fits perfectly! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now