Josh64

Modded trinket support (example mod)

Jan 10th, 2021 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. local Mod = RegisterMod("yourModName", 1)
  2. local game = Game()
  3.  
  4. local moddedCos = { -- keeps track which trinket is in the player posession
  5. YourTrinket = false -- ex. BloodyCobweb = false
  6. }
  7.  
  8. -- trinkets
  9. TrinketType.TRINKET_YOUR_TRINKET = Isaac.GetTrinketIdByName("Your Trinket")
  10. -- costumes
  11. Mod.COSTUME_OF_YOUR_TRINKET = Isaac.GetCostumeIdByPath("gfx/characters/yourtrinketscostume.anm2")
  12.  
  13. -- change if the costume gets applied on pickup or by smelting
  14. function Mod:setTrinketCostume(consol,para)
  15. if consol == "onPickup" then -- global. regulates when a trinket costume is applied
  16. if moddedCos.YourTrinket == true then
  17. ctc:SwitchCostumeRequirement(TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_OF_YOUR_TRINKET) -- gets called if the costume gets applied by picking up the trinket. Also removes the costume until it's applied again.
  18.  
  19. if switchTrinketBoolean == true then -- got set to 'true' in the function above
  20. moddedCos.YourTrinket = false -- reset moddedCos so that the costume can be reevaluated/applied again
  21. switchTrinketBoolean = false -- reset switchTrinketBoolean for a later use
  22. end
  23. end
  24. end
  25. end
  26. Mod:AddCallback(ModCallbacks.MC_EXECUTE_CMD, Mod.setTrinketCostume)
  27.  
  28. function Mod:onNewRun(bool)
  29. -- reset all moddedCos. variables to false at the begin of a new run
  30.  
  31. if bool == false -- is false on the start of a complete new game
  32. and trinketCostumesMod then
  33. moddedCos.YourTrinket = false
  34. end
  35. end
  36. Mod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, Mod.onNewRun)
  37.  
  38. function Mod:onModdedCostumeUpdate(_)
  39.  
  40. -- check if trinket costume mod is active
  41. if trinketCostumesMod then
  42. for i = 0, (game:GetNumPlayers() - 1) do
  43. local player = Isaac.GetPlayer(i)
  44.  
  45. if player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET) -- still have to check if the player has the trinket
  46. and moddedCos.YourTrinket == false then
  47. -- add the costume
  48. ctc:AddTrinketCostume(player, TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_OF_YOUR_TRINKET) -- applies the costumes. On smelting or pickup dependin on 'onPickup'
  49. -- change the moddedCos. boolean
  50. if switchTrinketBoolean == true then -- got set to 'true' in the function above
  51. moddedCos.YourTrinket = true -- the player now has the costume
  52. switchTrinketBoolean = false -- reset switchTrinketBoolean for a later use
  53. end
  54. end
  55. if (not player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET))
  56. and moddedCos.YourTrinket == true then -- check if the costume needs to be removed
  57. -- remove the costume
  58. ctc:RemoveTrinketCostume(player, TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_OF_YOUR_TRINKET)
  59. moddedCos.YourTrinket = false -- needs to be reset so that the costume could be...
  60. -- applied again in the same run
  61. end
  62. end
  63. end
  64. end
  65. Mod:AddCallback(ModCallbacks.MC_POST_UPDATE, Mod.onModdedCostumeUpdate)
Advertisement
Add Comment
Please, Sign In to add comment