Skip to content
Tomm edited this page Apr 7, 2019 · 3 revisions

What are timers?

Timers are a way to execute logic at specific intervals for players or npcs.

Why use timers?

Timers are an efficient way to handle logic that should occur for a player or npc after a specific amount of game cycles.

How do timers work?

Timers are made up of two parts:

  1. TimerKey
  2. TimerMap

TimerKeys are defined in your plugin file and the TimerMap is stored for each player and can be accessed via player.timers.

Example

package gg.rsmod.plugins.content.mechanics.poison

// If we want the timer to save on log-out, we specify a name 
// inside the TimerKey.
val NEXT_POISON_DMG = TimerKey()

// To test, we can create a short command to poison ourselves.
on_command("poisonme") {
    player.timers[NEXT_POISON_DMG] = 4 // Queue the timer to be invoked in 4 game cycles
}

on_timer(NEXT_POISON_DMG) {
    val damage = 4
    player.hit(damage)
    player.timers[NEXT_POISON_DMG] = 4 // Queue the timer to be invoked in 4 game cycles
}

Table of Contents

Clone this wiki locally