Skip to content

Valheim Event System

GeranisaurusRex edited this page Feb 25, 2021 · 4 revisions

Table of Contents

Classes Involved

  • RandomEvent
  • RandEventSystem
  • ZoneSystem
  • ZNet
  • Character

Workflow

Character.OnDeath()ZoneSystem.instance.SetGlobalKey(this.m_defeatSetGlobalKey)


  • Gets called when an entity dies. m_defeatSetGlobalKey would be "defeated_boss".
  • This key indicates that the boss has been defeated.

ZoneSystem.SetGlobalKey(string name)RPC_SetGlobalKey(long sender, string name)

  • Checks if key exists in ZoneSystem.m_globalKeys, if not add it.
  • Broadcasts list of keys to all connected players.

ZoneSystem.RPC_GlobalKeys(long sender, List<string> keys)

  • Clears client keys & fills with new keys.

RandEventSystem.StartRandomEvent()GetPossibleRandomEvents()

  • Gets all the possible events, if none, returns.
  • After getting possible events the game picks a random event/ZDO combo from the list & starts the event.

RandEventSystem.GetPossibleRandomEvents()

  • Gets list of all characterZDOs.
  • Cross references each event stored in m_events with RandEventSystem.m_globalKeys based on whether the key is "required or not." NOT required means the key MUST NOT be present in m_globalKeys.
  • Below are all of the event names I've pulled from the system as well as their required/notrequired keys.
EventName RequiredKey NotRequiredKey
army_eikthyr None defeated_eikthyr
army_theelder defeated_eikthyr defeated_gdking
army_bonemass defeated_gdking defeated_bonemass
army_moder defeated_bonemass defeated_moder
army_goblin defeated_moder defeated_goblinking
wolves None(Possibly Biome Specific) None
skeletons defeated_bonemass defeated_dragon
blobs defeated_bonemass None
foresttrolls KilledTroll, defeated_gdking None
surtlings killed_surtling, defeated_bonemass None
boss_eikthyr None None
boss_bonemass None None
boss_gdking None None
boss_goblinking None None

  • After this check it sends each event into GetValidEventPoints(RandomEvent ev, List<ZDO> characters).
  • This checks each ZDO to see if the event & ZDO match Biome, are near a base, & that the zdo is lower than 3000f in the y plane (I think dungeons are spawned in the sky, which could be the reason for this check.
  • If the ZDO passes the checks, its position gets added to a list.
  • After GetValidEventPoints(), it checks that the count isn't zero, grabs a random position(ZDO) from the list and adds it along with the associated RandomEvent to the list returned from GetPossibleRandomEvents().

RandEventSystem.SetRandomEvent(RandomEvent ev, Vector3 pos)

  • Last step. Makes sure event isn't null, isn't already running, and there isn't already a random event running.
  • If all checks clear, start event & SendEvent via ZRoutedRpc.

Additional Information

  • GlobalKeys are saved to the world. They can be grabbed as early as after Game.Start()
Clone this wiki locally