Jump to content

dxImage


w3rt1x

Recommended Posts

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
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 by bover
  • Like 1
Link to comment
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
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

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