how to make a 'code/password'

Started by ponderitus, September 21, 2019, 01:57:38 AM

Previous topic - Next topic
Hey Guys, I was wondering how to make a sort of code or password, as in enemy must be killed in a certain order to open a door/make a chest appear..so that if they are killed in the right order then x will happen but if the wrong order then everything is reset....

where would i start with this?

so that (1,2,3) opens the door but all other variants eg, (3,2,1) (2,1,3) ect would reset?

literally stuck at the start with this one...

would i have to make a bunch of save variables for each on_killed? depending on which have been killed before it?

Probably a reasonable, simple way to do it is like

Local failed = false
function enemy_1:on_dead()
  if enemy 2 or 3 is dead
    failed = true
  end
end

function enemy_2:on_dead()
  if enemy 3 is dead or enemy 1 is alive
    failed = true
  end
end

function enemy_3:on_dead()
  if enemy 1 and 2 are dead and failed = false
    Open door
  end
end


I don't want to type actual code on my phone, lol. But map:has_entity("enemy_1") will return true if they're around, false of they're dead.

This isn't the most elegant way to do this, but it's simple to understand. Honestly when I started typing I thought it'd be a lot simpler lol. If you wanted to do more than 3 enemies in a certain order, this would get bad though. Then you'd want an array of enemies that checked if each one before it was dead and each one after it was alive probably.