[Custom items] Freezing enemies (immobilize) ?

Started by MetalZelda, December 09, 2015, 01:51:31 PM

Previous topic - Next topic
Hi.

So I was working on some items today (ice rod, deku nuts) and I was wondering how can I make the custom item to immobilize enemies, I tried "set_attack_reaction = "immobilize" but it seems that it doesn't do anything. "set_attack_reaction = "immobilized" hurt the enemies even if the desired reaction is "immobilize". Enemies sprite does have "immobilized" animation.

Code (lua) Select
-- Initialize the metatable of appropriate entities to work with the ice.
local function initialize_meta()

  -- Add Lua ice beam properties to enemies.
  local enemy_meta = sol.main.get_metatable("enemy")
  if enemy_meta.get_ice_reaction ~= nil then
    -- Already done.
    return
  end

  enemy_meta.ice_reaction = "immobilize"
  enemy_meta.ice_reaction_sprite = {}
  function enemy_meta:get_ice_reaction(sprite)

    if sprite ~= nil and self.ice_reaction_sprite[sprite] ~= nil then
      return self.ice_reaction_sprite[sprite]
    end
    return self.ice_reaction
  end

  function enemy_meta:set_ice_reaction(reaction, sprite)

    self.ice_reaction = reaction
  end

  function enemy_meta:set_ice_reaction_sprite(sprite, reaction)

    self.ice_reaction_sprite[sprite] = reaction
  end

  -- Change the default enemy:set_invincible() to also
  -- take into account the ice.
  local previous_set_invincible = enemy_meta.set_invincible
  function enemy_meta:set_invincible()
    previous_set_invincible(self)
    self:set_ice_reaction("ignored")
  end
  local previous_set_invincible_sprite = enemy_meta.set_invincible_sprite
  function enemy_meta:set_invincible_sprite(sprite)
    previous_set_invincible_sprite(self, sprite)
    self:set_ice_reaction_sprite(sprite, "ignored")
  end

end
initialize_meta()


Also question : Does it need extensive code to allow enemies to have a "freeze" attack reaction ?

Any help would be great
Thanks

Code (lua) Select
enemy_meta.ice_reaction = "immobilize"
Don't you mean
Code (lua) Select
enemy_meta.ice_reaction = "immobilized"
?

It should be possible to make a custom "freezed" state of enemies, by making a function enemy_meta:freeze() that stops their movement, animation and timers. Maybe it can be useful if the built-in "immobilized" state in not exactly what you want.

Quote from: Christopho on December 09, 2015, 02:08:57 PM
Code (lua) Select
enemy_meta.ice_reaction = "immobilize"
Don't you mean
Code (lua) Select
enemy_meta.ice_reaction = "immobilized"
?

It should be possible to make a custom "freezed" state of enemies, by making a function enemy_meta:freeze() that stops their movement, animation and timers. Maybe it can be useful if the built-in "immobilized" state in not exactly what you want.

For the first thing it works, thanks.
For the second, the "freeze" state would be mostly the same as immobilize, the only thing that iterate is the animation depending on the item and collision, I'm gonna try your work-around.
Tkanks

Easier way: if it is just to change the animation, you can do that from enemy:on_immobilized().