Skip to content

Game

Game Class

The Game class provides global functions for interacting with the game world. Unlike other classes, Game methods are called statically (e.g., Game.getPlayers()).

Player & Creature Access

MethodReturnsDescription
Game.getPlayers()tableAll online players
Game.getPlayerCount()numberOnline player count
Game.getMonsters()tableAll monsters
Game.getMonsterCount()numberMonster count
Game.getNpcs()tableAll NPCs
Game.getNpcCount()numberNPC count
Game.getSpectators(pos, multifloor, onlyPlayers, minX, maxX, minY, maxY)tableCreatures in area
-- Get all players
for _, player in ipairs(Game.getPlayers()) do
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Server message!")
end
-- Get spectators in 7x7 area
local spectators = Game.getSpectators(position, false, false, 3, 3, 3, 3)

Creation Functions

MethodReturnsDescription
Game.createItem(itemId, count, position)ItemCreate item on map
Game.createContainer(itemId, size, position)ContainerCreate container
Game.createMonster(name, position, extended, force)MonsterSpawn monster
Game.createNpc(name, position, extended, force)NpcSpawn NPC
Game.createTile(position, isDynamic)TileCreate map tile
Game.createMonsterType(name)MonsterTypeCreate monster type
-- Create item
local item = Game.createItem(2160, 10, Position(1000, 1000, 7))
-- Spawn monster
local monster = Game.createMonster("Dragon", Position(1000, 1000, 7), true, true)

Game State

MethodReturnsDescription
Game.getGameState()numberCurrent game state
Game.setGameState(state)-Set game state
Game.getWorldType()numberWorld type (PvP/no-PvP)
Game.setWorldType(type)-Set world type

Game States:

  • GAME_STATE_STARTUP (0)
  • GAME_STATE_INIT (1)
  • GAME_STATE_NORMAL (2)
  • GAME_STATE_CLOSED (3)
  • GAME_STATE_SHUTDOWN (4)
  • GAME_STATE_CLOSING (5)
  • GAME_STATE_MAINTAIN (6)

World Types:

  • WORLD_TYPE_NO_PVP (1)
  • WORLD_TYPE_PVP (2)
  • WORLD_TYPE_PVP_ENFORCED (3)

Data Access

MethodReturnsDescription
Game.getTowns()tableAll towns
Game.getHouses()tableAll houses
Game.getOutfits(sex)tableAvailable outfits
Game.getMounts()tableAvailable mounts
Game.getVocations()tableAll vocations
Game.getMonsterTypes()tableAll monster types
Game.getCurrencyItems()tableCurrency items
-- List all towns
for _, town in ipairs(Game.getTowns()) do
print(town:getName())
end

Experience & Level

MethodReturnsDescription
Game.getExperienceStage(level)numberExperience multiplier for level
Game.getExperienceForLevel(level)numberTotal exp needed for level
local expNeeded = Game.getExperienceForLevel(100)
print("Exp for level 100: " .. expNeeded)

Storage

MethodReturnsDescription
Game.getAccountStorageValue(accountId, key)numberAccount storage value
Game.setAccountStorageValue(accountId, key, value)-Set account storage
Game.saveAccountStorageValues()-Force save storage

Utility

MethodReturnsDescription
Game.getItemAttributeByName(name)numberItem attribute type
Game.getReturnMessage(returnValue)stringError message for return value
Game.getClientVersion()tableClient version info
Game.reload(reloadType)booleanReload game data
Game.startRaid(raidName)booleanStart a raid
Game.loadMap(path)-Load additional map

Reload Types:

  • RELOAD_TYPE_ALL
  • RELOAD_TYPE_ACTIONS
  • RELOAD_TYPE_MONSTERS
  • RELOAD_TYPE_NPCS
  • RELOAD_TYPE_SPELLS
  • etc.
-- Reload monsters
Game.reload(RELOAD_TYPE_MONSTERS)
-- Start raid
Game.startRaid("dragon_raid")

Discord Integration

MethodDescription
Game.sendDiscordMessage(webhookUrl, message)Send Discord webhook
Game.sendDiscordMessage(
"https://discord.com/api/webhooks/...",
"Server event started!"
)

Examples

Broadcast Message

local function broadcastMessage(message)
for _, player in ipairs(Game.getPlayers()) do
player:sendTextMessage(MESSAGE_STATUS_WARNING, message)
end
end

Find Player by Name

local function findPlayer(name)
for _, player in ipairs(Game.getPlayers()) do
if player:getName():lower() == name:lower() then
return player
end
end
return nil
end

Spawn Wave of Monsters

local function spawnWave(centerPos, monsterName, count, radius)
for i = 1, count do
local x = centerPos.x + math.random(-radius, radius)
local y = centerPos.y + math.random(-radius, radius)
Game.createMonster(monsterName, Position(x, y, centerPos.z), true, true)
end
end