AFRLme

Cycle inventory items [vs]

Feb 10th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. --[[
  2. Cycle inventory items by ascending or descending order (v1) [11/02/2014]
  3. Written by AFRLme
  4. -- + --
  5. [email protected] | skype @ AFRLme
  6. --]]
  7.  
  8. -- * local variables * --
  9. local char, items, item, amt -- empty variables
  10.  
  11. -- * function for cycling through the inventory items * --
  12. function cycleItems(asc)
  13.  char = game:getLink(VGameCurrentCharacter) -- store current character
  14.  items = char:getLinks(VCharacterItems) -- store inventory items into a table
  15.  amt = table.maxn(items) -- get index number of last item
  16.  -- if asc is true (ascending) then item = last item, remove last item from table & insert into slot 1 else (descending) item = first item, remove first item & insert into last slot
  17.  if asc then item = items[amt]; table.remove(items, amt); table.insert(items, 1, item) else item = items[1]; table.remove(items, 1); table.insert(items, (table.maxn(items)+1), item) end
  18.  char:setValue(VCharacterItems, items) -- update the inventory
  19. end
Advertisement
Add Comment
Please, Sign In to add comment