Skip to content

Health

Hurting, healing and killing players, and explosions. A shot or a fall takes no health by itself: the mod hears it and decides, with hurt or set_health. At 0 health a player is dead until the mod brings them back.

Each hurt shows as it happens. The attacker sees a hit mark. The one hurt sees a red bar pointing at the attacker. Everyone sees a death, with the weapon, as a kill feed needs. A shot at a player shows its shooter a mark only once the mod hurts for it; one at an NPC shows it as it lands. The dead neither move nor fire, and no one sees them.

What a player, p, or an entity, e, reads beside the mod’s state. A field of the other side’s fails.

NameTypeSideWhat it is
p.healthnumber?On both sidesTheir health; on a client, the shown player's alone.
p.max_healthnumber?On both sidesThe health they have at most; on a client, the shown player's alone.
On the server explode(at, options)

Sets off an explosion at a point, hurting the players and NPCs around it as a grenade's does.

It plays no effect and no sound: play those with play_effect and play_sound. It goes off on the next tick, and what stops shots shields from it. It hurts by too, if near. 16 go off a tick and the rest wait their turn; past 256 waiting, more are dropped.

NameTypeWhat it is
atvectorNeeded.
optionstableA table of the options below. Those marked needed may not be left out.
radiusnumber0 to 50How far it reaches, in metres, over 0. Needed.
damagenumber0 or moreThe damage at its middle. Needed.
min_damagenumber0 or more, default 0The damage at its edge, radius away; in between it falls in a straight line from damage.
by(Player | number)?Who set it off, a player or an NPC, as its hurts and kills name them.
Fails
  • a value of the wrong type
  • an option it does not have
  • a key it needs left out
  • a value outside its range
local at = p.position
explode(at, { radius = 6, damage = 150, min_damage = 10 })
play_effect("explosion", { at = at })
play_sound("explosion_boom", { at = at, range = 200 })

To blow up the charge a player planted, so its kills are theirs

Section titled “To blow up the charge a player planted, so its kills are theirs”
local charge = model("grenade", { at = p.position })
wait(3)
explode(charge.position, { radius = 8, damage = 300, by = p })
charge:remove()
On the server p:hurt(damage, by?, weapon?, { kind?, location? }?)

Hurts a player, as a hit would, taking damage from their health; at 0 they die.

by is who did it, a player or an NPC, and weapon what with: any weapon’s name, a file of weapons/ or not. The player hurt sees a red bar pointing at by, and by sees a hit mark, as do those watching either through their eyes; a by not in play counts as no one. A death it causes is shown to everyone with who did it, the weapon, the kind and the limb, as a kill feed needs. The dead stay dead. An NPC has no health of the engine’s, so hurt on one fails: the mod keeps its own.

NameTypeWhat it is
damagenumber0 or moreNeeded.
by(Player | number)?May be left out.
weaponstring?May be left out.
howtable?A table of the options below. It, and each option, may be left out.
kind"bullet" | "melee" | "explosion" | "fall" | "mod"default "mod"How it was done, as the kill feed and the damaged and killed events' means name it.
location("head" | "neck" | "chest" | "stomach" | "upper_arm" | "lower_arm" | "hand" | "upper_leg" | "lower_leg" | "foot")?The limb it hit, one of a weapon's locations; none, a hurt of the whole body, without one.
Fails
  • a value of the wrong type
  • an option it does not have
  • a value outside its range
p:hurt(5)

To deal a zombie’s claw, so the kill feed names it

Section titled “To deal a zombie’s claw, so the kill feed names it”
local zombie = spawn()
p:hurt(40, zombie, "zombie_claw", { kind = "melee", location = "chest" })
On the server p:heal(amount)

Gives a living player back amount health, up to their maximum.

NameTypeWhat it is
amountnumber0 or moreNeeded.
Fails
  • a value of the wrong type
  • a value outside its range

To heal a player a little each second, for five seconds

Section titled “To heal a player a little each second, for five seconds”
for _ = 1, 5 do
p:heal(5)
wait(1)
end
On the server p:set_health(health)

Sets a living player's health, no higher than their maximum; at 0 they die, as by a hurt.

NameTypeWhat it is
healthnumber0 to 10000Needed.
Fails
  • a value of the wrong type
  • a value outside its range
p:set_health(p.max_health)
On the server p:set_max_health(max)

Sets a player's maximum health; everyone starts at 100.

It is kept through death, and a respawn brings the player back at it. Health over it comes down to it.

NameTypeWhat it is
maxnumber1 to 10000Needed.
Fails
  • a value of the wrong type
  • a value outside its range
p:set_max_health(250)
p:set_health(250)
On the server p:respawn()

Brings a dead player back at the next marker whose name starts with spawn, at full health, with the loadout.

Followed at once by p:set_position and p:set_angles on the same player, in the same handler, timer or tick, it brings anyone back there instead, dead or alive, and leaves that spawn for the next. A player alive is left as they are otherwise. A push, turn or move not yet carried out goes with the life before; tune, hold and limit_view outlast it.

To bring every dead player back at the start of a round

Section titled “To bring every dead player back at the start of a round”
for _, p in players do
if not p.npc and p.health == 0 then
p:respawn()
end
end

To bring a player back at a point of your choosing

Section titled “To bring a player back at a point of your choosing”
local at = vector.create(4, 0, 2)
p:respawn()
p:set_position(at)
p:set_angles({ yaw = math.pi })
On the server on("hit", fn)

Something struck a player or an NPC, once for each pellet that hits. It takes no health itself: the mod hurts them, as with p:hurt.

NameTypeWhat it is
e.victimPlayerWho was struck.
e.attackerPlayer?Who struck them; nil for no one, or one no longer here.
e.amountnumberThe damage it would do.
e.meansstringHow: bullet, melee, explosion, fall or mod, the mod's own.
e.locationstring?The limb it struck, as head; nil for an explosion or a fall.
e.weaponstring?The weapon it was done with; nil for none.
e.point{x: number, y: number, z: number}Where it struck.
e.dir{x: number, y: number, z: number}Which way it was going, a unit vector.
On the server on("fell", fn)

A player landed from over 6.5 m, a fall that would hurt, all their health from 12.2 m. It takes no health itself: the mod hurts them.

NameTypeWhat it is
e.playerPlayerWho landed.
e.amountnumberThe damage the fall would do.
e.heightnumberHow far they fell, in metres.
On both sides on("killed", fn)

A player or an NPC died, heard on the next mod tick.

NameTypeWhat it is
e.victimPlayerWho died: a player or an NPC.
e.killerPlayer?Who killed them; nil for no one, or one no longer here.
e.weaponstring?The weapon it was done with; nil for none.
e.meansstringHow: bullet, melee, explosion, fall or mod, the mod's own.
e.locationstring?The limb it struck, as head; nil for an explosion or a fall.
On both sides on("damaged", fn)

A player or an NPC lost health.

NameTypeWhat it is
e.victimPlayerWho was hurt: a player or an NPC.
e.attackerPlayer?Who hurt them; nil for no one, or one no longer here.
e.amountnumberThe health it took.
e.weaponstring?The weapon it was done with; nil for none.
e.meansstringHow: bullet, melee, explosion, fall or mod, the mod's own.
e.locationstring?The limb it struck, as head; nil for an explosion or a fall.
On a client on("hit_too_late", fn)

A shot of this player's reached its victim as they died or left, so it did nothing.

NameTypeWhat it is
e.victimPlayerWho the shot reached.