How to have monsters regenerate when you enter a room

The below is an example of one of the monsters. Basically what I want is for the zombies to return to full health once players pass through a particular exit / enter a room. I tried doing Set Attribute if Player Has Flag or if Player Is In Room but that didn't seem to work. I think because the attribute is only at that number WHILE they're in that room so the moment they leave the enemy returns to its uninjured state. So, how could I reset the monster?

      <object name="ZedStrainI">
      <inherit name="editor_object" />
      <inherit name="surface" />
      <displayverbs type="stringlist">
        <value>Look at</value>
        <value>Attack</value>
      </displayverbs>
      <feature_startscript />
      <alias>well-dressed zed</alias>
      <dead type="boolean">false</dead>
      <feature_container />
      <contentsprefix>in whose pocket there is</contentsprefix>
      <inroomdescription>You can see a well-dressed fellow in a suit standing at the other end of the corridor, swaying slightly.  He twitches, then lurches around to face you.</inroomdescription>
      <attr name="_initialise_" type="script"><![CDATA[
        this.listalias = CapFirst(this.alias)
        this.damage = 1
        this.attack = 0
        this.defence = 0
        this.armour = 0
        this.critdesc = "{random:You blank out a moment from the force of the #attacker#'s blow.  Luckily, you don't fall:Damnit!  You've been hit hard by the #attacker#:The #attacker# launches itself at you.  Its desperate strikes sends you reeling:The #attacker# slams into you, knocking you into a wall so hard your head rings:The #attacker# screams in your ear as it batters you with its weapon:Your rib cracks under the force of the #attacker#'s blow.} (#hits# hits)."
        this.attackdesc = "{random:#Attacker# batters you with its fist:#Attacker# wallops you in the side of the head with its weapon:#Attacker# smacks you across the shoulders with its weapon:You cop a hit to the knee as #attacker# rushes at you} (#hits# hits)."
        this.missdesc = "{random:#Attacker# misses you by mere inches:#Attacker#'s blow is too weak to hurt:You side-step #attacker#'s strike:#Attacker# stumbles into furniture or a wall and misses you}."
        this.changedhitpoints => {
          if (this.hitpoints < 1) {
            msg ("It is dead!")
            this.dead = true
          }
        }
      ]]></attr>
      <search type="script">
        MakeObjectVisible (half chewed pencil)
        msg ("You find a half chewed pencil in it's top pocket.")
      </search>
      <harvest type="script">
        msg ("You surgically remove its wastelander gland.  A good source of blood and DNA.")
        CloneObjectAndMove (ZedStrainIglands, ZedStrain1)
      </harvest>
      <loot type="script">
        MakeObjectVisible (half chewed pencil)
        msg ("You find a half chewed pencil in it's top pocket.")
      </loot>
      <look type="script"><![CDATA[
        if (ZedStrainI.dead = false) {
          msg ("The wild look in the creature's eyes chills you to the core.")
        }
        else {
          msg ("It's a corpse on the ground.  You can <b>loot</b> it and physicians / scientists can <b>harvest</b> it.")
        }
      ]]></look>
      <hitpoints type="int">3</hitpoints>
      <changedhitpoints type="script">
        if (game.pov = ) {
          ZedStrainI.hitpoints = ZedStrainI.hitpoints = 7
        }
      </changedhitpoints>
      <object name="half chewed pencil1">
        <inherit name="editor_object" />
        <visible type="boolean">false</visible>
      </object>
    </object>

One way would use a turn script, and heal each creature 1 HP per turn, up to their max...
But you need to prevent this during combat.
Then, if you return to a room shortly after the battle, you would not face a fully healed creature...
Maybe one partly healed...
Or... maybe what you want looks like this...
Room 1: start room
Room 2: empty
Room 3: zombie (fight and kill)
Room 4: nothing (zombie still dead)
Room 5: Big bat (fight and kill)
Room 6: Zombie regenerates, fight it if you go back there
Room 7: empty
Room 8: Bat regenerates
And so on...
Could add
Room 2: empty, Bat regenerates if killed.


Basically what I want is for the zombies to return to full health once players pass through a particular exit / enter a room

Exits can have a script that runs when the player clicks them. Rooms can have a script that runs when the player enters or leaves them.
Set one of these scripts (on the "scripts" tag for the exit or room) and just make it set the zombie's health to full. For example:

ZedStrainI.hitpoints = 100
ZedStrainI.dead = false

I'd need to set that for each individual creature it applies to, right? That's fine, just want to know. :)


If you want to make it apply to multiple creatures, you can do that. You just need to have some way for Quest to know which ones you want to restore.

Script to restore all enemies (well, everything with "hitpoints" and "dead" attributes) to 10 HP:

foreach (obj, AllObjects()) {
  // Make sure we don't include the player, if he has hitpoints too
  if (not obj = game.pov) {
    if (HasBoolean(obj, "dead") and HasInt(obj, "hitpoints")) {
      obj.hitpoints = 10
      obj.dead = false
    }
  }
}

If you give them a maxhitpoints attribute, we can use that to decide what to reset their HP to. This is better if you have some enemies with different HP totals. Enemies without a maxhitpoints wouldn't be restored:

foreach (obj, AllObjects()) {
  if (HasInt(obj, "maxhitpoints")) {
    obj.hitpoints = obj.maxhitpoints
    obj.dead = false
  }
}

If you want to restore them, but not fully:

foreach (obj, AllObjects()) {
  if (HasInt(obj, "maxhitpoints")) {
    obj.dead = false
    if (obj.hitpoints < obj.maxhitpoints) {
      obj.hitpoints = obj.hitpoints + 1
    }
  }
}

If you just want to heal the ones in a certain room:

foreach (obj, GetAllChildObjects(master bedroom)) {
  if (HasInt(obj, "maxhitpoints")) {
    obj.hitpoints = obj.maxhitpoints
    obj.dead = false
  }
}

(if you want to heal all the enemies in a particular building or area, you can create a room for the building and put all the rooms inside it. The player never sees it, but it makes stuff like this easier)

If you only want to respawn the dead zombies:

foreach (obj, FilterByAttribute(AllObjects(), "dead", true)) {
  if (HasInt(obj, "maxhitpoints")) {
    obj.hitpoints = obj.maxhitpoints
    obj.dead = false
  }
}

(or to heal any that have been injured but not killed, change 'true' to 'false')

If you're after healing all clones of a particular zombie, or all zombies of a particular type (assuming you have an original and create clones of it in different places):

foreach (obj, FilterByAttribute(AllObjects(), "prototype", Original Zombie)) {
  obj.hitpoints = obj.maxhitpoints
  obj.dead = false
}

Those are the most likely options I can think of. But if there's some other situation you can think of, I'm sure it can be done.


Log in to post a reply.

Support

Forums