Jump to content

Help with trigger dx with i


VenomOG

Recommended Posts

Hello i have an inventory script and it works but its dx im wondering how to trigger it . 
 

addEvent("showInventory", true)
addEventHandler("showInventory", getRootElement(),

    function(itens, quant)




	addEventHandler("onClientRender",root,function()
	i = 0
	local screenW, screenH = guiGetScreenSize()
	isOpen = true
	for k,v in ipairs(itens) do
				
					i = i + 20
					  dxDrawImage(screenW * 0.3441, screenH * 0.3841, screenW * 0.3097, screenH * 0.5313, ":GTCHUD/img/background.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawImage(screenW * 0.2936, screenH * 0.3503, screenW * 0.4085, screenH * 0.0898, ":GTCpolicecomputer/button.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawText("User Inventory", screenW * 0.4129, screenH * 0.3568, screenW * 0.4736, screenH * 0.3789, tocolor(255, 255, 255, 255), 3.00, "default", "left", "top", false, false, false, false, false)
        dxDrawText("Item", screenW * 0.3755, screenH * 0.4531, screenW * 0.4627, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("Stock", screenW * 0.5461, screenH * 0.4531, screenW * 0.6332, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["item"].."", screenW * 0.3755, screenH * 0.4974+i, screenW * 0.4627, screenH * 0.5339, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["quant"].."", screenW * 0.5461, screenH * 0.4948+i, screenW * 0.6332, screenH * 0.5313, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)

      
				end
			end)
    
    end
)

addEvent("hideInventory", true)
addEventHandler("hideInventory", getRootElement(), function ()
	destroyElement(GUIEditor.window[1])
	isOpen = false
	removeEventHandler("onClientRender",root,ourdx)
end)

I want to render it but have acess to item,quant . and when hideInventory remove the render

Link to comment
9 minutes ago, IIYAMA said:

This is something you can do yourself, it isn't really that hard...

function renderInventory(itens, quant)
	i = 0
	local screenW, screenH = guiGetScreenSize()
	isOpen = true
	for k,v in ipairs(itens) do
				
					i = i + 20
					  dxDrawImage(screenW * 0.3441, screenH * 0.3841, screenW * 0.3097*v["item"], screenH * 0.5313, ":GTCHUD/img/background.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawImage(screenW * 0.2936, screenH * 0.3503, screenW * 0.4085, screenH * 0.0898, ":GTCpolicecomputer/button.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawText("User Inventory", screenW * 0.4129, screenH * 0.3568, screenW * 0.4736, screenH * 0.3789, tocolor(255, 255, 255, 255), 3.00, "default", "left", "top", false, false, false, false, false)
        dxDrawText("Item", screenW * 0.3755, screenH * 0.4531, screenW * 0.4627, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("Stock", screenW * 0.5461, screenH * 0.4531, screenW * 0.6332, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["item"].."", screenW * 0.3755, screenH * 0.4974+i, screenW * 0.4627, screenH * 0.5339, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["quant"].."", screenW * 0.5461, screenH * 0.4948+i, screenW * 0.6332, screenH * 0.5313, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)

      
				end
			end
addEvent("showInventory", true)
addEventHandler("showInventory", getRootElement(),

    function(itens, quant)
addRenderEvent(renderInventory, "onClientRender", itens, quant)


    end
)

addEvent("hideInventory", true)
addEventHandler("hideInventory", getRootElement(), function ()
	isOpen = false
	removeRenderEvent("onClientRender",root,renderInventory)
end)

Dosn't work.

And yes i added the source

Link to comment
  • Moderators
3 minutes ago, Knuck said:

function renderInventory(itens, quant)
	i = 0
	local screenW, screenH = guiGetScreenSize()
	isOpen = true
	for k,v in ipairs(itens) do
				
					i = i + 20
					  dxDrawImage(screenW * 0.3441, screenH * 0.3841, screenW * 0.3097*v["item"], screenH * 0.5313, ":GTCHUD/img/background.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawImage(screenW * 0.2936, screenH * 0.3503, screenW * 0.4085, screenH * 0.0898, ":GTCpolicecomputer/button.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawText("User Inventory", screenW * 0.4129, screenH * 0.3568, screenW * 0.4736, screenH * 0.3789, tocolor(255, 255, 255, 255), 3.00, "default", "left", "top", false, false, false, false, false)
        dxDrawText("Item", screenW * 0.3755, screenH * 0.4531, screenW * 0.4627, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("Stock", screenW * 0.5461, screenH * 0.4531, screenW * 0.6332, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["item"].."", screenW * 0.3755, screenH * 0.4974+i, screenW * 0.4627, screenH * 0.5339, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["quant"].."", screenW * 0.5461, screenH * 0.4948+i, screenW * 0.6332, screenH * 0.5313, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)

      
				end
			end
addEvent("showInventory", true)
addEventHandler("showInventory", getRootElement(),

    function(itens, quant)
addRenderEvent(renderInventory, "onClientRender", itens, quant)


    end
)

addEvent("hideInventory", true)
addEventHandler("hideInventory", getRootElement(), function ()
	isOpen = false
	removeRenderEvent("onClientRender",root,renderInventory)
end)

Dosn't work.

And yes i added the source

Add some debug lines, so that you can inform me what doesn't work.

 

 

Link to comment
1 hour ago, Knuck said:

Hello i have an inventory script and it works but its dx im wondering how to trigger it . 
 


addEvent("showInventory", true)
addEventHandler("showInventory", getRootElement(),

    function(itens, quant)




	addEventHandler("onClientRender",root,function()
	i = 0
	local screenW, screenH = guiGetScreenSize()
	isOpen = true
	for k,v in ipairs(itens) do
				
					          if v = 20 then break end

					  dxDrawImage(screenW * 0.3441, screenH * 0.3841, screenW * 0.3097, screenH * 0.5313, ":GTCHUD/img/background.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawImage(screenW * 0.2936, screenH * 0.3503, screenW * 0.4085, screenH * 0.0898, ":GTCpolicecomputer/button.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawText("User Inventory", screenW * 0.4129, screenH * 0.3568, screenW * 0.4736, screenH * 0.3789, tocolor(255, 255, 255, 255), 3.00, "default", "left", "top", false, false, false, false, false)
        dxDrawText("Item", screenW * 0.3755, screenH * 0.4531, screenW * 0.4627, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("Stock", screenW * 0.5461, screenH * 0.4531, screenW * 0.6332, screenH * 0.4896, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["item"].."", screenW * 0.3755,( screenH * 0.4974)*v, screenW * 0.4627, screenH * 0.5339, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText(""..v["quant"].."", screenW * 0.5461,( screenH * 0.4948)*v, screenW * 0.6332, screenH * 0.5313, tocolor(255, 255, 255, 255), 1.20, "default-bold", "left", "top", false, false, false, false, false)
      
				end
			end)
    
    end
)

addEvent("hideInventory", true)
addEventHandler("hideInventory", getRootElement(), function ()
	destroyElement(GUIEditor.window[1])
	isOpen = false
	removeEventHandler("onClientRender",root,ourdx)
end)

I want to render it but have acess to item,quant . and when hideInventory remove the render

 

Link to comment
  • Moderators

See also the reply before this one.

 

@Knuck

You can also try to run the older version. Which I have personally validated.

Spoiler

--------------------
-- Author: IIYAMA --
--------------------

local renderEvents = {
	"onClientRender",
	"onClientPreRender",
	"onClientHUDRender"
}

local allTargetFunctions = {} -- All attached functions will be stored in this table.

local acceptedRenderEventTypes = {} -- Is type in use? See: renderEvents.
local renderEventTypeStatus = {} -- Is the event in use? (so it doesn't have to be attached again)




do
	-- prepare the data
	for i=1, #renderEvents do
		local event = renderEvents[i]
		allTargetFunctions[event] = {}
		acceptedRenderEventTypes[event] = true
		renderEventTypeStatus[event] = false
	end
end

-- render all events here
local processTargetFunction = function (timeSlice)
	local targetFunctions = allTargetFunctions[eventName]
	for i=#targetFunctions, 1, -1  do
		local targetFunctionData = targetFunctions[i]
		local arguments = targetFunctionData[2]
		if not arguments then
			targetFunctionData[1](timeSlice)
		else
			if timeSlice then
				targetFunctionData[1](timeSlice, unpack(arguments))
			else
				targetFunctionData[1](unpack(arguments))
			end
		end
	end
end



-- check if a function is already attached
local checkIfFunctionIsTargetted = function (theFunction, event)
	if not event or not acceptedRenderEventTypes[event] then
		event = "onClientRender"
	end
	local targetFunctions = allTargetFunctions[event]
	for i=1, #targetFunctions do
		if targetFunctions[i][1] == theFunction then
			return true
		end
	end
	return false
end

-- add render event, default type is onClientRender
function addRenderEvent(theFunction, event, ...)
	if not event or not acceptedRenderEventTypes[event] then
		event = "onClientRender"
	end
	if not checkIfFunctionIsTargetted(theFunction) then
		local targetFunctions = allTargetFunctions[event]
		targetFunctions[#targetFunctions + 1] = {theFunction, {...}}
		
		-- attach an event
		if not renderEventTypeStatus[event] then
			addEventHandler (event, root, processTargetFunction, false, "high")
			renderEventTypeStatus[event] = true
		end
		return true
	end
	return false
end

-- remove a render event
function removeRenderEvent(theFunction, event)
	if not event or not acceptedRenderEventTypes[event] then
		event = "onClientRender"
	end
	local targetFunctions = allTargetFunctions[event]
	for i=1, #targetFunctions do
		if targetFunctions[i][1] == theFunction then
			table.remove(targetFunctions, i)
			if #targetFunctions == 0 then
				if renderEventTypeStatus[event] then
					removeEventHandler (event, root, processTargetFunction)
					renderEventTypeStatus[event] = false
				end
			end
			return true
		end
	end
	return false
end

 

 

Link to comment
4 minutes ago, Knuck said:

Im trying to render it with the data from server and be able to remove render when hide inventory, but ty for try lil

 

4 minutes ago, Knuck said:

Im trying to render it with the data from server and be able to remove render when hide inventory, but ty for try lil

i cant see anything about RenderTarget here just try to change your lines

 

Edited by LilDawage
Link to comment
20 minutes ago, IIYAMA said:

See also the reply before this one.

 

@Knuck

You can also try to run the older version. Which I have personally validated.

  Hide contents


 ---------------------- Author: IIYAMA ----------------------local renderEvents = {	"onClientRender",	"onClientPreRender",	"onClientHUDRender"}local allTargetFunctions = {} -- All attached functions will be stored in this table.local acceptedRenderEventTypes = {} -- Is type in use? See: renderEvents.local renderEventTypeStatus = {} -- Is the event in use? (so it doesn't have to be attached again)do	-- prepare the data	for i=1, #renderEvents do		local event = renderEvents[i]		allTargetFunctions[event] = {}		acceptedRenderEventTypes[event] = true		renderEventTypeStatus[event] = false	endend-- render all events herelocal processTargetFunction = function (timeSlice)	local targetFunctions = allTargetFunctions[eventName]	for i=#targetFunctions, 1, -1  do		local targetFunctionData = targetFunctions[i]		local arguments = targetFunctionData[2]		if not arguments then			targetFunctionData[1](timeSlice)		else			if timeSlice then				targetFunctionData[1](timeSlice, unpack(arguments))			else				targetFunctionData[1](unpack(arguments))			end		end	endend-- check if a function is already attachedlocal checkIfFunctionIsTargetted = function (theFunction, event)	if not event or not acceptedRenderEventTypes[event] then		event = "onClientRender"	end	local targetFunctions = allTargetFunctions[event]	for i=1, #targetFunctions do		if targetFunctions[i][1] == theFunction then			return true		end	end	return falseend-- add render event, default type is onClientRenderfunction addRenderEvent(theFunction, event, ...)	if not event or not acceptedRenderEventTypes[event] then		event = "onClientRender"	end	if not checkIfFunctionIsTargetted(theFunction) then		local targetFunctions = allTargetFunctions[event]		targetFunctions[#targetFunctions + 1] = {theFunction, {...}}				-- attach an event		if not renderEventTypeStatus[event] then			addEventHandler (event, root, processTargetFunction, false, "high")			renderEventTypeStatus[event] = true		end		return true	end	return falseend-- remove a render eventfunction removeRenderEvent(theFunction, event)	if not event or not acceptedRenderEventTypes[event] then		event = "onClientRender"	end	local targetFunctions = allTargetFunctions[event]	for i=1, #targetFunctions do		if targetFunctions[i][1] == theFunction then			table.remove(targetFunctions, i)			if #targetFunctions == 0 then				if renderEventTypeStatus[event] then					removeEventHandler (event, root, processTargetFunction)					renderEventTypeStatus[event] = false				end			end			return true		end	end	return falseend

 

 

Works thank you.

 

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