How to make an object lock other objects

DuckyCream
I have an enemy in my game, and I made a combat system to kill it. But, I want to make it so that all objects in that room aren't maintainable until you kill the monster. Is there a way that I could do this? :lol:

The Pixie
You need something on the monster that changes when it dies. That could be a flag called "dead" that gets set, or a hit points attribute that is below zero. I am guessing you have already set this up.

Then you need to have the objects notice when it is dead. There are two approaches here, and which you choose depends on what maintaining an object means - you may find it convenient to do some one way and some the other.

The first approach is to change the objects when the monster dies. This would work for locked exits and containers. This would be a script that runs when the monster dies:
msg("Hurray you killed it!")
bigchest.locked = false
exit_to_next_room.locked = false

The second approach is for the object to check if the monster is dead when the player tries to do something. Say there is a vase that can be smashed, on the SMASH verb, you might do something like this:
if (monster.hits < 0) {
msg("You smash the vase.")
vase.parent = game
}
else {
msg("You cannot smash the vase while the monster is protecting it.")
}

I hope this is enough to point you in the right direction (and you can cope with code to some extent).

XanMag
Pixie's way is most likely way simpler, but what I do (and don't laugh =) is to duplicate any object in the room you want the player to be able to interact and place them in a dead room. Once the monster is dead, move the "interactable" objects from a dead room to the current room and the "non-interactable" objects to your dead room. Of course, you would need to add comments to your 'take message' or your verb commands to your "non-interactable" that print whatever message you find appropriate (i.e. "You cannot do that with that huge monster in the room for fear of being detected.")

Just my two cents and probably not helpful to you, but who knows... maybe you're a clueless trial-and-error type of game creator like me!! =)

Happy gaming!

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums