Skip to content

Global Utility Functions

LogAdd(color, message)

Writes a message to the GameServer console and log file.

  • Parameters: color (number) — log color constant; message (string) — text to log.
  • Returns: nil
LogAdd(LOG_BLUE, "Custom event started successfully.")

GetTickCount()

Returns the number of milliseconds since system start. Useful for measuring time intervals.

  • Returns: number
local start = GetTickCount()
-- ... do work ...
LogAdd(LOG_GREEN, "Took " .. (GetTickCount() - start) .. " ms.")

GetLargeRand(value)

Generates a high-quality random integer in the range [0, value-1].

  • Parameters: value (number) — exclusive upper bound.
  • Returns: number
local roll = GetLargeRand(100) -- 0 to 99

rand(value)

Standard random integer in the range [0, value-1].

  • Parameters: value (number) — exclusive upper bound.
  • Returns: number
if rand(10) < 3 then
    LogAdd(LOG_GREEN, "30% chance triggered!")
end

Object Limit Constants

These functions return compile-time constants defining object index ranges.

Function Description
MAX_OBJECT_MONSTER() Maximum number of monsters
MAX_OBJECT_USER() Maximum number of players
MAX_OBJECT_SUMMON() Maximum number of summons
MAX_OBJECT() Total object slots
OBJECT_START_MONSTER() First monster index
OBJECT_START_USER() First player index
LogAdd(LOG_BLUE, "Max players: " .. MAX_OBJECT_USER())

Object Range Checks

Function Returns true if...
OBJECT_RANGE(index) Index is valid for any object
OBJECT_MONSTER_RANGE(index) Index is a monster
OBJECT_SUMMON_RANGE(index) Index is a summon
OBJECT_USER_RANGE(index) Index is a player
if OBJECT_USER_RANGE(aIndex) then
    LogAdd(LOG_GREEN, "Index " .. aIndex .. " is a player.")
end

Bit Manipulation

Used primarily for network packet construction.

Function Description
SET_NUMBERHB(value) High byte of a WORD
SET_NUMBERLB(value) Low byte of a WORD
SET_NUMBERHW(value) High word of a DWORD
SET_NUMBERLW(value) Low word of a DWORD
SET_NUMBERHDW(value) High dword of a QWORD
SET_NUMBERLDW(value) Low dword of a QWORD
local hi = SET_NUMBERHB(0x1234) -- 0x12
local lo = SET_NUMBERLB(0x1234) -- 0x34

GetLevelExperience(level)

Returns the total experience required to reach the given character level.

  • Parameters: level (number)
  • Returns: number
local exp = GetLevelExperience(400)
LogAdd(LOG_BLUE, "Exp for level 400: " .. exp)

GetMasterLevelExp(level)

Returns the total experience required to reach the given Master Level.

  • Parameters: level (number)
  • Returns: number
local mlExp = GetMasterLevelExp(200)

GetCrywolfState()

Returns the current Crywolf event state (0=Inactive, 1=Notification, 2=Active).

  • Returns: number
if GetCrywolfState() == 2 then
    LogAdd(LOG_RED, "Crywolf battle is in progress!")
end