ZDO¶
The bread-and-butter of Valhiem
This class represents automatically synchronized networked objects and states throughout Valheim gameplay.
Shared lifetime
All ZDO's retrieved via ZDOManager or through callbacks have shared references, and thus are safe to persistently store between calls unlike the previous project.
Instance Members¶
zdo.id¶
Returns
ZDOID| readonlyThe id of the zdo
zdo.pos¶
Returns
Vec3fThe position of the zdo
zdo.zone¶
Returns
Vec2i| readonlyThe current zone the zdo is contained within
zdo.rot¶
Returns
QuaternionThe rotation of the zdo
zdo.prefab¶
Returns
Prefab| readonly
zdo.prefab_hash¶
Returns
number| readonly
zdo.owner¶
Returns
Int64
zdo:is_owner(uuid)¶
Returns
booleanChecks whether the specified uuid is the owner of the zdo
zdo.mine¶
Returns
booleanWhether the zdo is owned by the server
Can set to true to locally claim ownership
zdo.mine = true -- zdo.owner is now the server zdo.mine = false -- zdo is now unclaimed (owner set to 0)
zdo.owned¶
Returns
boolean| readonlyReturns whether this zdo has an owner
zdo:disown()¶
Sets the zdos owner to none (0)
zdo.data_rev¶
Returns
number| readonlyThe zdos data revision number
zdo.owner_rev¶
Returns
number| readonlyReturns the zdos owner revision number
zdo.ticks_created¶
zdo.ticks_createdReturns
Int64Returns the time in ticks the zdo was created
Removed following Valheim version 0.x.x where ZDO's underwent a rehaul for memory efficiency
Data Variables¶
ZDOs have Data Variables that are automatically synchronized between server and client. Data Variables are contained in key, value pairs within individual types. Can be read and written from using accessors below:
Getters¶
A zdo has several named getter and setter types
get_float,get_int,get_long,get_quat,get_vec3f,get_string,get_bool,get_zdoidzdo:get_...(hash: number, default: any) zdo:get_...(hash: number) zdo:get_...(name: string, default: any) zdo:get_...(name: string)local t = zdo.get_float("plantTime", 240) -- if "plantTime" does not exist, 240 is returned
Setters¶
set_float,set_int,setzdo:set_...(hash: number, value: any) zdo:set_...(name: string, value: any)The overload
set(...)accepts any of the above non-numeric typesAny usage of a long (64-bit integer) utilizes a
Int64and is overloaded byset(...)zdo:set("RightBackItem", "chestplate") zdo:set(VUtils.String.GetStableHashCode("RightBackItem"), "chestplate") -- the two lines above achieve the same outcome -- all keys are 32-bit hashes, lost but obtainable through lookup
ZDO <-> ZDO Connection¶
zdo:set_connection(type: ConnectorType, zdoid)¶
Sets the connection pair for this ZDO
zdo:get_connection(type: ConnectorType)¶
Returns
ZDOIDThe conneciton pair for the ZDO