Actor fields by name in ACS
Availability
ZandroX behaviour. These functions exist only on ZandroX; elsewhere they return 0. They take an actor handle.
| Number | Function | Returns |
|---|---|---|
| 24030 | fua_GetField(int h, str name [, int index]) |
the field's value, or 0 for an unknown field, index or handle |
| 24031 | fua_SetField(int h, str name, int value [, int index]) |
1 after writing a user_ variable or a player field, 0 for anything else |
Usage
int h = fua_GetActorHandle( 0 );
int health = fua_GetField( h, "health" );
int special = fua_GetField( h, "args", 2 ); // the third special argument
fua_SetField( h, "user_combo", fua_GetField( h, "user_combo" ) + 1 );
- Any field DECORATE knows: the native ones
actor.txtdeclares (health,x,y,z,velx,angle,pitch,args,tid,special,radius,height,scaleXand the rest) and everyuser_variable and array. Names ignore case. - Units as the existing getters give them. Integers come back as they are, positions and sizes as
fixed point, angles with a full turn as 1.0, as
GetActorAnglegives them. - Past ±32,767 map units a position keeps only its low 32 bits, exactly as
GetActorXdoes. - Player pawns' own fields (
JumpZ,ForwardMove1,MorphWeapon, ...) read and write too, and a server's write reaches clients: see Player fields. - Other writes reach
user_variables only, asSetUserVariableallows. LikeSetUserVariable, a write stays on the machine that made it: a server's write doesn't reach clients. Native fields are changed through the existing functions afterfua_SetActivatorHandle.
Examples
Each example is a whole library: compile it with zt-bcc, add it to LOADACS and run its scripts with
pukename.
Reading what GetActorProperty doesn't reach, with positions and sizes in fixed point:
#library "fuainsp"
#import "zcommon.bcs"
script "Inspect" ( int tid ) {
int h = fua_GetActorHandle( tid );
Log( s: "health ", d: fua_GetField( h, "health" ), s: ", radius ", d: fua_GetField( h, "radius" ) >> 16,
s: ", height ", d: fua_GetField( h, "height" ) >> 16, s: ", special arg 0 ", d: fua_GetField( h, "args", 0 ) );
}
A user_ counter, kept on actors whose DECORATE declares var int user_kills;, and refused on any other:
#library "fuakills"
#import "zcommon.bcs"
script "CountKill" ( int tid ) {
int h = fua_GetActorHandle( tid );
if ( fua_SetField( h, "user_kills", fua_GetField( h, "user_kills" ) + 1 ) ) {
Log( s: "kills ", d: fua_GetField( h, "user_kills" ) );
}
else {
Log( s: "no user_kills here" );
}
}
With ACC
ACC compiles these functions with fua.acs included in place of zcommon.acs
(Compiling ACS). zt-bcc is the better fit: it checks that a field's
name is a string, where ACC compiles a number in its place and the call reads 0. The kill counter, for ACC:
#library "acckills"
#include "fua.acs"
script "AccCountKill" (int tid)
{
int h = fua_GetActorHandle(tid);
if (fua_SetField(h, "user_kills", fua_GetField(h, "user_kills") + 1))
Log(s: "kills ", d: fua_GetField(h, "user_kills"));
else
Log(s: "no user_kills here");
}
Best practices
- Name fields as DECORATE does, in any case. An unknown name reads 0, so check a name once against a value you know when a field might not exist in every engine version.
- Whole units are
>> 16. Positions and sizes are fixed point; outside astrict namespace,( int ) xkeeps their bits (see Vectors). - Write only your own
user_variables, and change native fields through their setters (SetActorProperty,SetActorPosition, ...) afterfua_SetActivatorHandle, which send the change to clients where the engine does. - For values on actors you don't own, such as another mod's monsters, use actor data: it needs no DECORATE change.
Online
Reads give each machine's own copy of the actor. A user_ write stays on the machine that made it, as
SetUserVariable's does, so a server's write doesn't reach clients: send the value to a clientside
script, or keep it on the server.