player

The hunter: position, view, health, items.

Functions that read return nothing outside a hunt (player.pos() gives no values); functions that change the hunter raise an error outside a hunt: check game.inHunt() first. Yaw is the game's heading in degrees: 0 looks along -z, 90 along +x, 180 along +z, 270 along -x (on the game's own map: east, south, west, north); creatures use the same yaw.

Functions

# player.exists() → boolean

Whether the hunter exists.

Returns
booleantrue in a hunt

# player.pos() → number, number, number

hunt only

The hunter's position.

Returns
numberx
numbery (the ground under him)
numberz
local x, y, z = player.pos()

# player.setPos(x, y, z)

hunt only

Moves the hunter. player.setPos(x, z) puts him on the ground there.

ParameterType
xnumber
ynumberheight; with two arguments (x, z) he stands on the ground
znumber

# player.teleport(x, z)

hunt only

Moves the hunter to x, z on the ground.

ParameterType
xnumber
znumber

# player.yaw() → number

hunt only

Where the hunter looks (the heading).

Returns
numberdegrees 0-360

# player.setYaw(yaw)

hunt only

Turns the hunter.

ParameterType
yawnumberdegrees

# player.pitch() → number

hunt only

How far up or down he looks.

Returns
numberdegrees, + up / - down

# player.setPitch(pitch)

hunt only

Tilts the view.

ParameterType
pitchnumberdegrees (-89 to 89)

# player.forward() → number, number

hunt only

The unit direction he looks along, on the ground.

Returns
numberdx
numberdz
local dx, dz = player.forward()
local x, _, z = player.pos()
world.spawn("velociraptor", x + dx * 3000, z + dz * 3000)

# player.health() → number

hunt only

The hunter's health.

Returns
numbercurrent health

# player.setHealth(health)

hunt only

Sets his health (he dies only by the game's own causes).

ParameterType
healthnumberabove 0, at most player.maxHealth()

# player.maxHealth(health?) → number

The hunter's full health (128). Since API 3 a value sets it until your mod unloads: regeneration goes up to it and each hunt starts with it.

ParameterType
health optionalnumbersince API 3: his full health from now on (1-100000); nil = 128 again
Returns
numberhis full health

# player.alive() → boolean

Whether the hunter is alive (false outside a hunt).

Returns
boolean

# player.weapon() → integer

The current weapon.

Returns
integerthe weapon slot in hand, -1 = none

# player.ammo(slot?) → integer?, integer?

A weapon's ammunition; nothing outside a hunt, without a weapon in hand, or for the photo camera.

ParameterType
slot optionalintegera weapon slot (default: the one in hand)
Returns
integer?the ammunition left (what the HUD shows)
integer?the rounds loaded
local total, loaded = player.ammo()
if total then draw.text(20, 20, loaded .. " / " .. total) end

# player.aim(distance?) → string?, number?, number?, number?, Creature?

hunt only

What is under the crosshair: a ray from the hunter's eyes along his view.

ParameterType
distance optionalnumberhow far to look (default 20000)
Returns
string?"terrain", "water", "object" or "creature" (nothing when nothing is hit)
number?x of the point hit
number?y
number?z
Creature?the creature hit
local kind, x, y, z, c = player.aim()
if c then draw.text(20, 60, "Target: " .. c.name, "white", 20) end

# player.eye() → number, number, number

hunt only

Where the hunter's eyes (the camera) are.

Returns
numberx
numbery
numberz

# player.credits() → integer

The player's credits (the hunt menu's money).

Returns
integer

# player.addCredits(n) → integer

