Healing Zone
Before this: Looping Over a List
Needs admin to load: it changes players’ health with the Set Player Damage gate, which only an admin can place.
Stand in the zone and your wounds heal a little every second. Turned around, the same chip makes a zone that hurts.
Contents
You need
- a brick with an Attached Zone covering the healing area
zone "Zone Ref" -> chip room
Code
// Damage healed per tick of the zone.
const HEAL = 10.0
// Seconds between ticks.
const EVERY = 1.0
@left in room: zone
var inside: character[]
on Clock(interval = EVERY) {
inside.fillFromZonePlayers(room)
for p in inside {
let hurt = p.GetDamage()
if hurt > 0.0 {
p.SetDamage(max(hurt - HEAL, 0.0))
p.ShowStatusMessage("Healing...")
}
}
}
Wire it
- Compile the chip and paste it in-game, as an admin.
- Wire the Attached Zone’s Zone Ref to
room.
Check it in game
- Get hurt first (a second copy of this chip, made into a hurting zone as in Change it, can do that), then walk into the zone: once a second a status message says “Healing…”, and your health climbs back.
- Stay in the zone at full health: no message.
- With a second player: both of you heal at once.
- Walk out: the healing stops.
Change it
- Change
HEALandEVERYfor faster or slower healing. - Make a hurting zone: use
p.SetDamage(hurt + HEAL)and drop theif hurt > 0.0check. A player dies when their damage reaches the limit thatp.GetDamage().DamageLimitreports. - Heal only players who carry a tag: pass it as
inside.fillFromZonePlayers(room, "medic"), and give players the tag withcharacter.SetTag("medic"), from a button for example.
How it works
The Clock fires every EVERY seconds
(Reacting to the Game), fills a list with the
players standing in the zone, and loops over it
(Looping Over a List). A player’s health
is kept as damage taken: 0 is unhurt, and GetDamage() reads it.
max(a, b) gives the larger of two numbers, so healing never takes the
damage below 0. The list is filled again on every tick, so a player who
walked out is no longer in it.