swag_k_dog Posted July 6, 2017 Share Posted July 6, 2017 addEventHandler("onClientResourceStart", resourceRoot, function() inventoryWindow = guiCreateWindow(0.05, 0.04, 0.46, 0.65, "", true) guiWindowSetSizable(inventoryWindow, false) guiSetAlpha(inventoryWindow, 1.00) slot1 = guiCreateButton(15, 34, 82, 78, "", false, inventoryWindow) slot2 = guiCreateButton(0.02, 0.27, 0.13, 0.16, "", true, inventoryWindow) slot3 = guiCreateButton(0.02, 0.47, 0.13, 0.16, "", true, inventoryWindow) slot4 = guiCreateButton(0.02, 0.68, 0.13, 0.16, "", true, inventoryWindow) end ) this is a simple window with 4 inventory slots example: an admin uses this command to a player: giveWeapon and slot 1 becomes this: guiSetText slot1 Weapon_Name and all the slots working, for example if slot 1 is occupied, the next giveWeapon command will apply on the next slot. everything working until no more slots available.. I just need an idea of how to script this, please explain simple? thanks Link to comment
Rose Posted July 6, 2017 Share Posted July 6, 2017 Store the buttons in a table and loop it. For example: local slots = { } local maxslots = 4 for i = 1, maxslots do if slots[i] == nil then -- check if a table element is nil... slots[i] = "the object" -- store it print( i, slots[i] ) -- 1, "the object" break end end In your case, use guiGetText. ( i'm sorry, i do not speak english and can not explain you well ...) Link to comment
pa3ck Posted July 6, 2017 Share Posted July 6, 2017 local inventorySlots = {} local playerItems = { [12] = {itemID, itemData..., itemImage} -- an item on slot 12 } for i = 1, 15 do local itemID = -1 local img if playerItems[i] then img = guiCreateStaticImage( (i-1) * 20, 15, 18, 18, playerItems[i][3]) -- the inventory slot image setElementData(img, "itemID", i, false) -- don't need to sync with other clients else img = guiCreateStaticImage( (i-1) * 20, 15, 18, 18, defaultImageLocation) setElementData(img, "itemID", itemID, false) end table.insert(inventorySlots, img) end addEventHandler("onClientGUIClick", root, function() if source and getElementData(source, "itemID") then outputChatBox("you clicked an item...") else outputChatBox("you clicked an empty slot...") end end) Not tested at all, should give you a rough idea, although I would use dx functions, but that's a bit harder to do.. 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