w3rt1x Posted December 24, 2022 Share Posted December 24, 2022 (edited) Hello everyone! I wanna draw dxDrawImage when I clicked "O" on keyboard and destroy it to same button keyboard. How can I do that? @Shady1 Edited December 24, 2022 by w3rt1x Link to comment
Shady1 Posted December 24, 2022 Share Posted December 24, 2022 3 hours ago, w3rt1x said: Hello everyone! I wanna draw dxDrawImage when I clicked "O" on keyboard and destroy it to same button keyboard. How can I do that? @Shady1 hi, thanks for tagging me and asking for help, I have prepared a line of code to help you, I hope it will be useful for you. you can do this using a variable and bindKey local isImage = false addEventHandler("onClientRender", root, function() if(isImage) then dxDrawImage(...) -- draw image if isImage true end end ) bindKey("o", "down", function() if(isImage) then isImage = false else isImage = true end end ) Link to comment
bover Posted December 24, 2022 Share Posted December 24, 2022 (edited) 3 hours ago, Shady1 said: hi, thanks for tagging me and asking for help, I have prepared a line of code to help you, I hope it will be useful for you. you can do this using a variable and bindKey local isImage = false addEventHandler("onClientRender", root, function() if(isImage) then dxDrawImage(...) -- draw image if isImage true end end ) bindKey("o", "down", function() if(isImage) then isImage = false else isImage = true end end ) Better to remove event handler while not using. Also watch out for a pyramids if and else local isRendering function renderImage() dxDrawImage(...) end function bindKey() isRendering = not isRendering if (isRendering) then addEventHandler('onClientRender', root, renderImage) return true end removeEventHandler('onClientRender', root, renderImage) end bindKey('o', 'down', bindKey) Edited December 24, 2022 by bover 1 Link to comment
Shady1 Posted December 24, 2022 Share Posted December 24, 2022 56 minutes ago, bover said: Better to remove event handler while not using. Also watch out for a pyramids if and else local isRendering function renderImage() dxDrawImage(...) end function bindKey() isRendering = not isRendering if (isRendering) then addEventHandler('onClientRender', root, renderImage) return true end removeEventHandler('onClientRender', root, renderImage) end bindKey('o', 'down', bindKey) thanks for trying to add comments but your code is not working i think you need to improve this code or i can do it for you... bindKey has the same name as your function local isRendering function renderImage() end function bindRender() --change this isRendering = not isRendering outputDebugString(isRendering) if (isRendering) then addEventHandler('onClientRender', root, renderImage) return true end removeEventHandler('onClientRender', root, renderImage) end bindKey('o', 'down', bindRender) Link to comment
bover Posted December 27, 2022 Share Posted December 27, 2022 On 24/12/2022 at 17:34, Shady1 said: thanks for trying to add comments but your code is not working i think you need to improve this code or i can do it for you... bindKey has the same name as your function local isRendering function renderImage() end function bindRender() --change this isRendering = not isRendering outputDebugString(isRendering) if (isRendering) then addEventHandler('onClientRender', root, renderImage) return true end removeEventHandler('onClientRender', root, renderImage) end bindKey('o', 'down', bindRender) Oh, my bad. Didn't think about this 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