Scripting Events
The main method for reacting to gameplay events in Soldat 2 scripting is by registering listeners. This is done by calling the AddListener()
function, usually on the Eventor
object. In the case of Eventor listeners, you will need to specify both the event type to listen for, as well as a function to be called when the event occurs. Callback functions should have the signature void cb_func(IGameEvent)
.
The event types that are used with Eventor are defined by the Events
enum, which currently contains:
- None
- New_Connection
- Created
- Destroyed
- Died
- Add_Player
- Remove_Player
- Player_Joined
- Player_Assigned
- Player_Left
- Player_Changed_Team
- Player_Unassigned
- Level_Loaded
- Rules_Loaded
- Impacted
- Weapon_Selected
- Trigger
- Match_Waiting
- Match_Warmup
- Match_Started
- Match_Ended
- Hit
- Camera_Target_Changed
- Camera_Created
- Powerup_Started
- Powerup_Ended
- Bullet_Created
- Bot_Assigned
- Flag_Captured
- Flag_Returned
- Flag_Grabbed
- Use_Weapon
- Construct_AddBody
- Construct_RemoveBody
- Properties_Changed
- Item_Dropped
- Item_Picked
- AssignedNetworkId
- Changed_Team
- Request_Spawn
- End_Condition
- Reserved
A full example of an AddListener call is Eventor.AddListener(Events.Died, OnPlayerDied);
. These calls are usually placed within the Awake()
function of the script, which is executed when the script is loaded. Note that each AddListener call should be paired with a RemoveListener call (usually in the OnDestroy()
function) to ensure that the script does not continue to respond to events after it has been disabled. See the Unity manual entry for the MonoBehaviour class for other special functions.