Josh64

Modded trinket support (example mod 2)

Jan 10th, 2021 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 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
  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. if onPickup == true then -- check if the player holds trinkets since their costumes need to be removed
  18. for m = 0, (game:GetNumPlayers() - 1) do
  19. local player = Isaac.GetPlayer(m)
  20. local playerData = player:GetData()
  21. if ctc:GetHeldTrinkets (player, TrinketType.TRINKET_YOUR_TRINKET) then -- check if the player holds the trinket in one of the..
  22. -- trinket slots (returns true or false)
  23. player:TryRemoveNullCostume(Mod.COSTUME_OF_YOUR_TRINKET) -- remove costume
  24. moddedCos.YourTrinket = false
  25. end
  26. end
  27. end
  28. end
  29. end
  30. end
  31. Mod:AddCallback(ModCallbacks.MC_EXECUTE_CMD, Mod.setTrinketCostume)
  32.  
  33. function Mod:onNewRun(bool)
  34. -- reset at the begin of a new run
  35. if bool == false -- is false on the start of a complete new game
  36. and trinketCostumesMod then
  37. moddedCos.YourTrinket = false
  38. end
  39. end
  40. Mod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, Mod.onNewRun)
  41.  
  42. function Mod:onModdedCostumeUpdate(_)
  43.  
  44. -- check if trinket costume mod is active
  45. if trinketCostumesMod then
  46. for i = 0, (game:GetNumPlayers() - 1) do
  47. local player = Isaac.GetPlayer(i)
  48.  
  49. if player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET) -- still have to check if the player has the trinket
  50. and moddedCos.YourTrinket == false then
  51. -- add the costume
  52. if onPickup == false then -- global variable which decides when the costume gets applied
  53. if ctc:TrinketIsSmelted(player, TrinketType.TRINKET_YOUR_TRINKET) then -- specific function which checks if the to evaluated trinket is smelted
  54. -- returns 'true' or 'false'
  55. -- costume would get applied by smelting the trinket
  56. player:AddNullCostume(Mod.COSTUME_OF_YOUR_TRINKET)
  57.  
  58. -- set moddedCos. to true
  59. moddedCos.YourTrinket = true
  60. end
  61. else
  62. if player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET) then
  63. -- costume would get applied by picking up the trinket
  64. player:AddNullCostume(Mod.COSTUME_OF_YOUR_TRINKET)
  65.  
  66. -- set moddedCos. to true
  67. moddedCos.YourTrinket = true
  68. end
  69. end
  70. end
  71. if (not player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET))
  72. and moddedCos.YourTrinket == true then -- check if the costume needs to be removed
  73. -- remove the costume
  74. ctc:RemoveTrinketCostume(player, TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_OF_YOUR_TRINKET)
  75. moddedCos.YourTrinket = false
  76. end
  77. end
  78. end
  79. end
  80. Mod:AddCallback(ModCallbacks.MC_POST_UPDATE, Mod.onModdedCostumeUpdate)
Add Comment
Please, Sign In to add comment