Author Topic: A chest created when all the enemies are killed  (Read 1211 times)

Minefran12

  • Newbie
  • *
  • Posts: 12
    • View Profile
A chest created when all the enemies are killed
« on: October 10, 2017, 06:42:38 pm »
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. :)

Starlock

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: A chest created when all the enemies are killed
« Reply #1 on: October 10, 2017, 08:24:56 pm »
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

Minefran12

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: A chest created when all the enemies are killed
« Reply #2 on: October 10, 2017, 09:20:45 pm »
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.