Animan99 Posted August 19, 2015 Share Posted August 19, 2015 hello. I am working on an invetory system, but i have a problem, i couldn't solve. if i hover a picture, or rectangle then get that value from table. Here is a way to do this(this will explain if you dont understand so read the comments) asd = { {"asd1", 1}, {"asd2", 2}, {"asd3", 3}, } addEventHandler("onClientRender", getRootElement(), function() local row = 0 local elem = 0 cx, cy = getCursorPosition() cx, cy = cx*sW, cy*sH for k, v in ipairs(asd) do dxDrawRectangle(X, Y + row, W, H, tocolor(0, 0, 0, 150)) -- + row - this will render 3 rectangle because 3 value is in table named "asd" if cx > X and cx < X + W and cy > Y + row and cy < Y + H + row then -- if cursor on any rendered rectangle hoveredText = v[1] -- this RETURNS ONE VALUE not the all values in table dxDrawText(hoveredText, X, Y + row, 0, 0, etc..) -- if my cursor on the first rectangle this will draw the first value from table (asd1) and this is what i need but i have to find another way to solve this. end row = row + 25 elem = elem + 1 end end) So what i want that the table return one value that i hover or click. I have to do with ANOTHER method, because i cannot do my inventory with this. So this is wrong: for k, v in ipairs(items) do if getKeyState("mouse1") and isInBox(cx, cy, X , Y, X2, Y2) then hoverText = v[1] -- this returns ALL values in table end end so i need a way to get table a data like above, not all data. I need this because when i am moving an item from my inventory sadly all item moves. i want that specific item to move, (items in table) so this is what i need this. Hope you understand, sorry for bad english. Link to comment
Ab-47 Posted August 19, 2015 Share Posted August 19, 2015 Try the useful "unpack" pre-defined variable. It's easier than loops and is simple to understand. Let me give you an example. local table = { [1] = {"hello world", "second string of data"}; [2] = {"I like MTA", "second row of the table, and second string"}; } local elements = {} local elements2 = {} function unpackTheData() if (table) then elements[1], elements[2] = unpack(table[1]) elements2[1], elements2[2] = unpack(table[2]) outputChatBox(elements[1].." : "..elements[2]) outputChatBox(elements2[1].." : "..elements2[2]) end end addEventHandler("onClientResourceStart", root, unpackTheData) Hope this example helps you find a new solution to your problem. Link to comment
Animan99 Posted August 19, 2015 Author Share Posted August 19, 2015 thanks, i figured out that my problem is not this, so i do not know anything anymore. i have this function to move items: function itemMoveToSlot(item, newSlot) for k, v in ipairs(Items) do if isSlotEmpty(ujSlot) then Items[k][2] = newSlot end end end this is working, when i have ONE item in the items table(this table contains all the items that the player currently have) if i have 2 or more items then the first item is not moving, just the second one, and the first one moves with the second. 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