Josh64

Untitled

Dec 2nd, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. r/themoddingofisaac
  2. Error when having multiple familiars orbiting around the player
  3. u/quotee
  4. This code works fine, but when I look in the log I get this error:
  5.  
  6. mirrorshield.lua:41: bad argument #1 to 'AddToOrbit' (EntityFamiliar expected, got number)
  7. The problem starts to occur when I have more than one mirror shield at a time. Every one of them stacks on top of one another.
  8.  
  9. local mod = RegisterMod("Mirror Shield", 1)
  10. local COLLECTIBLE_MIRROR_SHIELD = Isaac.GetItemIdByName("Mirror Shield")
  11. local debug = true
  12.  
  13. local itemProperties = {
  14. VARIANT = Isaac.GetEntityVariantByName("Mirror Shield"),
  15. ORBIT_DISTANCE = Vector (65, 65), -- Distance orbital is from the player
  16. ORBIT_SPEED = 0.02, -- 0 < orbitSpeed < .1
  17. ORBIT_LAYER = 200
  18. }
  19.  
  20. function mod:onRunInitialization()
  21. if Game():GetFrameCount() == 0 then
  22. if debug then
  23. Isaac.ExecuteCommand("spawn 5.100."..COLLECTIBLE_MIRROR_SHIELD)
  24. end
  25. end
  26. end
  27.  
  28. mod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, mod.onRunInitialization)
  29.  
  30. function mod:init(shield)
  31. shield:AddToOrbit(itemProperties.ORBIT_LAYER)
  32. end
  33.  
  34. mod:AddCallback(ModCallbacks.MC_FAMILIAR_INIT, mod.init, itemProperties.VARIANT)
  35.  
  36. function mod:onUpdate(shield)
  37. local player = Isaac.GetPlayer(0)
  38. shield.OrbitDistance = itemProperties.ORBIT_DISTANCE
  39. shield.OrbitSpeed = itemProperties.ORBIT_SPEED
  40. shield.Velocity = shield:GetOrbitPosition(player.Position + player.Velocity) - shield.Position
  41. end
  42.  
  43. mod:AddCallback(ModCallbacks.MC_FAMILIAR_UPDATE, mod.onUpdate, itemProperties.VARIANT)
  44.  
  45. function mod:updateCache(player, cacheFlag)
  46. if cacheFlag == CacheFlag.CACHE_FAMILIARS then
  47. local shield_pickups = player:GetCollectibleNum(COLLECTIBLE_MIRROR_SHIELD)
  48. local shield_rng = player:GetCollectibleRNG(COLLECTIBLE_MIRROR_SHIELD)
  49. player:CheckFamiliar(itemProperties.VARIANT, shield_pickups, shield_rng)
  50. end
  51. end
  52.  
  53. mod:AddCallback(ModCallbacks.MC_EVALUATE_CACHE, mod.updateCache)
  54. ShareComment2
  55.  
  56. Best
  57. Write a comment
  58. Share this Link
  59. Preparing your link
  60. SHARE LINK
Advertisement
Add Comment
Please, Sign In to add comment