Jump to content

gui Inventory - problem


sacr1ficez

Recommended Posts

Posted

Hey. I need a little help from you guys. 

row1, column1 = guiGridListGetSelectedItem(gridlistItems["inventory"])

if row1 and column1 then
  guiGridListSetSelectedItem(gridlistItems["inventory"], row1, column1)
  end

 

This thing select next item in inventory, it works as it should, however if this is last item then item which it's above don't select, and i need to mark it manually.

Posted

I don't really understand your problem. BUT, I think this should help:

row1, column1 = guiGridListGetSelectedItem(gridlistItems["inventory"])

if row1 and column1 then
  guiGridListSetSelectedItem(gridlistItems["inventory"], row1, column1)
  if row1 == -1 then guiGridListSetSelectedItem(gridlistItems["inventory"], 0, column1) end
  end

 

Scripts

1. Mission: Pizza delivery [OPEN SOURCE]

Posted
1 hour ago, Peti said:

I don't really understand your problem. BUT, I think this should help:


row1, column1 = guiGridListGetSelectedItem(gridlistItems["inventory"])

if row1 and column1 then
  guiGridListSetSelectedItem(gridlistItems["inventory"], row1, column1)
  if row1 == -1 then guiGridListSetSelectedItem(gridlistItems["inventory"], 0, column1) end
  end

 

Tested it and doesn't work. I tried to change

guiGridListSetSelectedItem(gridlistItems["inventory"], row1, column1)

on

guiGridListSetSelectedItem(gridlistItems["inventory"], row1 - 1, column1)

 

It works, however it executes each time player drop a item. I will try to explain it better, here's a picture.

ADflonN.png

 

Green arrow (from top to bottom):

- Player drop a item, Pepsi. When there's no more Pepsi, script marks next item (Coca-Cola)

- Player drop a item, Coca-Cola, When there's no more Coca-Cola, script marks next item (Mountain Dew)

- Player drop a item, Mountain Dew, When there's no more Mountain Dew, script clear selection (which it's fine, because there's no more items in this category)

 

Red arrow (from bottom to top):

- Player drop a item, Mountain Dew, When there's no more Mountain Dew, script clear selection (and that's the problem, because it should mark the item which is above - Coca-Cola)

 

By other words, if player drop item from bottom, script should mark next item, because of that player is forced to do it manually.

Posted (edited)
5 hours ago, majqq said:

Hey. I need a little help from you guys. 


row1, column1 = guiGridListGetSelectedItem(gridlistItems["inventory"])

if row1 and column1 then
  guiGridListSetSelectedItem(gridlistItems["inventory"], row1, column1)
  end

 

This thing select next item in inventory, it works as it should, however if this is last item then item which it's above don't select, and i need to mark it manually.

An easy way to select the last gridlist row:

	local lastRow = guiGridListGetRowCount(gridlistItems["inventory"])
	guiGridListSetSelectedItem( gridlistItems["inventory"], lastRow, column1 )

How do you know when you'll need to use this function? > By checking if the dropped item row is the last one in gridlist.

Edited by DNL291

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
1 hour ago, DNL291 said:

An easy way to select the last gridlist row:


	local lastRow = guiGridListGetRowCount(gridlistItems["inventory"])
	guiGridListSetSelectedItem( gridlistItems["inventory"], lastRow, column1 )

How do you know when you'll need to use this function? > By checking if the dropped item row is the last one in gridlist.

I'll test it out soon, thanks for answer ☺️

Posted (edited)
15 hours ago, majqq said:

I'll test it out soon, thanks for answer ☺️

@DNL291 I tried to do it, but doesn't work, I am sure that i am doing it wrong.

row1, column1 = guiGridListGetSelectedItem(gridlistItems["inventory"]) -- this is at beginning of function which refresh player inventory.

