fuaZandroX modding reference

Player fields and handle checks in ACS

Availability

ZandroX behaviour. These functions exist only on ZandroX; elsewhere they return 0. They take an actor handle.

Number Function Returns
24025 fua_HandlePlayer(int h [, bool dolls]) the player number of the handle's actor, or -1 when it is no player's body
24026 fua_HandleMatches(int h, int filter [, a [, b]]) whether the handle's actor passes one query filter
24030 fua_GetField(int h, str name [, int index]) a player pawn's field by name too, as below
24031 fua_SetField(int h, str name, value [, int index]) 1 after writing a player pawn's writable field too, 0 when refused

Usage

int h = fua_GetActorHandle( 0 );
if ( fua_HandlePlayer( h ) >= 0 ) {
   fua_SetField( h, "JumpZ", 12.0 );
   fua_SetField( h, "MorphWeapon", "Chainsaw" );
}
if ( fua_HandleMatches( h, FQ_CLASS, "Weapon" ) ) { /* any weapon, a mod's subclasses too */ }
if ( fua_HandleMatches( h, FQ_MONSTER ) ) { /* a monster */ }
  • fua_HandlePlayer gives the player number of a player's body, morphed or not, bots included. A body left behind when its player respawned gives -1, and so does a voodoo doll unless dolls is true.
  • fua_HandleMatches takes any FQ_ filter with the arguments fua_QueryFilter takes: FQ_CLASS (with subclasses unless its second argument is 0) answers "is it an Inventory, a Weapon, a CustomInventory, a PlayerPawn" or any class a mod declares; FQ_MONSTER, FQ_PLAYER and FQ_MISSILE the kinds that aren't classes; FQ_FLAG, FQ_ALIVE and the rest as in queries. The range filters FQ_2D and FQ_EDGES always match. A stale handle or an unknown filter gives 0.
  • Player fields are found once DECORATE's own fields miss, on player pawns only, any case. They follow UZDoom's ZScript PlayerPawn: its plain fields read and write, its meta fields only read and PlayerFlags stays hidden. The fork's own movement tuning reads and writes the same way.
  • Units as DECORATE gives them. Speeds, heights and the tuning values are fixed point, names, classes, textures and sprites strings. A write of a class, texture or sprite that doesn't exist is refused, and "" clears one.
  • A new body starts from its class. Respawning or morphing gives the player a new pawn with its class's values, as in UZDoom; write them again from a RESPAWN script if they should last.
Field Kind Access
MaxHealth, MugShotMaxHealth, RunHealth, SpawnMask int read/write
JumpZ, GruntSpeed, FallingScreamMinSpeed, FallingScreamMaxSpeed, ViewHeight, AttackZOffset, FullHeight, UseRange, AirCapacity fixed read/write
ForwardMove1-4, SideMove1-4 fixed, walk, run, crouch-walk and crouch-run read/write
ViewBob, ViewBobSpeed, FlyBob, WaterClimbSpeed fixed read/write
DamageFade int, the colour as 0xRRGGBB with its alpha on top read/write
MorphWeapon string, a weapon class name read/write
FlechetteType string, an Inventory class name read/write
ScoreIcon string, a texture name read/write
crouchsprite string, a four-letter sprite name read/write
SoundClass string, as APROP_SoundClass read/write
MvType, RejumpDelay, FootstepInterval, JumpDelay, SecondJumpDelay, SecondJumpAmount, DoubleTapMaxTics, CrouchSlideEffectInterval, WallClimbEffectInterval int read/write
AirAcceleration, VelocityCap, CrouchScale, CrouchChangeSpeed, JumpXY, SecondJumpXY, SecondJumpZ, WallClimbSpeed, AirWallRunMinVelocity fixed read/write
GroundAcceleration, GroundFriction, CpmAirAcceleration, CpmMaxForwardAngleRad, FootstepVolume, CrouchSlideAcceleration, CrouchSlideFriction, CrouchSlideMaxTics, CrouchSlideRegen, WallClimbFriction, WallClimbMaxTics, WallClimbRegen, AirWallRunMaxTics, AirWallRunRegen fixed read/write
FootstepsEnabled1-4 bool read/write
EffectActors string array of 3, an actor class name for the crouch-slide, wall-climb and footstep slots read/write
InvFirst, InvSel handle of an inventory item, 0 for none read
TeleportFreezeTime int read
Face, Portrait, HealingRadiusType, InvulMode string read
Slot string array of 10, the class's weapon slot list read
HexenArmor fixed array of 5 read
ColorRangeStart, ColorRangeEnd int read

