Best way of triggering events?

I'm looking at some ways I can trigger an event.
I have the player going into a 4 room house and at some stage near the start of the adventure I want him to hear a sound in room 1 then discover a character in that room.
The two common ways to do this would be to have a turns counter so that after a certain amount of turns the player gets a message about hearing a sound in room 1
The other way is to have the character walk into one of the other rooms (2-4) which would trigger the message that someone is in room 1.
If the character walks into the room 1 at the start of the adventure then the character is not there.
Adventure players are unpredictable. If the player decided to spend all his time in room 1 then the character would not appear as the player needs to be out of room 1. If I used a "when entering a certain room" to trigger this new character event then the player might not go into the certain room or might go into the room at the start of the game which triggers the character's arrival too soon.
I need a bit of time for the player to explore the house, especially exploring room 1 before the character arrives. The character comes into the house and is discovered in room 1.

Just after suggestions thanks as someone may of thought of an idea that I have not through of.


Is there a 'room' for the house, which contains the other rooms? That can sometimes make it easier for scripting purposes. (This could be done without it, but takes a little longer)

I'd probably have a turnscript something like:

if (Contains (house, game.pov) and not Contains (room1, game.pov)) {
  roomsvisited = FilterByAttribute (GetDirectChildren (house), "visited", true)
  if (ListContains (roomsvisited, room1) and RandomChance (8 * ListCount (roomsvisited)) {
    // code to run the event here
    this.enabled = false
  }
}

This seems most natural to me. The event only triggers if the player has visited room1 but isn't there now, and the chance of it happening each turn increases the more rooms they've visited. You can tweak the probabilities by adjusting one number; I think for a typical player this would take around 5-6 turns.

(I used game.pov in the code instead of player because that's a good habit to get into. Not sure if you've come across that one yes, but game.pov refers to the current player object)


Thanks mrangel.

Please correct me if I'm wrong.
From the code you've suggested I'm thinking that it reads if player is in the house and player is not in room 1 then
get the number of rooms the player has visited and use this number to increase the chance of an event from happening.
If the list of room visited contains room1 and the random number passes then trigger the event.

I'm not certain what this.enabled = false is for, maybe it disables something in the code.


In answer to your question mrangel
The house is a location and not a container and each room is a location.


I'm not certain what this.enabled = false is for, maybe it disables something in the code.

Within a turnscript, this refers to the turnscript. So in this case, the turnscript disables itself to stop the event triggering again (I guessed this was the desired behaviour).

The house is a location and not a container and each room is a location.

I only asked because I used GetDirectChildren (house) to get the list of rooms; that assumes that the rooms are all inside the house. It doesn't matter if the house is a room or an object; just that the rooms are inside the house. If they weren't, it would take a bit more code to see if the player had visited them.


Ok thanks mrangel.


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

Support

Forums