Scripting Events: Difference between revisions
(Created page with "The main method for reacting to gameplay events in Soldat 2 scripting is by registering ''listeners''. This is done by calling the <code>AddListener()</code> function, usually on the <code>Eventor</code> 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 <code>void cb_func(IGameEvent)</code>. The event types that are u...") |
No edit summary |
||
Line 46: | Line 46: | ||
A full example of an AddListener call is <code>Eventor.AddListener(Events.Died, OnPlayerDied);</code>. These calls are usually placed within the <code>Awake()</code> 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 <code>OnDestroy()</code> 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 [https://docs.unity3d.com/2020.1/Documentation/ScriptReference/MonoBehaviour.html MonoBehaviour] class for other special functions. | A full example of an AddListener call is <code>Eventor.AddListener(Events.Died, OnPlayerDied);</code>. These calls are usually placed within the <code>Awake()</code> 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 <code>OnDestroy()</code> 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 [https://docs.unity3d.com/2020.1/Documentation/ScriptReference/MonoBehaviour.html MonoBehaviour] class for other special functions. | ||
Not all necessary game events are currently accessible with just the Eventor object, methods for adding listeners to other useful events are listed below: | |||
* Player chat events: <code>GameChat.instance.OnChat.AddListener()</code>, only takes a callback function as an argument, required signature for callback is <code>void cb_func(Player, string)</code> |
Revision as of 15:39, 16 January 2023
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.
Not all necessary game events are currently accessible with just the Eventor object, methods for adding listeners to other useful events are listed below:
- Player chat events:
GameChat.instance.OnChat.AddListener()
, only takes a callback function as an argument, required signature for callback isvoid cb_func(Player, string)