Turn Script during Combat

MrNichols
11 Oct 2018, 11:59

I have been following the Zombie Attack tutorial http://docs.textadventures.co.uk/quest/zombie-apocalypse-1.html and trying to incorporate this coding into my game. During my attack turnscript.
...
foreach (obj, GetDirectChildren(player.parent)) {
if (HasBoolean(obj, "dead")) {
if (not obj.dead) {
DoAttack (obj, obj, player)
}
}
}

...

When the player enters the room, the Algonquins immediately attack. Is there a way to make it so that the Algonquins only attack, if they are attacked first?


mrangel
11 Oct 2018, 12:51

You could modify the player's attack command so that it sets a flag on the enemy when you attack them, and then add a condition if (GetBoolean (obj, "hasattacked")) { before making them attack.

Or if you want to make them all attack when the player attacks any of them, you could set a flag on the room, to show that a fight has started. Use an if condition to test for that in the turnscript.

Or even have the turnscript disabled, and have the player's "attack" command enable it.


MrNichols
11 Oct 2018, 16:01

Thank you, I enabled the turnscript on the attack command. Worked!


MrNichols
11 Oct 2018, 22:03

New problem,

Now once I start an attack on one person in one room, then all the people in other rooms attack. In other words, I kill the mountain lion in the north, then head south and the French starting attacking me!

Here's what the code looks like:

EnableTurnScript (attackturnscript)
if (not HasBoolean(object, "dead")) {
msg ("That's not something you can attack.")
}
else if (object.dead) {
msg ("That one is already dead.")
}
else {
if (player.equipped = null) {
DoAttack (player, player, object)
}
else {
DoAttack (player, player.equipped, object)
}
}


mrangel
11 Oct 2018, 23:13

That'll be because you've only got one turnscript to enable, so it enables it everywhere.

If you want it to apply for each room, then you'd give each room a flag to say a fight has started there. For example:
attack command:

if (not HasBoolean(object, "dead")) {
  msg ("That's not something you can attack.")
}
else if (object.dead) {
  msg ("That one is already dead.")
}
else {
  player.parent.fightstarted = true
  if (player.equipped = null) {
    DoAttack (player, player, object)
  }
  else {
    DoAttack (player, player.equipped, object)
  }
}

and the turnscript:

if (GetBoolean (player.parent, "fightstarted")) {
  foreach (obj, GetDirectChildren(player.parent)) {
    if (HasBoolean(obj, "dead")) {
      if (not obj.dead) {
        DoAttack (obj, obj, player)
      }
    }
  }
}

MrNichols
11 Oct 2018, 23:44

Thank you, I think that did it.


jmnevil54
12 Oct 2018, 01:32

I would think the get remove the option to stop all the enemies following you. Unless The Pixie updated his code and I didn't know about it.