Jump to content

[HELP] DX Bug


Erknneto

Recommended Posts

Hi!
I have a problem with my DX script.
I made a DX screen that gets the items in a table and display it on the rectangle
The problem is, it's multiplying everything that is related with the text.

This is how the issue looks in game, look at the rectangle with the texts, it's multiplying everything!
VHsixqPsQSyLiD_-EabOgA.png

And here is my code:
 

-------------------------------------------------------
local itemList = {
{"Wooden Wall"},
{"Wooden Doorway"},
{"Wooden Window"},
{"Wooden Floor"},
{"Wooden Floorport"},
{"Wooden Stairs"},
{"Wooden Fence"},
{"Wooden Door"},
{"Wooden Gate"},
{"Metal Wall"},
{"Metal Doorway"},
{"Metal Window"},
{"Metal Floor"},
{"Metal Floorport"},
{"Metal Stairs"},
{"Metal Fence"},
{"Metal Door"},
{"Metal Gate"},
{"Concrete Wall"},
{"Concrete Doorway"},
{"Concrete Window"},
{"Concrete Floor"},
{"Concrete Floorport"},
{"Concrete Stairs"},
{"Concrete Fence"},
{"Reinforced Door"},
{"Reinforced Gate"},
}
-------------------------------------------------------
function returnTableCount (tab)
	count = 1
	if ( getLocalPlayer() ) then
		for i,item in ipairs(tab) do
			if ( item ) then
				count = count + 1
			end
		end
		return count
	end
	return false
end
-------------------------------------------------------
local totalRows = returnTableCount(itemList)
local iRows = totalRows 
local iVisibleRows = 20
local iCurrentCell = 0 
-------------------------------------------------------
local screenWidth,screenHeight = guiGetScreenSize()
local screenW, screenH = guiGetScreenSize()
local sx,sy = guiGetScreenSize() 
local px,py = 1366,768
local x,y =  (sx/px), (sy/py) 
-------------------------------------------------------

function isCursorOverRectangle(x,y,w,h) 
	if isCursorShowing() then 
		local mx,my = getCursorPosition()
		cursorx,cursory = mx*px,my*py 
		if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then 
			return true 
		end 
	end 
	return false 
end

function drawInventory ()
	if ( getElementData(getLocalPlayer(),"viewingInv") ) then
		titleTable = dxDrawRectangle(x*050, y*040, x*350, y*45, tocolor(0, 77, 126, 170), false)
		titleText = dxDrawText("Building",x*060, y*055, x*250, y*30,tocolor(255,255,255, 255))
		mainTable = dxDrawRectangle(x*050, y*090, x*350, y*640, tocolor(0, 0, 0, 170), false)
		
		for i,item in ipairs(itemList) do
			for ki = iCurrentCell, iVisibleRows+iCurrentCell-1 do 
				visibleI = ki - iCurrentCell
				dxDrawRectangle(x*050+x*350, y*090+y*640/iRows*iCurrentCell, 5, y*640/iRows*iVisibleRows) 
			
				itemBackground = dxDrawRectangle(x*060, y*100+visibleI*31, x*200, y*30, tocolor(0, 0, 0, 200), false)
				itemText = dxDrawText(item[1],x*070, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255)) --Problem is here :C
		
				useBackground = dxDrawRectangle(x*265, y*100+visibleI*31, x*60, y*30, tocolor(0, 0, 0, 200), false)
				useText = dxDrawText("Text",x*282, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255))
		
				dropBackground = dxDrawRectangle(x*330, y*100+visibleI*31, x*60, y*30, tocolor(0, 0, 0, 200), false)
				dropText = dxDrawText("Text",x*347, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255))

				if isCursorOverRectangle(x*060, y*100+visibleI*31, x*200, y*30) or isCursorOverRectangle(x*265, y*100+visibleI*31, x*60, y*30) or isCursorOverRectangle(x*330, y*100+visibleI*31, x*60, y*30) then 
					dxDrawRectangle(x*060, y*100+visibleI*31, x*200, y*30, tocolor(0, 77, 126,20)) 
					dxDrawRectangle(x*265, y*100+visibleI*31, x*60, y*30, tocolor(0, 77, 126,20)) 
					dxDrawRectangle(x*330, y*100+visibleI*31, x*60, y*30, tocolor(0, 77, 126,20)) 
				end
			end
		end
	end
