Trigger Logic

Introduction

Triggers offer a non-scripting solution to creating game logic. Triggers interact with each other using interface IDs. Think of it like walkie-talkies that communicate on a certain frequency.

Trigger Events

Events allow you to listen for game events and trigger specific actions accordingly:

IDEventDescription
0onShootFires when a player shoots the trigger object.
1onMeleeFires when a player melees the trigger object.
2onDamageFires when the trigger object takes damage in any way.
3onEnterObjectFires when a player enters the trigger object.
4onDestroyFires when the trigger object is destroyed.
5onRespawnFires when the trigger object respawns.
6onTimerFires when the trigger object's timer runs out.
7onProjectileFires on the configured projectile event.
8onThrowingMeleeFires when a melee weapon is thrown.
9onPunchFires when a player punches the trigger object.
10onHoldMouseFires when a player holds the mouse button on the trigger object.
11onCollisionFires on collision with the trigger object.
12onStorageEqualsFires when interface storage equals a specific value.
13onStorageGreaterFires when interface storage is greater than a specific value.
14onStorageLesserFires when interface storage is less than a specific value.
15onAIDeathFires when an AI dies.
16onInteractKeyFires when a player presses the interact key.
17onPlayerSpawnFires when a player spawns in the game.
18onPlayerKillFires when a player gets a kill.
19onPlayerDieFires when a player dies.
20onAIDamageFires when an AI takes damage.
21onNukeStartFires when a nuke starts.
22onNukeEndFires when a nuke ends.
23onExitObjectFires when a player exits the trigger object.
24onCustomValEqualsFires when a custom value equals a specific value.
25onCustomValLesserFires when a custom value is less than a specific value.
26onGameStartFires when the game starts.
27onObjectiveSwitchFires when the objective switches (e.g. Hardpoint).
28onPlayerDamageFires when a player takes damage.
29onAIHalfHealthFires when an AI reaches half health.
30onCustomValGreaterFires when a custom value is greater than a specific value.
31onAIKillPlayerFires when an AI kills a player.

Trigger Conditions

Conditions allow you to execute an action only if a certain condition is met, similar to if statements in KrunkScript:

