Josh64

Modded trinket support (updated example mod)

Jan 12th, 2021 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. local Mod = RegisterMod("yourModName", 1)
  2. local game = Game()
  3.  
  4. -- trinkets
  5. TrinketType.TRINKET_YOUR_TRINKET = Isaac.GetTrinketIdByName("Your Trinket") -- your trinketId
  6. -- costumes
  7. Mod.COSTUME_OF_YOUR_TRINKET = Isaac.GetCostumeIdByPath("gfx/characters/yourtrinketscostume.anm2") -- your costumeId
  8.  
  9. function Mod:setModdedTrinketCostume(consol,para)
  10. if OnPickupSwitch(consol) then -- takes "onPickup" and checks if it's state is 'true'.
  11. -- If so, the it will return true. Otherwise it will return false
  12. for i = 0, (game:GetNumPlayers() - 1) do
  13. local player = Isaac.GetPlayer(i)
  14. local playerData = player:GetData()
  15. if playerData.YourTrinketName == true then
  16. if ctc:GetHeldTrinkets(player, TrinketType.TRINKET_YOUR_TRINKET) then -- check if the player holds the trinket in one of the trinket slots (returns true or false)
  17. player:TryRemoveNullCostume(Mod.COSTUME_OF_YOUR_TRINKET) -- remove costume
  18. playerData.YourTrinketName = false
  19. end
  20. end
  21. end
  22. end
  23. end
  24. Mod:AddCallback(ModCallbacks.MC_EXECUTE_CMD, Mod.setModdedTrinketCostume)
  25.  
  26. -- on post peffect update
  27. function Mod:onModUpdate(player)
  28. local playerData = player:GetData() -- if you already assigned a variable to player:GetData() that's fine. Just make sure to use it instead of playerData
  29. if game:GetFrameCount() == 1 then
  30. playerData.YourTrinketName = false -- saves and keeps track if the player has picked up YOUR trinket | ex. playerData.BloodyCobweb
  31. end
  32. if trinketCostumesMod then -- trinket costume mod is active
  33. if player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET) -- still have to check if the player has the trinket
  34. and playerData.YourTrinketName == false then
  35. -- add the costume
  36. ctc:AddTrinketCostume(player, TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_OF_YOUR_TRINKET)
  37. if hasTrinketCostume == true then -- global variable, got set to 'true' in the function above
  38. playerData.YourTrinketName = true -- the player now has the costume
  39. hasTrinketCostume = false -- reset hasTrinketCostume for a later use
  40. end
  41. end
  42. if (not player:HasTrinket(TrinketType.TRINKET_YOUR_TRINKET))
  43. and playerData.YourTrinketName == true then -- check if the costume needs to be removed
  44. -- remove the costume
  45. ctc:RemoveTrinketCostume(player, TrinketType.TRINKET_YOUR_TRINKET, Mod.COSTUME_OF_YOUR_TRINKET)
  46. playerData.YourTrinketName = false
  47. end
  48. end
  49. Mod:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, Mod.onModUpdate)
Add Comment
Please, Sign In to add comment