Guest User

End Error

a guest
May 31st, 2018
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. --Where
  2. spawnLocation = {0,5,0}
  3.  
  4. --Button Stuff
  5. buttonParam = {
  6.     label = 'Trade', click_function = 'spawnItem', function_owner = self,
  7.     position = {0,0.1,-0.5}, rotation = {0,0,0}, height=400, width=900, font_size=350
  8. }
  9.  
  10. --Tables, Misc
  11. function onload()
  12.     self.createButton(buttonParam)
  13.     itemList = {"$1 Septillion"}
  14.     itemsNeeded = 1
  15.     spawnMax = 1
  16.     getItem = getObjectFromGUID("a7ec54")
  17.     itemSpawnX = 0
  18.     itemSpawnY = 1
  19.     itemSpawnZ = 0
  20. end
  21.  
  22. --Runs when button clicked
  23. --Spawns Items
  24. function spawnItem()
  25.     if container.getQuantity() > 0 then
  26.         badItems = {}
  27.         totalItems, badItems = countContainerContents(container.getObjects())
  28.         if #badItems == 0 then
  29.             if (totalItems >= itemsNeeded) then
  30.                 local spawnAmount = (totalItems / itemsNeeded)
  31.                 if spawnAmount <= spawnMax then
  32.                     self.reset()
  33.                 for i = 1,spawnAmount,1 do
  34.                     spawnItem(self, getItem, i+2)
  35.                 end
  36.             else
  37.                 broadcastToColor("Nope!")
  38.             end
  39.         else
  40.             broadcastToColor("Error: Wrong Item!")
  41.         end
  42.     else
  43.         broadcastToColor("Never!")
  44.     end
  45. end
  46.  
  47. --Where
  48. function spawnItem(targetZone, item, heightOffset)
  49.     local params = {}
  50.     params.position = targetZone.getPosition()
  51.     params.position.x = itemSpawnX
  52.     params.position.y = itemSpawnY + (heightOffset or 0)
  53.     params.position.z = itemSpawnZ
  54.     takenObject = item.takeObject(params)
  55. end
  56.  
  57. --Checks
  58. function countContainerContents(objectList)
  59.     local totalItems = 0
  60.     local badItemList = {}
  61.     for objIndex,obj in ipairs(objectList) do
  62.         nameFound = false
  63.         if string.match(obj.name, "$1 Septillion") then
  64.             for nameIndex,name in ipairs(itemList) do
  65.                 if obj.name == name then
  66.                     totalItems = totalItems + 1
  67.                     nameFound = true
  68.                     break
  69.                 end
  70.             end
  71.         end
  72.         if nameFound == false then
  73.             table.insert(badItemList, obj.name)
  74.         end
  75.     end
  76.     return totalItems, badItemList
  77. end
Advertisement
Add Comment
Please, Sign In to add comment