Repository navigation
Scripting Modules
A guide to scripting custom modules using Squirrel scripting language.
You can create special script modules full of functions that will be executed upon specific events in the game.
These modules can be defined as singular .nut scripts inside the Scripts/Squirrel/Custom/ directory that are automatically loaded and executed once upon starting the game. If you wish to add/remove script modules during the game or modify any existing ones, they have to be reloaded using the scr_ReloadCustomScripts() shell command.
Additionally, any extra modules can be loaded by using the scr_LoadCustomScript() shell command.
Warning
Upon reloading script modules with scr_ReloadCustomScripts(), any custom scripts that have been loaded from outside the modules directory will have to be manually loaded in again using the scr_LoadCustomScript() command.
By default, any code outside functions is executed as soon as the custom script module is loaded. But certain functions may be defined as hooks that will be called at specific points in time.
Timed events that execute upon specific tick updates.
Executed after each tick of the world simulation, essentially synchronized with the current game. Affected by real time factor.
Return value: null
Executed after rendering an entire frame of the game window.
Arguments:
-
surface-CDrawPortto draw on.
Return value: null
Events that execute upon rendering the "game" part of the game.
Executed before drawing a frame of the current game.
Arguments:
-
surface-CDrawPortto draw on.
Return value: null
Executed after drawing a frame of the current game.
Arguments:
-
surface-CDrawPortto draw on.
Return value: null
Executed after rendering a world from a certain viewpoint.
Arguments:
-
viewer-CEntityPointerwith the entity that's currently viewing the world (may be none). -
surface-CDrawPortto draw on.
Return value: null
Events that execute upon certain network packets received by the client in a game.
Executed upon adding a new player to the game.
Arguments:
-
entity-CEntityPointerwith the player that has just been added to the game. -
local- Whether this player entity belongs to the client running the script and not to some other client.
Return value: null
Executed upon removing a player from the game.
Arguments:
-
entity-CEntityPointerwith the player that has just been added to the game. -
local- Whether this player entity belongs to the client running the script and not to some other client.
Return value: null
Events that execute upon certain network packets received by the currently running server.
Executed upon a specific client trying to connect a new player to the game. The passed player character may be modified before applying it to the new player.
Arguments:
-
client- Index of the client that's trying to connect with a specific player character. -
character-CPlayerCharacterwith the player profile of the connecting player.
Return value: null
Executed upon a specific client trying to change the player character of one of their players (e.g. set a new name or a player model). The passed player character may be modified before applying it to the specified player.
Arguments:
-
client- Index of the client that requests a character change. -
player- Index of the player in the game that requests a character change (may be different for the same client index if the client is connected in split screen). -
character-CPlayerCharacterwith the new player profile that the player wants to change to.
Return value: bool with whether the character is allowed to be changed.
Executed upon receiving a player action from a specific player with new controls that need to applied. The passed player action may be modified before applying it to the specified player (e.g. to disable specific keys or modify movement/rotation speed).
Note
These player actions are sent every single simulation tick regardless of whether the player applied any input or not. This may be used in order to execute specific actions on player's behalf, such as make them walk in some direction or fire a weapon without them ever perfoming those actions themselves.
Caution
Player actions may be sent multiple times at once, each one using a different resent index. If you intend on executing singular actions upon specific player actions (such as sending packets for modifying entities), make sure to always check for resent index of -1 and exiting the function if it's not equal to it!
Arguments:
-
client- Index of the client that sent the player action. -
player- Index of the player in the game that needs to apply the new player action. -
action-CPlayerActionwith the action to apply to the specified player. -
resent- Index of the buffered action that needs to be reapplied. Index of the original unbuffered action is always-1.
Return value: null
Executed upon receiving a chat message from the specified client but before sending it out to the destination players.
Arguments:
-
client- Index of the client that sent the chat message. -
from_mask- Integer with the bit mask of players that are sending the chat message. -
to_mask- Integer with the bit mask of players that are supposed to receive the chat message. -
message- String with the chat message.
Return value: bool with whether the chat message can be forwarded to the requested players instead of simply processed and discarded.
Executed upon receiving a chat message from the server to be displayed in chat for this client locally.
The function may optionally return an array with two strings that will modify the way the chat message will be printed out in the console. If the sender name or the message are set to empty strings (""), the chat message will not be printed out. If the return value isn't an array or doesn't contain two strings, it is ignored.
Arguments:
-
from_mask- Integer with the bit mask of players that sent the chat message to this client. -
from_name- String with the symbolic name of the chat sender (e.g."Server","Client 1","Client 2"etc.). -
sender- String with the names of the chat message senders (may be the same asfrom_nameif there are no physical players that sent the message). -
message- String with the chat message.
Return value: array with two strings:
- New sender name (set it to
senderto keep it the same) - New chat message (set it to
messageto keep it the same)
Events that execute upon game logic.
Executed after starting any game.
Return value: null
Executed after changing levels during the game.
Return value: null
Executed after stopping the game.
Return value: null
Executed after saving the game into the specified save file.
Arguments:
-
file- String with the path to the save file.
Return value: null
Executed after loading the game from the specified save file.
Arguments:
-
file- String with the path to the save file.
Return value: null
Events that execute upon demo logic.
Executed after starting playing the specified demo file.
Arguments:
-
file- String with the path to the demo file.
Return value: null
Executed after starting recording the specified demo file.
Arguments:
-
file- String with the path to the demo file.
Return value: null
Executed after stopping recording a demo file.
Return value: null
Events that execute upon specific entity logic.
Executed upon sending some generic event to some entity.
Arguments:
-
entity-CEntityPointerwith the entity that's supposed to receive the event. -
event- Event code of the sent event. -
args- Array of event arguments depending on the event code.
Return value: null
Executed upon sending some enemy event to some enemy (
EnemyBase).
Arguments:
-
entity-CEntityPointerwith the entity that's supposed to receive the event. -
event- Event code of the sent event. -
args- Array of event arguments depending on the event code.
Return value: null
Executed upon sending some player event to some player entity (
PlayerorPlayerWeapons).
Arguments:
-
entity-CEntityPointerwith the entity that's supposed to receive the event. -
event- Event code of the sent event. -
args- Array of event arguments depending on the event code.
Return value: null
Executed upon receiving some generic event by some entity during its procedure logic.
Depending on specific entity logic, it may not always trigger, even if the same event triggeredOnSendGenericEvent.
Arguments:
-
entity-CEntityPointerwith the entity that's receiving the event. -
event- Event code of the sent event. -
args- Array of event arguments depending on the event code.
Return value: null
Executed upon receiving some enemy event by some enemy (
EnemyBase) during its procedure logic.
Depending on specific entity logic, it may not always trigger, even if the same event triggeredOnSendEnemyEvent.
Arguments:
-
entity-CEntityPointerwith the entity that's receiving the event. -
event- Event code of the sent event. -
args- Array of event arguments depending on the event code.
Return value: null
Executed upon receiving some player event by some player entity (
PlayerorPlayerWeapons) during its procedure logic.
Depending on specific entity logic, it may not always trigger, even if the same event triggeredOnSendPlayerEvent.
Arguments:
-
entity-CEntityPointerwith the entity that's receiving the event. -
event- Event code of the sent event. -
args- Array of event arguments depending on the event code.
Return value: null
Executed upon any player receiving a new item.
Arguments:
-
entity-CEntityPointerwith the entity that's receiving the item. -
event- Event code of the received item. -
args- Array of event arguments depending on the event code. -
picked- Whether the item has been successfully picked up by the player instead of simply passing through it.
Return value: null
Executed upon any entity receiving any sort of damage.
Arguments:
-
caller-CEntityPointerwith the entity that called the function to deal damage. -
target-CEntityPointerwith the target that receives damage. -
inflictor-CEntityPointerwith the entity that dealt the damage (may be different fromcalleror even none). -
damage_type- Damage type from theDMTenum. -
damage_amount- Amount of damage that was supposed to be dealt. -
hit_point-FLOAT3Dwith the absolute position of the physical point of damage. -
direction-FLOAT3Dwith the normalized direction away from the source of damage (e.g. in the opposite direction from the explosion).
Return value: null
Timed events that execute globally across the entire game.
Executed each game tick regardless of the current world at a constant tickrate of 20 TPS.
Return value: null
Executed each second regardless of the current world (right after the first tick at 20 TPS).
Return value: null
Reference table for arrays of arguments that are passed into listener functions depending on the event code.
Event codes that may be passed to OnSendGenericEvent() or OnReceiveGenericEvent() with their respective arguments.
Event code (event) |
Arguments array (args) |
Argument types |
|---|---|---|
EVENTCODE.EInternal |
[] |
None |
EVENTCODE.EVoid |
[] |
None |
EVENTCODE.EReturn |
[] |
None |
EVENTCODE.EBegin |
[] |
None |
EVENTCODE.ETimer |
[] |
None |
EVENTCODE.ETouch |
[other, this_moved, collision] |
CEntityPointer, bool, FLOATplane3D
|
EVENTCODE.EPass |
[other, this_moved] |
CEntityPointer, bool
|
EVENTCODE.EBlock |
[other, collision] |
CEntityPointer, FLOATplane3D
|
EVENTCODE.EWouldFall |
[] |
None |
EVENTCODE.ETeleport |
[] |
None |
EVENTCODE.EPreLevelChange |
[user_data] |
integer |
EVENTCODE.EPostLevelChange |
[user_data] |
integer |
EVENTCODE.EFirstWorldBase |
[] |
None |
EVENTCODE.EDamage |
[inflictor, direction, hit_point, damage, damage_type] |
CEntityPointer, FLOAT3D, FLOAT3D, float, integer (DMT enum) |
EVENTCODE.EDeath |
[inflictor, direction, hit_point, damage, damage_type] |
CEntityPointer, FLOAT3D, FLOAT3D, float, integer (DMT enum) |
EVENTCODE.ETakingBreath |
[breath_delay] |
float |
EVENTCODE.EActivate |
[] |
None |
EVENTCODE.EDeactivate |
[] |
None |
EVENTCODE.EEnvironmentStart |
[] |
None |
EVENTCODE.EEnvironmentStop |
[] |
None |
EVENTCODE.ETeleportMovingBrush |
[] |
None |
EVENTCODE.EEnd |
[] |
None |
EVENTCODE.EStop |
[] |
None |
EVENTCODE.EStart |
[caller] |
CEntityPointer |
EVENTCODE.ETrigger |
[caller] |
CEntityPointer |
EVENTCODE.EReminder |
[value] |
integer |
EVENTCODE.EScroll (only in TSE) |
[start, sender] |
bool, CEntityPointer
|
EVENTCODE.ETextFX (only in TSE) |
[start, sender] |
bool, CEntityPointer
|
EVENTCODE.EHudPicFX (only in TSE) |
[start, sender] |
bool, CEntityPointer
|
EVENTCODE.ECredits (only in TSE) |
[start, sender] |
bool, CEntityPointer
|
Event codes that may be passed to OnSendEnemyEvent() or OnReceiveEnemyEvent() with their respective arguments.
Event code (event) |
Arguments array (args) |
Argument types |
|---|---|---|
EVENTCODE.EStartAttack |
[] |
None |
EVENTCODE.EStopAttack |
[] |
None |
EVENTCODE.EStopBlindness |
[] |
None |
EVENTCODE.EStopDeafness |
[] |
None |
EVENTCODE.EHitBySpaceShipBeam |
[] |
None |
EVENTCODE.ERestartAttack |
[] |
None |
EVENTCODE.EReconsiderBehavior |
[] |
None |
EVENTCODE.EForceWound |
[] |
None |
EVENTCODE.ESound |
[sound_type, target] |
integer, CEntityPointer
|
Event codes that may be passed to OnSendPlayerEvent() or OnReceivePlayerEvent() with their respective arguments.
Event code (event) |
Arguments array (args) |
Argument types |
|---|---|---|
EVENTCODE.EKilledEnemy |
[] |
None |
EVENTCODE.ESecretFound |
[] |
None |
EVENTCODE.EWeaponChanged (only in TSE) |
[] |
None |
EVENTCODE.EBoringWeapon |
[] |
None |
EVENTCODE.EFireWeapon |
[] |
None |
EVENTCODE.EReleaseWeapon |
[] |
None |
EVENTCODE.EReloadWeapon |
[] |
None |
EVENTCODE.ECenterMessage |
[message, length, sound_type] |
string, float, integer
|
EVENTCODE.EComputerMessage |
[message_file] |
string |
EVENTCODE.EVoiceMessage |
[sound_file] |
string |
EVENTCODE.EReceiveScore |
[points] |
integer |
EVENTCODE.ESelectWeapon |
[weapon_slot] |
integer |
Event codes that may be passed to OnPlayerItem() with their respective arguments.
Event code (event) |
Arguments array (args) |
Argument types |
|---|---|---|
EVENTCODE.EAmmoItem |
[ammo_type, quantity] |
integer, integer
|
EVENTCODE.EAmmoPackItem (TFE) |
[shells, bullets, rockets, grenades, electricity, iron_balls] |
integer, integer, integer, integer, integer, integer
|
EVENTCODE.EAmmoPackItem (TSE) |
[shells, bullets, rockets, grenades, napalm, electricity, iron_balls, sniper_bullets] |
integer, integer, integer, integer, integer, integer, integer, integer
|
EVENTCODE.EArmor |
[amount, over_top_armor] |
float, bool
|
EVENTCODE.EHealth |
[amount, over_top_health] |
float, bool
|
EVENTCODE.EKey |
[key_type] |
integer |
EVENTCODE.EMessageItem |
[message_file] |
string |
EVENTCODE.EPowerUp (only in TSE) |
[powerup_type] |
integer |
EVENTCODE.EWeaponItem |
[weapon_type, ammo_quantity, dropped] |
integer, integer, bool
|
Designed and developed by Dreamy Cecil since 2022