end
addEventHandler("onClientRender",getRootElement(),drawInventory)

function rustCraftScrollUp ()
	if ( getElementData(getLocalPlayer(),"viewingInv") ) then
		if isCursorOverRectangle(x*050, y*090, x*350, y*640) then
			iCurrentCell = iCurrentCell - 1 
			if iCurrentCell < 0 then iCurrentCell = 0 end 
		end
	end
end
bindKey("mouse_wheel_up","down",rustCraftScrollUp)

function rustCraftScrollDown ()
	if ( getElementData(getLocalPlayer(),"viewingInv") ) then
		if isCursorOverRectangle(x*050, y*090, x*350, y*640) then 
			iCurrentCell = iCurrentCell + 1 
			if iCurrentCell > iRows-iVisibleRows then iCurrentCell = iRows-iVisibleRows end 
		end
	end
end
bindKey("mouse_wheel_down","down",rustCraftScrollDown)

function showInventory ()
	if ( getElementData(getLocalPlayer(),"viewingInv") ) then
		setElementData(getLocalPlayer(),"viewingInv",false)
		showCursor(false)
		showChat(true)
	else
		setElementData(getLocalPlayer(),"viewingInv",true)
		showCursor(true)
		showChat(false)
	end
end
bindKey("k","down",showInventory)


How can I get the items in that table 'itemList' and put it in the screen that the dxGridList works without multiplying those stuff?
I hope you guys undestand my problem :v pls help

Edited by Erknneto
Link to comment
  • Moderators

It is duplicated because of double loops. Just use one.

 

--for i,item in ipairs(itemList) do
for ki = iCurrentCell, iVisibleRows+iCurrentCell-1 do 
	
	local visibleI = ki - iCurrentCell
	dxDrawRectangle(x*050+x*350, y*090+y*640/iRows*iCurrentCell, 5, y*640/iRows*iVisibleRows) 
	
	local index = ki + 1 -- ki starts at 0, in lua we start with 1.
	local item = itemList[index]
	if item then
		dxDrawRectangle(x*060, y*100+visibleI*31, x*200, y*30, tocolor(0, 0, 0, 200), false) -- NOT AN ELEMENT:  itemBackground = 
		dxDrawText(item[1],x*070, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255)) --Problem is here :C

		dxDrawRectangle(x*265, y*100+visibleI*31, x*60, y*30, tocolor(0, 0, 0, 200), false) -- NOT AN ELEMENT: useBackground =
		dxDrawText("Text",x*282, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255)) -- NOT AN ELEMENT: useText = 

		dxDrawRectangle(x*330, y*100+visibleI*31, x*60, y*30, tocolor(0, 0, 0, 200), false) -- NOT AN ELEMENT: dropBackground = 
		dxDrawText("Text",x*347, y*107+visibleI*31, x*250, y*30,tocolor(255,255,255, 255)) -- NOT AN ELEMENT: dropText = 

		if isCursorOverRectangle(x*060, y*100+visibleI*31, x*200, y*30) or isCursorOverRectangle(x*265, y*100+visibleI*31, x*60, y*30) or isCursorOverRectangle(x*330, y*100+visibleI*31, x*60, y*30) then 
			dxDrawRectangle(x*060, y*100+visibleI*31, x*200, y*30, tocolor(0, 77, 126,20)) 
			dxDrawRectangle(x*265, y*100+visibleI*31, x*60, y*30, tocolor(0, 77, 126,20)) 
			dxDrawRectangle(x*330, y*100+visibleI*31, x*60, y*30, tocolor(0, 77, 126,20)) 
		end
	end
end
--end

 

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