IDConditionDescriptionParameters
0NoneNo condition required for the action to execute.-
1Player ValueRequires a specific player value for the action to execute.Key (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Type (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Val
2Current ClassRequires the player to be using a specific class.Class
3Trigger ValueRequires the trigger value to match a specific amount.Key (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Type (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Val
4Player CountRequires a specific player count to be met.Type (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Filter (Active, Spectating, Overall Connected); Amount
5Global ValueRequires a specific global value to be met.Key (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Type (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Val
6Player has AccountRequires the player to have a registered Krunker account.-
7Player has PremiumRequires the player to be subscribed to Krunker Premium.-
8Player is VerifiedRequires the player to have verification status.-
9Player is PartnerRequires the player to have partner status.-
10Player LevelRequires the player to be at a specific level.Type (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Level
11Player Inventory ValueRequires the player's inventory value to meet a condition.Type (Equal, Not Equal, Greater than, Greater or Equal, Less than, Less or Equal); Val
12Custom ActionCalls a custom KrunkScript function to check the condition.Custom Param

Trigger Actions

Execute actions to interact with the game and players:

IDActionDescription
0Give Player ScoreGives the player a specified amount of score.
1Kill PlayerKills the player.
2Respawn PlayerRespawns the player.
3Change Player HealthAdjusts the player's health by a specified amount.
4Destroy InterfaceDestroys the target interface.
5Toggle Interface GateToggles the target interface gate open or closed.
6Change Interface HealthChanges the health of the target interface.
7Teleport Player To InterfaceTeleports the player to the target interface.
8Change Interface Deposit Box AmountChanges the deposit box amount of the target interface.
9Kill Opposing TeamKills all players on the opposing team.
10Respawn Opposing TeamRespawns all players on the opposing team.
11Respawn Destructible InterfaceRespawns the target destructible interface.
12Toggle Destructible InterfaceToggles the target destructible interface between destroyed and active.
13Set Player ScoreSets the player's score to a specific value.
14Broadcast SoundPlays a sound for all players in the game.
15Clear Player LoadoutClears the player's weapon loadout.
16Broadcast MessageSends a chat message to all players in the lobby.
17Send MessageSends a chat message to the triggering player only.
18Swap Player TeamSwaps the player to the opposing team.
19Set Player TeamSets the player to a specific team.
20Round TimeAdjusts the round timer by a specified amount.
21Reset InterfaceCompletely resets the target interface to its original state.
22End RoundEnds the current round.
23Refill Player KnifeRefills the player's throwable knife.
24Destroy SelfDestroys the trigger object itself.
25Increase Interface StorageIncreases the target interface storage by a specified amount.
26Decrease Interface StorageDecreases the target interface storage by a specified amount.
27Set Interface StorageSets the target interface storage to a specific value.
28Reset Interface StorageResets the target interface storage to zero.
29Broadcast PopupSends a popup message to all players in the lobby.
30Send PopupSends a popup message to the triggering player only.
31Jump ScareDisplays a jump scare effect to the player.
32Reward KRRewards the player with a specified amount of KR.
33Clear Player CheckpointsClears all of the player's checkpoints.
34Send SoundPlays a sound for the triggering player only.
35ExplosionCreates an explosion at the trigger object's position.
36Spawn AISpawns AI bots at their configured positions.
37Set Player ValueSets a custom player value to a specific number.
38Inc/Dec Player ValueIncreases or decreases a custom player value by a specified amount.
39Play AnimationPlays a specified animation on AIs or interface objects.
40Teleport Player to Path NodeTeleports the player to a specified path node.
41Teleport Destructible Interface to Path NodeTeleports the target destructible interface to a specified path node.
42Reset Destructible Interface PositionResets the destructible interface to its original position.
43Set Interface Trigger ValueSets a custom value on the target interface trigger.
44Inc/Dec Interface Trigger ValueIncreases or decreases a custom value on the target interface trigger.
45Set Trigger Value (Self)Sets a custom value on the trigger object itself.
46Inc/Dec Trigger Value (Self)Increases or decreases a custom value on the trigger object itself.
47Change ClassChanges the player's class.
48Set Interface Deposit Box AmountSets the deposit box amount of the target interface.
49Save DataSaves player data to persistent storage.
50Change Primary WeaponChanges the player's primary weapon.
51Change Secondary WeaponChanges the player's secondary weapon.
52Set Global ValueSets a global value visible to the entire lobby.
53Change Global ValueChanges a global value visible to the entire lobby.
54Stop SoundStops a currently playing sound.
55Show/Hide GUI Element (All)Shows or hides a GUI element for all players.
56Show/Hide GUI Element (Player)Shows or hides a GUI element for the triggering player only.
57Load DataLoads the player's saved data from persistent storage.
58Custom ActionExecutes a custom KrunkScript action with optional parameters.
61Change Ambient SoundChanges the game's ambient sound.
63Play Animation (Self)Plays a custom animation on the trigger object itself.
64Give EffectGives the player a selected status effect.
66Give Random EffectGives the player a random status effect.
67Play Video AdPlays a full-screen video ad for the player.
69Force AI TargetForces all AI to target the trigger object's position.
70Mode SpecificExecutes a game mode-specific trigger action.

Triggers & Scripts

Triggers and scripts can interact with each other. You can call a KrunkScript action from a Trigger Event using Custom Action (58).

When this action executes, it automatically calls the onCustomTrigger hook in the server script:

# server-side hook called by Custom Action trigger
public action onCustomTrigger(str playerID, str customParam, num value) {
    # playerID - automatically passed in
    # customParam - custom string from the trigger
    # value - custom number from the trigger
}