Advertisement
KBM-Quine

anotherPowerDownLibrary.lua

Sep 2nd, 2021
1,878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.73 KB | None | 0 0
  1. -------------------------------------------------------
  2. --[[anotherPowerDownLibrary.lua v1.1.2 by KBM-Quine]]--
  3. --[[              with code help from:             ]]--
  4. --[[         rixithechao, Enjl, and Hoeloe         ]]--
  5. -------------------------------------------------------
  6. local anotherPowerDownLibrary = {}
  7. local pm = require("playermanager")
  8. local bowser
  9. if not isOverworld then
  10.     bowser = require("characters/bowser")
  11. end
  12.  
  13. anotherPowerDownLibrary.enabled = true
  14. anotherPowerDownLibrary.customForcedState = 751
  15. anotherPowerDownLibrary.powerDownSFX = 5
  16.  
  17. local usableCharacters = { --most characters either don't work with it or have unique enough gameplay that warrants exclusion
  18.     [CHARACTER_MARIO] = true,
  19.     [CHARACTER_LUIGI] = true,
  20.     [CHARACTER_PEACH] = false,
  21.     [CHARACTER_TOAD] = false,
  22.     [CHARACTER_LINK] = false,
  23.     [CHARACTER_MEGAMAN] = false,
  24.     [CHARACTER_WARIO] = true,
  25.     [CHARACTER_BOWSER] = false, --bowser is coded to work, but will be disabled by default
  26.     [CHARACTER_KLONOA] = false,
  27.     [CHARACTER_NINJABOMBERMAN] = false,
  28.     [CHARACTER_ROSALINA] = false,
  29.     [CHARACTER_SNAKE] = false,
  30.     [CHARACTER_ZELDA] = true,
  31.     [CHARACTER_ULTIMATERINKA] = false,
  32.     [CHARACTER_UNCLEBROADSWORD] = true,
  33.     [CHARACTER_SAMUS] = false
  34. }
  35.  
  36. function anotherPowerDownLibrary.setCharacterActive(charID, bool)
  37.     usableCharacters[charID] = bool
  38. end
  39.  
  40. function anotherPowerDownLibrary.onInitAPI()
  41.     registerEvent(anotherPowerDownLibrary, "onTick", "onTick", true)
  42.     registerEvent(anotherPowerDownLibrary, "onPlayerHarm", "onPlayerHarm", true)
  43. end
  44.  
  45. function anotherPowerDownLibrary.onPlayerHarm(event, p)
  46.     if usableCharacters[p.character] and anotherPowerDownLibrary.enabled then
  47.         if p.character == CHARACTER_UNCLEBROADSWORD or p.character == CHARACTER_BOWSER then
  48.             event.cancelled = false
  49.         elseif p.powerup > 2 and p.mount == MOUNT_NONE and not p:mem(0x0C, FIELD_BOOL) and p:mem(0x16, FIELD_WORD) < 3 and not p.hasStarman then
  50.             event.cancelled = true
  51.             SFX.play(anotherPowerDownLibrary.powerDownSFX)
  52.             p.forcedState = anotherPowerDownLibrary.customForcedState
  53.         end
  54.     end
  55. end
  56.  
  57. local playerData = {}
  58.  
  59. function anotherPowerDownLibrary.onTick()
  60.     if not isOverworld and anotherPowerDownLibrary.enabled then
  61.         for _, p in ipairs(Player.get()) do
  62.             local ps = PlayerSettings.get(pm.getCharacters()[p.character].base, p.powerup)
  63.             playerData[p] = playerData[p] or {}
  64.             playerData[p].curState = playerData[p].curState or 0
  65.  
  66.             if p.BlinkTimer == 120 and p.character == CHARACTER_UNCLEBROADSWORD and playerData[p].curState ~= PLAYER_BIG then --allows uncle broadsword to use this libaray without overwriting his unique mechanics
  67.                 p.powerup = PLAYER_BIG
  68.             end
  69.             if p.BlinkTimer > 0 and p.character == CHARACTER_BOWSER then --allows bowser to use this libaray without overwriting his unique mechanics
  70.                 if playerData[p].curState > PLAYER_BIG then
  71.                     if bowser ~= nil then
  72.                         bowser.setHP(2)
  73.                     end
  74.                 end
  75.                 return
  76.             end
  77.            
  78.             if p.forcedTimer == 0 then --if a forcedState timer isn't active, track player powerup
  79.                 playerData[p].curState = p.powerup
  80.             end
  81.             if p.forcedState == anotherPowerDownLibrary.customForcedState then --taken from modPlayer.bas, line 7477
  82.                 if p:mem(0x12E, FIELD_BOOL) then --ducking state, seemingly wouldn't work if using player.InDuckingPosition?
  83.                     p:mem(0x132, FIELD_BOOL, true) --standing value?? seems to corrilates to .stand in modPlayer.bas, is player.Unknown132
  84.                     p:mem(0x12E, FIELD_BOOL, false)
  85.                     p.height = ps.hitboxHeight
  86.                     p.y = p.y - ps.hitboxHeight + ps.hitboxDuckHeight
  87.                 end
  88.                 p.forcedTimer = p.forcedTimer + 1
  89.                 p.CurrentPlayerSprite = 1
  90.                 if p.forcedTimer % 5 == 0 then
  91.                     if p.powerup == PLAYER_BIG then
  92.                         p.powerup = playerData[p].curState
  93.                     else
  94.                         p.powerup = PLAYER_BIG
  95.                     end
  96.                 end
  97.                 if p.forcedTimer >= 50 then
  98.                     if p.powerup == playerData[p].curState then
  99.                         p.powerup = PLAYER_BIG
  100.                     end
  101.                     p.BlinkTimer = 150
  102.                     p.BlinkState = true
  103.                     p.forcedState = 0
  104.                     p.forcedTimer = 0
  105.                 end
  106.             end
  107.         end
  108.     end
  109. end
  110.  
  111. return anotherPowerDownLibrary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement