Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Where
- spawnLocation = {0,5,0}
- --Button Stuff
- buttonParam = {
- label = 'Trade', click_function = 'spawnItem', function_owner = self,
- position = {0,0.1,-0.5}, rotation = {0,0,0}, height=400, width=900, font_size=350
- }
- --Tables, Misc
- function onload()
- self.createButton(buttonParam)
- itemList = {"$1 Septillion"}
- itemsNeeded = 1
- spawnMax = 1
- getItem = getObjectFromGUID("a7ec54")
- itemSpawnX = 0
- itemSpawnY = 1
- itemSpawnZ = 0
- end
- --Runs when button clicked
- --Spawns Items
- function spawnItem()
- if container.getQuantity() > 0 then
- badItems = {}
- totalItems, badItems = countContainerContents(container.getObjects())
- if #badItems == 0 then
- if (totalItems >= itemsNeeded) then
- local spawnAmount = (totalItems / itemsNeeded)
- if spawnAmount <= spawnMax then
- self.reset()
- for i = 1,spawnAmount,1 do
- spawnItem(self, getItem, i+2)
- end
- else
- broadcastToColor("Nope!")
- end
- else
- broadcastToColor("Error: Wrong Item!")
- end
- else
- broadcastToColor("Never!")
- end
- end
- --Where
- function spawnItem(targetZone, item, heightOffset)
- local params = {}
- params.position = targetZone.getPosition()
- params.position.x = itemSpawnX
- params.position.y = itemSpawnY + (heightOffset or 0)
- params.position.z = itemSpawnZ
- takenObject = item.takeObject(params)
- end
- --Checks
- function countContainerContents(objectList)
- local totalItems = 0
- local badItemList = {}
- for objIndex,obj in ipairs(objectList) do
- nameFound = false
- if string.match(obj.name, "$1 Septillion") then
- for nameIndex,name in ipairs(itemList) do
- if obj.name == name then
- totalItems = totalItems + 1
- nameFound = true
- break
- end
- end
- end
- if nameFound == false then
- table.insert(badItemList, obj.name)
- end
- end
- return totalItems, badItemList
- end
Advertisement
Add Comment
Please, Sign In to add comment