A chest created when all the enemies are killed

Started by Minefran12, October 10, 2017, 06:42:38 PM

Previous topic - Next topic
I'm having a problem becaose i want to do to what the title says but i'm don't know how to do it exactly, Christopho say to me that i have to use the map:has_entities(prefix) and the enemy:on_dead(), and i start to do it following the docs and solving the errors that i saw in the console but in one point, i don' see any errors but it still dont work.

Please, could somebody tell me how i must do it, thanks.



PD: Sorry if I make mistakes of spealing or something else, i dont have a very high level of English. :)

Hey, could you post your current code?

You might have to make the declaration in the map:on_started() function It would be something like this

Code ( lua) Select
  if game:get_value("chestsavevalue") then yourchestname:set_enabled(true) else yourchestname:set_enabled(false) end

The functions you are talking about should look something like this:

Code ( lua) Select
for enemy in map:get_entities("yourenemy") do
  enemy.on_dead = function()
    if not map:has_entities("yourenemy") then
      yourchestname:set_enabled(true)
      sol.audio.play_sound("chest_appears")
    end
  end
end

Thak you a lot, the problem was i havent declared game:get_value and i have only enemy.on_dead() insted of enemy.on_dead = function(). Tahnks again.