Gives or takes credits (kept with the game's save): rewards, shops, bets.

ParameterType
nintegercredits to give; negative takes (not below 0)
Returns
integerthe new amount
on("kill", function(e) if e.byHunter then player.addCredits(25) end end)

# player.camouflage(on?) → boolean

hunt only

The camouflage item: creatures see the hunter worse.

ParameterType
on optionalbooleanswitch it on / off
Returns
booleanwhether it is on

# player.scent(on?) → boolean

hunt only

The cover-scent item: creatures smell the hunter worse.

ParameterType
on optionalbooleanswitch it on / off
Returns
booleanwhether it is on

# player.slot(n?) → WeaponSlot|nil

since API 3

A weapon slot of the hunter (player.weapon() stays the slot number).

ParameterType
n optionalintegera slot 0-7 (default: the weapon in hand)
Returns
WeaponSlot|nilnil without a weapon
local s = player.slot()
if s then s.ammo = s.ammo + 10 end

# player.weapons() → table

since API 3

The slots he carries this hunt.

Returns
tableWeaponSlot list in the chooser's order

# player.setWeapon(n)

hunt only since API 3

Changes the weapon through the game's own change (the one in hand is put away first; weapon_change fires).

ParameterType
nintegera slot he carries

# player.velocity() → number, number, number

hunt only since API 3

How fast he moves (the game's own velocities).

Returns
numberforward (units/s)
numbersideways
numbervertical

# player.swimming() → boolean

hunt only since API 3

Swimming.

Returns
boolean

# player.underwater() → boolean

hunt only since API 3

Under water (drowning, no call, weapon put away).

Returns
boolean

# player.inWater() → boolean

hunt only since API 3

Standing in water.

Returns
boolean

# player.breath() → number

hunt only since API 3

How long he has been under water.

Returns
numberseconds

# player.scoped() → boolean

hunt only since API 3

Looking through a scope.

Returns
boolean

# player.scanned() → Creature|nil

hunt only since API 3

The creature under the binocular or camera crosshair.

Returns
Creature|nil

# player.killer() → string?, Creature?

hunt only since API 3

After his death: what killed him (nothing while he lives).

Returns
string?the species id, "drowning" or "fog"
Creature?the creature

# player.evacuating() → boolean

hunt only since API 3

The evacuation runs.

Returns
boolean

# player.relocating() → boolean

hunt only since API 3

A relocation runs.

Returns
boolean

# player.kick(amount)

hunt only since API 3

A recoil kick of the camera.

ParameterType
amountnumbercamera units (a rifle shot: 64)

# player.jump(speed?)

hunt only since API 3

Launches him upwards (gravity takes him).

ParameterType
speed optionalnumberupward speed (default: his standing jump, 800 x jumpPower)

# player.speed(k?) → number

since API 3

A factor on his walking and swimming speed. Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
k optionalnumber0-20 (nil = 1)
Returns
number

# player.runScale(k?) → number

since API 3

A factor on the forward speed factor (balance PLAYER_FORWARD_SPEED_SCALE). Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
k optionalnumber0-20
Returns
number

# player.jumpPower(k?) → number

since API 3

A factor on his jumps (800 + forward speed x 800). Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
k optionalnumber0-20
Returns
number

# player.gravity(g?) → number

since API 3

Gravity (3000). Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
g optionalnumberunits/s² (0-100000)
Returns
number

# player.eyeHeight(h?) → number

since API 3

His standing eye height (256). 180 or lower is a crouch: creatures see him worse (the game's own rule), shots start lower. Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
h optionalnumber16-2048
Returns
number

# player.regenRate(r?) → number

since API 3

Regeneration (4/s). Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
r optionalnumberhealth per second
Returns
number

# player.drownRate(r?) → number

since API 3

Health lost per second under water (12). Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
r optionalnumber
Returns
number

# player.fogRate(r?) → number

since API 3

Health lost per second in poisonous fog (64). Kept until your mod unloads (every hunt); nil puts the game's value back.

ParameterType
r optionalnumber
Returns
number

# player.evacuate() → boolean, string?

hunt only since API 3

Starts the evacuation as the in-game menu's exit does (credits are paid at its end).

Returns
booleantrue when it started
string?why not

# player.relocate(x, z) → boolean, string?

hunt only since API 3

Relocates him as the map's RELOCATE button: the cooldown, a relocation of the profile (Dinosaur Hunter), the fade. The target is kept inside the map.

ParameterType
xnumber
znumber
Returns
booleantrue when it started
string?why not
local ok, why = player.relocate(120000, -130000)
if not ok then game.message(why) end

# player.resupply() → boolean, string?

hunt only since API 3

A resupply as the RESUPPLY button (one of hunt.resupplies; not in water unless hunt.rules.resupplyInWater).

Returns
booleantrue when the supply ship comes
string?why not

# player.fields() → table

since API 3

Every member of the hunter's struct (the raw layer).

Returns
tableFieldInfo list

# player.get(name) → any

since API 3

One member (nothing outside a hunt).

ParameterType
namestring
Returns
any
print(player.get("breath"))

# player.set(name, value)

hunt only since API 3

One member (health: above 0, at most maxHealth).

ParameterType
namestring
valueany