Refcount

From EventScripts Community Encyclopedia

Contents

Overview

Syntax: refcount <command>
Note: Command parameters are described inside the < and > characters. Optional parameters are contained within [ and ] characters.

Description

Increase, decrease or get the reference count for a variable.

by Wonder


Note: It doesn't expand server variables. Prefix the command with es to expand variables (es refcount).

Parameters

  • command - To increase the reference count:
refcount increment <var> [silent]

To decrease the reference count:

refcount decrement <var> [silent]

To get the reference count and/or put it inside a variable:

refcount count [return var] <var>


Examples

event player_say
{
  // Let's end the current round.
  if (event_var(text) == endtheround) do
  {
    // Increase the reference count silenty.
    // This is so clients cannot take advantage that it was enabled.
    refcount increment sv_cheats 1
    // Now end the round.
    endround
    // Now decrease the reference count again silently.
    refcount decrement sv_cheats 1
  }
  else do
  {
    // Let's get the reference count of sv_cheats.
    if (event_var(text) == countcheats) do
    {
      // Create a variable to hold the reference count.
      es_setinfo cheatcount 0
      // Get the reference count of sv_cheats and put it inside cheatcount.
      refcount count cheatcount sv_cheats
      // Tell the user the reference count.
      es_tell event_var(userid) The reference count for sv_cheats is: server_var(cheatcount)
    }
  }
}

Notes

  • refcount is available in EventScripts v1.3 and later.
  • It is a good idea to use refcount to enable toggle variables when you will disable them later.
  • Make sure to call refcount decrement when you no longer need the variable enabled.

See Also

blog comments powered by Disqus