Josh64

multiple costumes support

Jan 16th, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. local Mod = RegisterMod("yourMod", 1)
  2. local game = Game()
  3.  
  4. TrinketType.TRINKET_YOUR_TRINKET = Isaac.GetTrinketIdByName("Your Trinket") -- trinket
  5. Mod.COSTUME_ONE = Isaac.GetCostumeIdByPath("gfx/characters/YourCostume.anm2")
  6. Mod.COSTUME_TWO = Isaac.GetCostumeIdByPath("gfx/characters/YourCostumeTwo.anm2")
  7. Mod.COSTUME_THREE = Isaac.GetCostumeIdByPath("gfx/characters/YourCostumeThree.anm2")
  8. Mod.COSTUME_FOUR = Isaac.GetCostumeIdByPath("gfx/characters/YourCostumeFour.anm2")
  9. Mod.COSTUME_FIVE = Isaac.GetCostumeIdByPath("gfx/characters/yourCostumeFive.anm2")
  10.  
  11. -- on post peffect update
  12. function Mod:onModUpdate(player)
  13.  
  14. if game:GetFrameCount() == 1
  15. and ctc then
  16. ctc:RegisterTrinketCostume(TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_ONE, "true")
  17. ctc:AddMoreCostumes(TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_TWO, Mod.COSTUME_THREE, Mod.COSTUME_FOUR, Mod.COSTUME_FIVE)
  18. -- ctc:AddMoreCostumes(TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_TWO, Mod.COSTUME_THREE, _, _)
  19. end
  20. end
  21. end
  22. Mod:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, Mod.onModUpdate)
  23.  
  24.  
  25.  
  26. -- for the sake of this example mod, let's say we make a trinket, which changes the player's appearance depending on the amount of time the player got hit
  27. -- Max is 4 times per floor. At the start of a new floor the 'hit'-counter ans the player's appearance gets reset.
  28. -- every condition has one costume asssigned to it
  29. -- Our list of conditiond looks like this
  30. -- Condition 1 = No damage taken | costume 1
  31. -- Condition 2 = 1 damage taken | costume 2
  32. -- Condition 3 = 2 damage taken | costume 3
  33. -- Condition 4 = 3 damage taken | costume 4
  34. -- Condition 5 = 4 damage taken | costume 5
  35.  
  36.  
  37. function Mod:conditionExample(entity, amt, flag, source, countdown)
  38. if ctc then -- check if the Trinket Costume mod is active
  39. for i = 0, (game:GetNumPlayers() - 1) do
  40. local player = Isaac.GetPlayer(i)
  41. local playerData = player:GetData()
  42.  
  43. if player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET) then
  44.  
  45. if playerData.GotHit == nil then -- init playerData
  46. playerData.GotHit = 0
  47. -- during the first init of the mod the first condition is automatically set to 'true'
  48. -- no condition change during the init needed
  49. end
  50.  
  51. if playerData.GotHit == 0 then -- player never got hit before
  52. playerData.GotHit = 1 -- now he got hit once
  53. -- change the condition
  54. -- required function ctc:UpdateConditions(player, trinketId, conditionNum)
  55. -- will set the other conditions to 'false' and remove the current costume
  56. -- trinketId = TrinketType.TRINKET_YOUR_TRINKET
  57. -- conditionNum is the number of the your condition which is now fullfilled
  58.  
  59. ctc:UpdateConditions(player, TrinketType.TRINKET_YOUR_TRINKET, 2)
  60.  
  61. elseif playerData.GotHit == 1 then -- player got hit once before
  62. playerData.GotHit = 2 -
  63. ctc:UpdateConditions(player, TrinketType.TRINKET_YOUR_TRINKET, 3)
  64.  
  65. elseif playerData.GotHit == 2 then -- player got hit once before
  66. playerData.GotHit = 3
  67. ctc:UpdateConditions(player, TrinketType.TRINKET_YOUR_TRIKET, 4)
  68.  
  69. elseif playerData.GotHit == 3 then -- player got hit once before
  70. playerData.GotHit = 4
  71. ctc:UpdateConditions(player, TrinketType.TRINKET_YOUR_TRINKET, 5)
  72. end
  73. end
  74. end
  75. end
  76. end
  77. Mod:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, Mod.conditionExample, EntityType.ENTITY_PLAYER)
  78.  
  79. -- So now to the part where we check if the player entered a new level/floor
  80. function Mod:conditionExamplePartTwo(_)
  81. if ctc then -- check if the Trinket Costume mod is active
  82. -- now we need to check for the player, since he isn't given by the Callback itself
  83. for i = 0, (game:GetNumPlayers() - 1) do
  84. local player = Isaac.GetPlayer(i)
  85. local playerData = player:GetData()
  86.  
  87. -- check if the player has your trinket
  88. if player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET) then
  89.  
  90. if playerData.GotHit > 0 then -- the player got hit on the previous floor, so has another costume
  91. playerData.GotHit = 0 -- reset the 'hit'- counter
  92. -- change the condition
  93.  
  94. ctc:UpdateConditions(player, TrinketType.TRINKET_YOUR_TRINKET, 1) -- never gotten hit was the first conditions
  95. end
  96. end
  97. end
  98. end
  99. end
  100. Mod:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, Mod.conditionExamplePartTwo)
Advertisement
Add Comment
Please, Sign In to add comment