local row = guiGridListAddRow(gridlistItems["inventory"]) -- this is in middle of function, there's some more loops with other categories.
		guiGridListSetItemText(gridlistItems["inventory"], row, gridlistItems["inventory_colum"], "Food and Drinks", true, false)
		for i, item in ipairs(inventoryItems["Food and Drinks"]) do
			if getElementData(getLocalPlayer(), item[1]) and getElementData(getLocalPlayer(), item[1]) >= 1 then
				local row = guiGridListAddRow(gridlistItems["inventory"])
				guiGridListSetItemText(gridlistItems["inventory"], row, gridlistItems["inventory_colum"], item[1], false, false)
				guiGridListSetItemText(gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"], getElementData(getLocalPlayer(), item[1]), false, false)
			end
		end

if row1 and column1 then -- and this is nearly at the end of function
			guiGridListSetSelectedItem(gridlistItems["inventory"], row1, column1)
		end

 

Or i should do it after player drop a item. I don't have idea, can u help me a bit? This is clear, not edited function.

Edited by majqq
Posted (edited)

Hm, have you tried saving the index before deleting the item and then forcing a new selection using said index?

I mean:

item1 -- 0
item2 -- 1
item3 -- 2

Delete item2(save index first, then delete it)
Force selection on saved index.

Edited by Peti

Scripts

1. Mission: Pizza delivery [OPEN SOURCE]

Posted (edited)

I made this custom command for you as an example of what I'm saying:

local anchoPantalla, largoPantalla = guiGetScreenSize()
function obtenerPosicionVentana(ancho, largo)
    local x = anchoPantalla / 2 - ancho / 2
    local y = largoPantalla / 2 - largo / 2

    return x, y, ancho, largo
end

local tableItems = { 'item1', 'item2', 'item3' }
local itemRow = 1
function createTable()
    local x, y, ancho, largo = obtenerPosicionVentana(400, 400)
    local windowItems = guiCreateWindow(x, y, ancho, largo, 'Example', false)
    local listItems = guiCreateGridList(0.04, 0.1, 0.4, 0.78, true, windowItems)
    local columnItems = guiGridListAddColumn(listItems, 'Items', 0.75)
    if (columnItems) then
        for _, item in pairs(tableItems) do
            local row = guiGridListAddRow(listItems, item)
            guiGridListSetItemText(listItems, row, columnItems, item, false, true)
        end
    end
    local btn = guiCreateButton(0.55, 0.1, 0.2, 0.1, 'Delete', true, windowItems)

    showCursor(true)

    itemRow = itemRow - 1
    if #tableItems == 1 then itemRow = 0 end
    if itemRow == #tableItems then itemRow = itemRow - 1 end
    guiGridListSetSelectedItem(listItems, itemRow, 1, true)

    addEventHandler('onClientGUIClick', btn, function (boton, estado)
        if boton == 'left' and estado == 'up' then
            itemRow = guiGridListGetSelectedItem (listItems)
            itemRow = itemRow + 1
            table.remove(tableItems, itemRow)
            local timer = setTimer(createTable, 100, 1)
            destroyElement(windowItems)
        end
    end, false)
end
addCommandHandler('items', createTable)

THIS IS NOT A SOLUTION, JUST AN EXAMPLE.

Edited by Peti

Scripts

1. Mission: Pizza delivery [OPEN SOURCE]

Posted
16 hours ago, Peti said:

I made this custom command for you as an example of what I'm saying:


local anchoPantalla, largoPantalla = guiGetScreenSize()
function obtenerPosicionVentana(ancho, largo)
    local x = anchoPantalla / 2 - ancho / 2
    local y = largoPantalla / 2 - largo / 2

    return x, y, ancho, largo
end

local tableItems = { 'item1', 'item2', 'item3' }
local itemRow = 1
function createTable()
    local x, y, ancho, largo = obtenerPosicionVentana(400, 400)
    local windowItems = guiCreateWindow(x, y, ancho, largo, 'Example', false)
    local listItems = guiCreateGridList(0.04, 0.1, 0.4, 0.78, true, windowItems)
    local columnItems = guiGridListAddColumn(listItems, 'Items', 0.75)
    if (columnItems) then
        for _, item in pairs(tableItems) do
            local row = guiGridListAddRow(listItems, item)
            guiGridListSetItemText(listItems, row, columnItems, item, false, true)
        end
    end
    local btn = guiCreateButton(0.55, 0.1, 0.2, 0.1, 'Delete', true, windowItems)

    showCursor(true)

    itemRow = itemRow - 1
    if #tableItems == 1 then itemRow = 0 end
    if itemRow == #tableItems then itemRow = itemRow - 1 end
    guiGridListSetSelectedItem(listItems, itemRow, 1, true)

    addEventHandler('onClientGUIClick', btn, function (boton, estado)
        if boton == 'left' and estado == 'up' then
            itemRow = guiGridListGetSelectedItem (listItems)
            itemRow = itemRow + 1
            table.remove(tableItems, itemRow)
            local timer = setTimer(createTable, 100, 1)
            destroyElement(windowItems)
        end
    end, false)
end
addCommandHandler('items', createTable)

THIS IS NOT A SOLUTION, JUST AN EXAMPLE.

 

Thank you, i'll try it out soon.

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