MaxHealth, JumpZ, ViewHeight, MvType, RejumpDelay and SoundClass are written as SetActorProperty writes them (APROP_SpawnHealth for MaxHealth), with the same checks and sends.

Examples

Each example is a whole library: compile it with zt-bcc, add it to LOADACS and run its scripts with pukename.

Reading a player's movement, in whole units where fixed point:

#library "fuaplrd"
#import "zcommon.bcs"

script "PlayerInfo" ( void ) {
   int h = fua_GetActorHandle( 0 );
   Log( s: "player ", d: fua_HandlePlayer( h ), s: ", jump ", d: fua_GetField( h, "JumpZ" ) >> 16,
      s: ", use range ", d: fua_GetField( h, "UseRange" ) >> 16, s: ", sound class ", s: fua_GetField( h, "SoundClass" ) );
}

A lighter player for one map: a higher jump, a faster run and no view bob, and a meta field that refuses the write:

#library "fuaplwr"
#import "zcommon.bcs"

script "Featherweight" ( void ) {
   int h = fua_GetActorHandle( 0 );
   fua_SetField( h, "JumpZ", 16.0 );
   fua_SetField( h, "ForwardMove2", 1.5 );
   fua_SetField( h, "ViewBob", 0 );
   Log( s: "jump ", d: fua_GetField( h, "JumpZ" ) >> 16, s: ", bob ", d: fua_GetField( h, "ViewBob" ),
      s: ", face written ", d: fua_SetField( h, "Face", "STC" ) );
}

Telling handles apart, here the player and the map's first imp:

#library "fuaplis"
#import "zcommon.bcs"

script "WhatIsIt" ( int tid ) {
   int h = fua_GetActorHandle( tid );
   Log( s: "player ", d: fua_HandlePlayer( h ), s: ", pawn ", d: fua_HandleMatches( h, FQ_CLASS, "PlayerPawn" ),
      s: ", monster ", d: fua_HandleMatches( h, FQ_MONSTER ), s: ", inventory ", d: fua_HandleMatches( h, FQ_CLASS, "Inventory" ) );
}

With ACC

ACC compiles these functions with fua.acs included in place of zcommon.acs (Compiling ACS). zt-bcc is the better fit: it refuses a string where a handle belongs and a number where a field's name belongs, where ACC compiles either and the call returns 0. Reading a player and telling handles apart, for ACC:

#library "accplis"
#include "fua.acs"

script "AccWhatIsIt" (int tid)
{
    int h = fua_GetActorHandle(tid);
    Log(s: "player ", d: fua_HandlePlayer(h), s: ", pawn ", d: fua_HandleMatches(h, FQ_CLASS, "PlayerPawn"),
        s: ", monster ", d: fua_HandleMatches(h, FQ_MONSTER), s: ", use range ", d: fua_GetField(h, "UseRange") >> 16);
}

Best practices

  • Check the handle before writing. fua_HandlePlayer( h ) >= 0 keeps a write to a player's body; a monster's handle reads every player field as 0 and refuses every write.
  • Write from the server's scripts. A clientside script reads the server's values, but its writes are refused, so a client's prediction never parts from the server.
  • Write again after a respawn if a change should outlive the body, from a RESPAWN script.
  • Prefer a field to a DECORATE class swap for a temporary change: a class change resets the inventory and the sprite, a field only the one value.

Online

A server's write goes to every client, and a client joining later gets every field a script changed from its class's value, so the player's own prediction, the HUD and clientside scripts all use the server's values. MaxHealth, JumpZ, ViewHeight, MvType, RejumpDelay and SoundClass travel as SetActorProperty's do. fua_HandlePlayer and fua_HandleMatches read each machine's own copy of the actor.

Implementation notes

src/zandronum/src/features/acs-player-fields/.