Advertisement
MiraMiraMira

Powerup and Rupee Converter Lua

Jan 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.02 KB | None | 0 0
  1. --[[                    Mira's Powerup Converter                   ]]--
  2.  
  3. function onload()
  4.     self.createButton({
  5.         label="Trade\nIn", click_function="powerupTradeIn", function_owner=self,
  6.         position={0,4.96,0}, height=450, width=550, font_size=180
  7.     })
  8.  
  9.     --[[        Begin Config        ]]--
  10.     powerupsNeeded = 2 --powerups needed per random powerup
  11.     rupeesNeeded = 5 --rupees needed per random powerup
  12.     spawnMax = 50 --max amount of random powerups you're allowed to convert at a time
  13.     bagLimit = 5 --max amount of random powerups to spawn before using a powerup bag
  14.     itemSpawnX = 25.5 --random powerup and bag spawn x, y, z locations
  15.     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
  16.     itemSpawnZ = -14
  17.     randomPowerup = getObjectFromGUID("737b2a")
  18.     randomPowerupBag = getObjectFromGUID("903a88")
  19.     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"}
  20.     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]" }
  21.  
  22.     self.setDescription("Converts any "..tostring(powerupsNeeded).." powerups or any "..tostring(rupeesNeeded).." rupees into random powerup draws.\nUp to "..tostring(spawnMax).." at a time!")
  23.     --[[        End Config        ]]--
  24.     lockout = false
  25. end
  26.  
  27. --Button function
  28. --Determines how many random powerups are rewarded spawns them, or displays the appropriate error messages for too many/few or bad items
  29. function powerupTradeIn(container, color)
  30.     if not lockout then
  31.         lockoutTimer(1)
  32.         if container.getQuantity() > 0 then
  33.             badItems = {}
  34.             totalPowerups, totalRupees, badItems = countContainerContents(container.getObjects())
  35.             if #badItems == 0 then
  36.                 local powerupOverflow = totalPowerups % powerupsNeeded
  37.                 local rupeeOverflow = totalRupees % rupeesNeeded
  38.                 if (totalPowerups >= powerupsNeeded or totalPowerups == 0) and (totalRupees >= rupeesNeeded or totalRupees == 0) and powerupOverflow == 0 and rupeeOverflow == 0 then
  39.                     local spawnAmount = (totalPowerups / powerupsNeeded) + (totalRupees / rupeesNeeded)
  40.                     if spawnAmount <= spawnMax then
  41.                         self.reset()
  42.                         if spawnAmount > bagLimit then
  43.                             spawnItem(self, randomPowerupBag)
  44.                             spawnAmount = spawnAmount - 1
  45.                         end
  46.                         for i = 1,spawnAmount,1 do
  47.                             spawnItem(self, randomPowerup, i+2)
  48.                         end
  49.                     else
  50.                         broadcastToColor("Error: Max powerup conversions is "..tostring(spawnMax)..".\nYou're trying to spawn "..tostring(spawnAmount-spawnMax).." too many.", color, {1,0.25,0.25})
  51.                     end
  52.                 else
  53.                     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
  54.                     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
  55.                     if totalPowerups < powerupsNeeded and totalPowerups ~= 0 then broadcastToColor("Error: You need "..tostring(powerupsNeeded - totalPowerups).." more powerups.", color, {1,0.25,0.25}) end
  56.                     if totalRupees < rupeesNeeded and totalRupees ~= 0 then broadcastToColor("Error: You need "..tostring(rupeesNeeded - totalRupees).." more rupees.", color, {1,0.25,0.25}) end
  57.                 end
  58.             else
  59.                 broadcastToColor("Error: "..tostring(table.concat(badItems, ", ")).." is/are not in the powerup or rupee lists.", color, {1,0.25,0.25})
  60.             end
  61.         else
  62.             broadcastToColor("Error: Random Powerup and Rupee Converter is empty.", color, {1,0.25,0.25})
  63.         end
  64.     else
  65.         broadcastToColor("Error: Button delay is active.\nWait a moment then try again.", color, {1,0.25,0.25})
  66.     end
  67. end
  68.  
  69. --spawns items in the configured position with any needed offset to prevent clipping
  70. function spawnItem(targetZone, item, heightOffset)
  71.     local params = {}
  72.     params.position = targetZone.getPosition()
  73.     params.position.x = itemSpawnX
  74.     params.position.y = itemSpawnY + (heightOffset or 0)
  75.     params.position.z = itemSpawnZ
  76.     takenObject = item.takeObject(params)
  77. end
  78.  
  79. --Returns how many acceptable powerups and rupees are in objectList and an array of any bad items found
  80. function countContainerContents(objectList)
  81.     --Returned values
  82.     local powerupCount = 0
  83.     local rupeeCount = 0
  84.     local badItemList = {}
  85.     --Iterate through the container's inventory
  86.     for objIndex,obj in ipairs(objectList) do
  87.         nameFound = false
  88.         --Iterate through and test for matches in either powerupList or rupeeList
  89.         if string.match(obj.name, "Trophy") then
  90.             for nameIndex,name in ipairs(rupeeList) do
  91.                 if obj.name == name then
  92.                     rupeeCount = rupeeCount + 1
  93.                     nameFound = true
  94.                     break
  95.                 end
  96.             end
  97.         else
  98.             for nameIndex,name in ipairs(powerupList) do
  99.                 if obj.name == name then
  100.                     powerupCount = powerupCount + 1
  101.                     nameFound = true
  102.                     break
  103.                 end
  104.             end
  105.         end
  106.         --Add any bad items found to the return table
  107.         if nameFound == false then
  108.             table.insert(badItemList, obj.name)
  109.         end
  110.     end
  111.     return powerupCount, rupeeCount, badItemList
  112. end
  113.  
  114. --locks the button to prevent any possible exploits
  115. function lockoutTimer(time)
  116.     lockout = true
  117.     Timer.destroy('lockout_timer')
  118.     Timer.create({identifier='lockout_timer', function_name='concludeLockout', delay=time})
  119. end
  120.  
  121. --unlocks the button
  122. function concludeLockout()
  123.     lockout = false
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement