Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Mira's Powerup Converter ]]--
- function onload()
- self.createButton({
- label="Trade\nIn", click_function="powerupTradeIn", function_owner=self,
- position={0,4.96,0}, height=450, width=550, font_size=180
- })
- --[[ Begin Config ]]--
- powerupsNeeded = 2 --powerups needed per random powerup
- rupeesNeeded = 5 --rupees needed per random powerup
- spawnMax = 50 --max amount of random powerups you're allowed to convert at a time
- bagLimit = 5 --max amount of random powerups to spawn before using a powerup bag
- itemSpawnX = 25.5 --random powerup and bag spawn x, y, z locations
- itemSpawnY = 3 --make sure the Y axis is free between itemSpawnY and (itemSpawnY + spawnMax + 2) as there is a height offset of +1 for every powerup spawned and +2 for the bag
- itemSpawnZ = -14
- randomPowerup = getObjectFromGUID("737b2a")
- randomPowerupBag = getObjectFromGUID("903a88")
- powerupList = {"Copy a random player's hand", "Shuffle all player's cards", "Martyr", "Turn a random card into Ace", "New bonus round", "Minigame", "Spite", "Refresh", "Random Subtract", "Bust another player", "Swap hands with a random player", "Shuffle hands with another player", "Redraw all cards", "Sacrifice", "Nothing", "Give another player Blackjack", "Discard the last drawn card", "Activate Bonus Round Timer", "Save all other players", "Backstab another player", "Force a player to draw an additional card", "Steal a random card from another player", "Remove a random card from a player's hand", "Force a player to redraw their hand", "View the next card", "Exit from the round", "Help another player exit from the round", "Discard your hand and stand on 17", "Discard your hand and stand on 19", "Discard your hand and stand on 21", "+10 to your own hand", "+1 to anyone's hand", "+2 to anyone's hand", "+3 to anyone's hand", "+4 to anyone's hand", "+5 to anyone's hand", "+6 to anyone's hand", "+7 to anyone's hand", "+8 to anyone's hand", "+9 to anyone's hand", "+10 to anyone's hand", "-1 from anyone's hand", "-2 from anyone's hand", "-3 from anyone's hand", "-4 from anyone's hand", "-5 from anyone's hand", "-6 from anyone's hand", "-7 from anyone's hand", "-8 from anyone's hand", "-9 from anyone's hand", "- from anyone's hand", "Copy another player's hand", "Swap hands with another player", "Swap hands with the dealer", "Force the dealer to draw an additional card", "Force the dealer to stand on two cards", "Force the dealer to reveal their facedown card", "Force the dealer to bust", "Random Cheat Token", "Mugging", "Give a card", "Bump", "Swap All", "Swap Powerups", "Chaos"}
- rupeeList = {"[AD51C2]Purple rupee[-] [Trophy]", "[F06800]Orange rupee[-] [Trophy]", "[E81931]Red rupee[-] [Trophy]", "[EEFF00]Yellow rupee[-] [Trophy]", "[1965E8]Blue rupee[-] [Trophy]", "[1CE055]Green rupee[-] [Trophy]", "[514464]Rupoor[-] [Trophy]", "[BEBEBE]Silver rupee[-] [Trophy]", "[DEB444]Gold rupee[-] [Trophy]" }
- self.setDescription("Converts any "..tostring(powerupsNeeded).." powerups or any "..tostring(rupeesNeeded).." rupees into random powerup draws.\nUp to "..tostring(spawnMax).." at a time!")
- --[[ End Config ]]--
- lockout = false
- end
- --Button function
- --Determines how many random powerups are rewarded spawns them, or displays the appropriate error messages for too many/few or bad items
- function powerupTradeIn(container, color)
- if not lockout then
- lockoutTimer(1)
- if container.getQuantity() > 0 then
- badItems = {}
- totalPowerups, totalRupees, badItems = countContainerContents(container.getObjects())
- if #badItems == 0 then
- local powerupOverflow = totalPowerups % powerupsNeeded
- local rupeeOverflow = totalRupees % rupeesNeeded
- if (totalPowerups >= powerupsNeeded or totalPowerups == 0) and (totalRupees >= rupeesNeeded or totalRupees == 0) and powerupOverflow == 0 and rupeeOverflow == 0 then
- local spawnAmount = (totalPowerups / powerupsNeeded) + (totalRupees / rupeesNeeded)
- if spawnAmount <= spawnMax then
- self.reset()
- if spawnAmount > bagLimit then
- spawnItem(self, randomPowerupBag)
- spawnAmount = spawnAmount - 1
- end
- for i = 1,spawnAmount,1 do
- spawnItem(self, randomPowerup, i+2)
- end
- else
- broadcastToColor("Error: Max powerup conversions is "..tostring(spawnMax)..".\nYou're trying to spawn "..tostring(spawnAmount-spawnMax).." too many.", color, {1,0.25,0.25})
- end
- else
- if powerupOverflow ~= 0 and totalPowerups > powerupsNeeded then broadcastToColor("Error: You have "..tostring(powerupOverflow).." too many powerups or need "..tostring(powerupsNeeded - powerupOverflow).." more.", color, {1,0.25,0.25}) end
- if rupeeOverflow ~= 0 and totalRupees > rupeesNeeded then broadcastToColor("Error: You have "..tostring(rupeeOverflow).." too many rupees or need "..tostring(rupeesNeeded - rupeeOverflow).." more.", color, {1,0.25,0.25}) end
- if totalPowerups < powerupsNeeded and totalPowerups ~= 0 then broadcastToColor("Error: You need "..tostring(powerupsNeeded - totalPowerups).." more powerups.", color, {1,0.25,0.25}) end
- if totalRupees < rupeesNeeded and totalRupees ~= 0 then broadcastToColor("Error: You need "..tostring(rupeesNeeded - totalRupees).." more rupees.", color, {1,0.25,0.25}) end
- end
- else
- broadcastToColor("Error: "..tostring(table.concat(badItems, ", ")).." is/are not in the powerup or rupee lists.", color, {1,0.25,0.25})
- end
- else
- broadcastToColor("Error: Random Powerup and Rupee Converter is empty.", color, {1,0.25,0.25})
- end
- else
- broadcastToColor("Error: Button delay is active.\nWait a moment then try again.", color, {1,0.25,0.25})
- end
- end
- --spawns items in the configured position with any needed offset to prevent clipping
- 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
- --Returns how many acceptable powerups and rupees are in objectList and an array of any bad items found
- function countContainerContents(objectList)
- --Returned values
- local powerupCount = 0
- local rupeeCount = 0
- local badItemList = {}
- --Iterate through the container's inventory
- for objIndex,obj in ipairs(objectList) do
- nameFound = false
- --Iterate through and test for matches in either powerupList or rupeeList
- if string.match(obj.name, "Trophy") then
- for nameIndex,name in ipairs(rupeeList) do
- if obj.name == name then
- rupeeCount = rupeeCount + 1
- nameFound = true
- break
- end
- end
- else
- for nameIndex,name in ipairs(powerupList) do
- if obj.name == name then
- powerupCount = powerupCount + 1
- nameFound = true
- break
- end
- end
- end
- --Add any bad items found to the return table
- if nameFound == false then
- table.insert(badItemList, obj.name)
- end
- end
- return powerupCount, rupeeCount, badItemList
- end
- --locks the button to prevent any possible exploits
- function lockoutTimer(time)
- lockout = true
- Timer.destroy('lockout_timer')
- Timer.create({identifier='lockout_timer', function_name='concludeLockout', delay=time})
- end
- --unlocks the button
- function concludeLockout()
- lockout = false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement