Skip to content
ItsDeltin edited this page Mar 7, 2023 · 3 revisions

Rules

Rules are the base of the workshop and all OSTW code. Any code that runs originates from a rule.


There are several different event types that causes the rule to activate at different times.

Some functions can only be executing depending on the event type. Player-context events such as OngoingPlayer and DamageTaken can access EventPlayer, while global rules cannot. Variables defined in an ongoing global rule will be stored as a global variable. Variables defined in a player-context event rule will be stored as a player variable.

There are 11 different event types:

Event Name Player context Assault context Heal context
OngoingGlobal No No No
OngoingPlayer Yes No No
OnElimination Yes Yes No
OnFinalBlow Yes Yes No
OnDamageDealt Yes Yes No
OnDamageTaken Yes Yes No
OnDeath Yes Yes No
OnHealingDealt Yes No Yes
OnHealingTaken Yes No Yes
OnPlayerJoin Yes No No
OnPlayerLeave Yes No No

In the workshop, there is a 12th event type called subroutines. See subroutines for more information.


A rule with no event type will be global by default.

rule: "My rule"
{
    define a = 5;
}

To set the event type, add the event enumerator right after the rule name is defined, and before the conditions.

rule: "A player rule!"
Event.OngoingPlayer
{
    define a = 5;
}

To add conditions, add an if statement before the rule's block.

rule: "Kill when touching the ground."
if (!inSafeZone)
if (IsOnGround(EventPlayer()))
{
    Kill(EventPlayer());
}

Ordering rules

In some cases, the order the rules matter. When multiple rules' conditions become true on the same frame, the rules will execute from top to bottom. By default, rules are printed in the order they are defined. However, this may be hard to track when you start importing files. To order rules, simply add a number after the rule's name. The rules will be ordered from the lowest to greatest number. By default, all rules have a sort order of 0. So 1 will put the rule after all other rules, and -1 will put it before.

rule: "Disable inspector" -1
{
    // Disabling the inspector can improve server load.
    DisableInspectorRecording();
}

OSTW will internally add rules. If there are any rule-level or static variables that have an initial value, a rule called Initial Global or Initial Player will be created, depending on the context of the variable. Pathfinding will also add rules. All internally added rules have a sort order of 0, but Initial Global and Initial Player takes precedence over other rules with a sort order of 0.