Variables must always include their specific prefix so the engine knows the data type. Create or update variables using =.
From most to least used:
| Type | Prefix | Description | Examples |
|---|---|---|---|
| Player | @ |
Array of players | @sender, @all, @evAttacker |
| Literal | $ |
Numbers, text, time, booleans, colors, enums | $age = 10, $time = 5s, $role = "Scientist" |
| Reference | * |
C# objects (e.g., rooms, items) | *spawnRoom, *evRoom |
| Collection | & |
A list of multiple items | &inventory, &rooms |
-
Local (Default): Deleted when the script finishes. (
$var = 10) -
Global: Persists for the entire round. Accessible by other scripts. You must use the
globalkeyword when assigning/changing it to avoid local name collisions. Read without the keyword. -
Set:
global $score = 100 -
Read:
Print {$score} -
Verify:
if {VarExists $myGlobal} is false -
Ephemeral: Exists only inside a specific loop or function. (
ephm $x = 1)
- Basic Text: Enclosed in double quotes (
"Hello!"). - Interpolation (
{}): Insert variables/properties into text ("Hello {$name}"). - Escaping (
~): Prevent interpolation ("var: ~{$var}"printsvar: {$var}). - Newlines: Use
<br>. - Comments (
#): Must have a space after the pound sign (# Comment).
- Operators:
+,-,*,/,%(Handled via NCalc 1.3.8). - Negative Values: Script parsing relies on whitespace, so negatives don't need parentheses (e.g.,
TPPosition @plr -37 313 -140). - Percent Sign (
%): Divides a number by 100 (50%becomes0.5).
Methods perform actions and are written in PascalCase.
- Syntax:
MethodName Arg1 Arg2(e.g.,Broadcast @all 5s "Hello") - Return Values: Can be stored directly (
$name = ServerInfo name) - The Wildcard (
*): Targets ALL of something, excluding players (CloseDoor *) - Omit Arguments (
_): Skip optional arguments (*embed = Embed.Create "Title" _ _ "Author")
Access internal data of values. Can be chained (e.g., @plr -> name -> length -> isOdd).
-
Player Properties: MUST strictly be one player. Use
{AmountOf @all}if you need a length count. -
Reference Validity: C# objects can become null. Always validate before use:
if {*room -> isInvalid}. -
Context Rules:
-
Variable definitions: No brackets (
$name = @plr -> name) -
Conditions & Interpolation: Use brackets (
if {@plr -> role} is "ClassD") -
Enum Conversion: In methods, bare enum tokens work (
SetRole @plr ClassD). In properties/conditions, enums are converted to strings (if {@plr -> role} is "ClassD").
Compare values using standard operators (is/==, isnt/!=, >, <, and/&&, or/||).
- Note:
!andnotare illegal. - Early Return: Use
stopto immediately end the script.
| Loop Type | Description | Example Syntax |
|---|---|---|
repeat |
Fixed iterations. | repeat 5 with $iter |
while |
Runs while condition is true. | while $count < 10 with $iter |
over |
Iterates through collections/arrays. | over @all with @plr |
forever |
Infinite loop. Must include wait. |
forever with $iter |
- Loop Control:
break(exit loop) andcontinue(skip iteration). withKeyword: Assigns a name to the current item or iteration number.
wait: Pause for duration (wait 5s,wait 100ms).wait_until: Pause until a condition is met (wait_until {AmountOf @all} > 0).
Must be hoisted (defined before use).
The prefix in the name defines the return type($Name = literal, @Name = players, *Name = reference, &Name = collection, Name = nothing).
Call using run.
func $Add with $a $b
return $a + $b
end
$sum = run $Add 5 3
Use attempt and on_error to catch exceptions without breaking the script.
attempt
PlayAudio "invalid speaker" "invalid clip name"
on_error with $msg
Print "Error: {$msg}"
end
A script can optionally start with one flag, defining how it triggers. Use serreload if modifying a flagged script on a live server.
| Flag Type | Syntax Example | Description |
|---|---|---|
| Utility | (No flag) | Run manually via serrun or RunScript. |
| Custom Command | !-- CustomCommand heal-- availableFor RemoteAdmin |
Binds the script to a custom command. |
| Event | !-- OnEvent Dying-- require @evPlayer |
Triggers on a LabAPI game event. |
- Event Cancellation: Use
IsAllowed falsefollowed bystopto cancel the base game event. - Event Variables: Provided via C# reflection, but may not always exist. Use
--requireto validate.
| Category | Methods |
|---|---|
| Communication | Broadcast, Hint, Cassie |
| Player Control | GiveItem, ClearInventory, SetRole, SetSize, GiveEffect |
| Health & Damage | Kill, Damage, Heal, SetHealth, SetMaxHealth, Explode |
| Environment | CloseDoor, OpenDoor, LockDoor, UnlockDoor |
| Movement | TPPlayer, TPPosition |
| Utility | AmountOf, Take, Random, Chance, SetRoundLock, SetLobbyLock, SetPlayerData, GetPlayerData, HasPlayerData |
| Event | Variables Provided | Common Use Cases |
|---|---|---|
| RoundStarted | None | Round logic. |
| WaitingForPlayers | None | Server systems. |
| Death | @evPlayer, @evAttacker, $evOldRole, *evOldPosition |
Kill streaks, death rewards. |
| Hurt | @evPlayer, @evAttacker, $evDamage |
Hit reactions, damage tracking. |
| Joined | @evPlayer |
Welcome messages, tutorial hints. |
| ChangedRole | @evPlayer, $evOldRole, $evNewRole |
Class transitions, spawn effects. |
Select Random Player:
@plr = Take @all 1
Check % Chance & SCP Team:
if {Chance 25%} and {@plr -> team} is "SCPs"
# 25% chance to run for SCPs
end
Player Data Management:
SetPlayerData @plr "kills" 5
$kills = GetPlayerData @plr "kills"