Turn Script to spawn monsters

jmnevil54
26 Oct 2017, 13:32

So I need help with this.

This is my turn script.

msg ("You did something.")
if (game.spawn = true) {
  game.spawncount = game.spawncount + 1
}
if (game.spawncount >= 5) {
  OnEnterRoom (SpawnZombie (this))
}

I suppose I would need to make a new turn script for each monster that spawns in a room.

I don't know how to make this spawn a monster in every room.

Basically what I'm trying to do is, to make the monster spawn after 5 turns pass, the player enters the room, and game.spawn = false.

game.spawncount counts the turns, in this case 5.

game.spawn is used to make sure the player isn't stuck in an infinite monster loop, since I teleport the player to a different room for the battle.

SpawnZombie (this) is the function to spawn a monster, and the parameter is this.


mrangel
26 Oct 2017, 14:23

OK... tying to work out how this works.

If you've reached 5 turns, your script:

  1. Runs the function SpawnZombie, passing it a single parameter (the turnscript object)
  2. Runs the "on exit" script for the room returned by SpawnZombie
  3. Runs the "on enter" scripts, and shows the description for, the room the player is currently in

Is that what it's supposed to do?

I can think of a few things you might want the turnscript to do. I think from when I looked at your code previously, you've got a room's onenter script teleporting them to a battle room to fight. So I assume you want the turnscript to set that onenter script on some room. But which room?

  • The room the player is currently in?
  • The next room they enter?
  • Every room?
  • Every room with a certain attribute?
  • A randomly selected room?
  • A randomly selected room with a certain attribute?

jmnevil54
26 Oct 2017, 14:45

I select the rooms. But you pretty much got the rest covered.


mrangel
26 Oct 2017, 14:53

As an example (and looking at the last version of your game I've seen), this turnscript should spawn a zombie in a room picked randomly from a list:

msg ("You did something.")
if (game.spawn = true) {
  game.spawncount = game.spawncount + 1
  if ((game.spawncount % 5) = 0) {
    // This line picks a random room from those listed; change it if that's not the behaviour you want
    some_room = GetObject(PickOneString(Split("room;Hell 1;Hell 2;Fuck 3",";")))
    some_room.enter => {
      SpawnZombie (this)
      this.enter = null
    }
  }
}

jmnevil54
26 Oct 2017, 14:56

Well... I was thinking that the turn script would work for almost all the rooms, like Enpherdaen's.

I asked if I could see his code, but he hasn't responded yet.


mrangel
26 Oct 2017, 15:14

So ... after 5 turns, a zombie spawns in every room? Or a room that contains a zombie spawns another one 5 turns after you kill the first?

option 1: Every 5 turns, spawn a zombie in every room that doesn't have one (from a list in the turnscript):

if (HasObject (game.pov, "currentcommandpattern")) {
  if (game.spawn = true) {
    game.spawncount = game.spawncount + 1
    if ((game.spawncount % 5) = 0) {
      foreach (roomname, Split("room;Hell 1;Hell 2;Fuck 3",";")) {
        room = GetObject(roomname)
        room.beforeenter => {
          SpawnZombie (this)
          this.beforeenter = null
        }
      }
    }
  }
}

option 2: Spawn a zombie in each room 5 turns after you killed the last one. A simpler turnscript:

if (game.spawn = true) {
  foreach (room, AllObjects()) {
    if (HasInt(room, "spawncount")) {
      room.spawncount = room.spawncount + 1
    }
  }
}        

and the 'beforeenter' script for zombie rooms becomes:

firsttime {
  // There's already a zombie here the first time
  this.spawncount = 5
}
if (this.spawncount >= 5) {
  this.spawncount = 0
  SpawnZombie (this)
}

jmnevil54
26 Oct 2017, 15:38

Thanks! I'll try option 2!


mrangel
26 Oct 2017, 15:52

Like the one I did for Enpherdaen; the turnscript does the minimum work possible, just incrementing the counter so that each room's enter script can check the number. That means that you can adjust the number in each room, to make some rooms take longer than others to spawn; or have some rooms call a different function instead of SpawnZombie so that they spawn different monsters.

In the 'option 1' script I wrapped the turnscript up in if (HasObject (game.pov, "currentcommandpattern")) {, which should stop it from counting turns where the player made a typo or entered something Quest doesn't understand. Not sure if you want to include that or not.