EVENT scripts

From Zandronum Wiki
Jump to navigation Jump to search

EVENT scripts are scripts that are triggered by various in-game events:

script 123 (int type, int arg1, int arg2) EVENT

The event that caused the script to be fired is enumerated into the type argument. arg1 and arg2 may or may not be used (depending on the event type) to provide additional data.

Script types

Player frags another player. The activator is the killing player and arg1 is the number of the player who was fragged.
Player receives a medal. The activator is the player who recieves the medal and arg1 is the string containing the name of the medal.
Player captures the flag/skull. The activator is the capturing player and arg1 is the player who assisted. If nobody assisted the capture, -1 is supplied instead. In Zandronum 3.1, arg2 returns the number of points earned.
Player touches the flag/skull. The activator is the player who touched the team item and arg1 is the team index of the team whose flag/skull was touched.
The flag/skull is returned. The activator is the player who returned the team item (or the world if the item was automatically returned), arg1 is the index of the team whose item was returned. arg2 is set to 0 if the return was done automatically or 1 if it was done by a player.
When the round starts.
The current round ends and the win sequence starts, e.g. when the fraglimit is hit.
If the round is aborted (e.g. in duel where one of the combatants leaves the game).
GAMEEVENT_CHAT 8 (development version 3.1-alpha and above only)
When a chat message is sent. The activator is always the world, arg1 is the number of the player who sent the message (if the server sent the message, -1 is passed instead), and arg2 is set to 0 if it was a global chat message or 1 if it was a team chat message.
GAMEEVENT_PLAYERCONNECT 9 (development version 3.1-alpha and above only)
A client or bot connects to the server. The activator is the world, arg1 is the number of the player, and arg2 is set to 1 if the client had previously joined the server or 0 if not.
GAMEEVENT_ACTOR_SPAWNED 10 (development version 3.1-alpha and above only)
When an non-player actor is spawned. Strictly speaking, this occurs just before the actor's first tic. The activator is the actor that spawned.
GAMEEVENT_ACTOR_DAMAGED 11 (development version 3.1-alpha and above only)
When an actor is just about to take damage, after all damage modifications are applied. The activator is the actor taking damage, arg1 is the amount of damage received, and arg2 is a dynamic ACS string containing the damage type.

Additional information

Due to risks of performance drops because of how often they might be called, GAMEEVENT_ACTOR_SPAWNED and GAMEEVENT_ACTOR_DAMAGED are disabled by default. There are two methods for enabling these event types:

  • Method A: Add the properties ForceSpawnEventScripts or ForceDamageEventScripts in the GameInfo Definition. This helps if you want all actors to execute these events. Note that using this method in the case of GAMEEVENT_ACTOR_SPAWNED, actors with the NOBLOCKMAP or NOSECTOR flags still won't execute the event. This way, only the non-trivial actors are accounted for.
  • Method B: Add the USESPAWNEVENTSCRIPT or USEDAMAGEEVENTSCRIPT flags to the actor that you wish have execute the events. These are useful if you only want certain actors to trigger the events and not all of them, which can optimize your mod better.

If you wish to forbid an actor from triggering these events, you can add the NOSPAWNEVENTSCRIPT or NODAMAGEEVENTSCRIPT flags to them.

In addition, GAMEEVENT_ACTOR_DAMAGED enables special actor pointers that give you access to the actors involved in the P_DamageMobj call:

  • AAPTR_DAMAGE_SOURCE: Accesses the "shooter" responsible for making the attack.
  • AAPTR_DAMAGE_INFLICTOR: Accesses the actor directly responsible for causing damage (e.g. a barrel or projectile).
  • AAPTR_DAMAGE_TARGET: Accesses the "victim" taking the damage. By default, this actor is already the activator of the script.

You may use these in ACS functions that deal with actor pointers, such as IsPointerEqual, SetActivator, SetPointer, or Warp.

It's recommended not to use GAMEEVENT_ACTOR_SPAWNED or GAMEEVENT_ACTOR_DAMAGED in conjunction with CLIENTSIDE scripts, since the server must tell clients to execute the scripts every time the events are fired. Due to their frequent occurrence, this can create lots of network traffic, resulting in a huge drop in performance. Furthermore, the extra actor pointers available in the latter, along with the damage type stored in arg2, do not work properly in CLIENTSIDE scripts.


Let's say we want to use GAMEEVENT_ACTOR_SPAWNED and GAMEEVENT_ACTOR_DAMAGED for our mod. For the sake of simplicity, we want the events to be triggered by all actors, so we'll create a MAPINFO lump in our WAD file and add the following:

3    ForceSpawnEventScripts = true
4    ForceDamageEventScripts = true

Next, we'll create an ACS EVENT script that prints a message whenever an actor is spawned or takes damage. GAMEEVENT_ACTOR_DAMAGED gives us access to a lot of information about how an actor takes damage, so let's also print that stuff.

 1script "ActorEvent" (int type, int arg1, int arg2) EVENT
 3    if (type == GAMEEVENT_ACTOR_SPAWNED)
 4    {
 5        // This prints every time an actor is spawned.
 6        PrintBold(s:GetActorClass(0), s:" has spawned!");
 7    }
 8    else if (type == GAMEEVENT_ACTOR_DAMAGED)
 9    {
10        // This event is called just before the actor's health is reduced. We can get
11        // their new health by subtracting their current health by arg1.
12        int oldHealth = GetActorProperty(0, APROP_HEALTH);
13        int newHealth = oldHealth - arg1;
15        // Construct a string that displays everything.
16        str message = StrParam(s:GetActorClass(0), s: " got damaged by ", d:arg1, s:" points! The damage type is: ", s:arg2);
17        message = StrParam(s:message, s:"\nTheir health was ", d:oldHealth, s:", now it's ", d:newHealth);
19        // Print the names of the source and inflictor classes, if they exist.
20        if (SetActivator(0, AAPTR_DAMAGE_SOURCE));
21            message = StrParam(s:message, s:"\nThe source was ", s:GetActorClass(0));
22        if (SetActivator(0, AAPTR_DAMAGE_INFLICTOR));
23            message = StrParam(s:message, s:"\nThe inflictor was ", s:GetActorClass(0));
25        // Set the activator back to the target.
26        SetActivator(0, AAPTR_DAMAGE_TARGET);
28        // Print the message!
29        PrintBold(s:message);
30    }