Lua functions

Game

Available methods:

Game.broadcastMessage(message, messageType)

Description: Send message to all players Parameters: Returns: Nothing Example:
1
local message = 'Hello'
2
local messageType = MESSAGE_STATUS_DEFAULT
3
Game.broadcastMessage(message, messageType)
Copied!
Added in version: 1.0

Game.convertIpToString(ip)

Description: Convert numeric representation of IPv4 to string with dot separated octets Parameters: Returns: String Example:
1
function Player:onLook(thing, position, distance)
2
if thing:isCreature() then
3
if thing:isPlayer() then
4
local playerIp = thing:getIp()
5
local ip = Game.convertIpToString(playerIp)
6
local description = string.format("IP: [%s].", ip)
7
end
8
end
9
self:sendTextMessage(MESSAGE_INFO_DESCR, description)
10
return true
11
end
Copied!
Added in version: 1.0

Game.createItem(itemId, count[, position])

Description: Creates an item. Parameters: Returns: The item created. (userdata) Example:
1
-- Create an item somewhere on the map.
2
local item = Game.createItem(2400, 1, Position(100, 100, 7))
3
--
4
-- Create a temporary item that is given to a player (if it isn't moved from creation it will be deleted)
5
local player = Player(...)
6
player:addItemEx(Game.createItem(2400, 1))
Copied!
Added in version: 1.0

Game.createContainer(itemId, size[, position])

Description: Creates a container with given size. Parameters: Returns: The container created. (userdata) Example:
1
-- Create an amulet of loss as a container with size 5 at position: x 100, y 100, z 7.
2
local item = Game.createContainer(ITEM_AMULETOFLOSS, 5, Position(100, 100, 7))
3
--
4
-- Create a temporary container that is given to a player (if it isn't moved from creation it will be deleted)
5
local player = Player(...)
6
player:addItemEx(Game.createContainer(ITEM_AMULETOFLOSS, 5))
Copied!
Added in version: 1.1

Game.createMonster(monsterName, position[, extended = false[, force = false]])

Description: Creates a monster. Parameters: Returns: The monster created. (userdata) Example:
1
-- This should always create this monster.
2
local monster = Game.createMonster("demon", Position(100, 100, 7), false, true)
3
if not monster then
4
-- Something went wrong?
5
end
Copied!
Added in version: 1.0

Game.createNpc(npcName, position[, extended = false[, force = false]])

Description: Creates a npc. Parameters: Returns: The npc created. (userdata) Example:
1
-- This may possibly not create the npc.
2
local npc = Game.createMonster("some npc", Position(100, 100, 7), false, false)
3
if not npc then
4
-- Something is probably blocking that position and around it aswell
5
end
Copied!
Added in version: 1.0

Game.createTile(x, y, z[, isDynamic = false])

Description: Creates a tile if it can. Parameters: Returns: The tile created or the previous existing one. (userdata) Example:
1
local tile = Game.createTile(100, 100, 7)
2
local ground = tile:getGround()
3
if ground then
4
print(ground:getName())
5
end
Copied!
Added in version: 1.0

Game.createTile(position[, isDynamic = false])

Description: Creates a tile if it can. Parameters: Returns: The tile created or the previous existing one. (userdata) Example:
1
local tile = Game.createTile(Position(100, 100, 7))
2
local ground = tile:getGround()
3
if ground then
4
print(ground:getName())
5
end
Copied!
Added in version: 1.0

Game.getExperienceStage(level)

Description: Find the experience rate related to a certain level. Parameters: Returns: The experience rate related to the specified level. Example:
1
-- Print the experience rate for level 8 to the console
2
print(Game.getExperienceStage(8))
Copied!
Added in version: 1.0

Game.getGameState()

Description: Gets the current gamestate. Parameters: None Returns: Current gamestate on the server. Example:
1
print(Game.getGameState())
Copied!
Added in version: 1.0

Game.getHouses()

Description: Get all houses. Parameters: None Returns: A table containing all houses (userdata). Example:
1
-- This prints the names of all houses that exist on the server
2
local houses = Game.getHouses()
3
for i = 1, #houses do
4
print(houses[i]:getName())
5
end
Copied!
Added in version: 1.0

Game.getMonsterCount()

Description: Find the total amount of monsters on the server. Parameters: None Returns: Total amount of monsters on the server. Example:
1
print(Game.getMonsterCount())
Copied!
Added in version: 1.0

Game.getNpcCount()

Description: Find the total amount of npcs on the server. Parameters: None Returns: Total amount of npcs on the server. Example:
1
print(Game.getNpcCount())
Copied!
Added in version: 1.0

Game.getPlayerCount()

Description: Find the total amount of players on the server. Parameters: None Returns: Total amount of players on the server. Example:
1
print(Game.getPlayerCount())
Copied!
Added in version: 1.0

Game.getPlayers()

Description: Get all connected players. Parameters: None Returns: A table containing all connected players (userdata). Example:
1
-- This prints the names of all players connected to the server
2
local players = Game.getPlayers()
3
for i = 1, #players do
4
print(players[i]:getName())
5
end
Copied!
Added in version: 1.0

Game.getReturnMessage(value)

Description: Gets a message associated with the value. Parameters: Returns: true Example:
1
-- This makes no sense but its an example.
2
local player = Player(...)
3
player:say(Game.getReturnMessage(RETURNVALUE_YOUARENOTTHEOWNER), TALKTYPE_SAY)
Copied!
Added in version: 1.0

Game.getReverseDirection(direction)

Description: Gets reversed direction. Parameters: Returns: Direction (integer) Example:
1
local direction = DIRECTION_NORTH
2
local reversedDirection = Game.getReverseDirection(direction)
3
print('Numerical value of SOUTH direction is equel '.. tostring(reversedDirection))
Copied!
Added in version: 1.0

Game.getSkillType(weaponType)

Description: Gets skill type associatet with weapon type. Parameters: Returns: Skill type (integer) Example:
1
local itemtype = ItemType(...)
2
local weaponType = itemtype:getWeaponType()
3
local skillType = Game.getSkillType(weaponType)
Copied!
Added in version: 1.0

Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])

Description: Get all creatures in the area. Parameters: Returns: A table containing creatures found (userdata). Example:
1
-- This finds all players in a 5x5 area around (100, 100, 7)
2
local spectators = Game.getSpectators(Position(100, 100, 7), false, true, 0, 2, 0, 2)
3
for i = 1, #spectators do
4
local spectator = spectators[i]
5
spectator:say(spectator:getName(), TALKTYPE_SAY)
6
end
Copied!
Added in version: 1.0

Game.getStorageValue(key)

Description: Get value from globalStorageTable Parameters: Returns: Value from table on empty index nil value Example:
1
local storage = Game.getStorageValue(1)
2
print(tostring(storage))
Copied!
Added in version: 1.0

Game.getTowns()

Description: Get all towns. Parameters: None Returns: A table containing all towns (userdata). Example:
1
-- This prints the names of all towns that exist on the server
2
local towns = Game.getTowns()
3
for i = 1, #towns do
4
print(towns[i]:getName())
5
end
Copied!
Added in version: 1.0

Game.getWorldType()

Description: Gets the current world type. Parameters: None Returns: Current gamestate on the server. Example:
1
print(Game.getWorldType())
Copied!
Added in version: 1.0

Game.loadMap(path)

Description: This loads a new map chunk. Parameters: Returns: Nothing Example:
1
Game.loadMap("data/map/some_other_map.otbm")
Copied!
Added in version: 1.0

Game.setGameState(state)

Description: Sets the current gamestate. Parameters: Returns: true Example:
1
-- Shutdown the server
2
Game.setGameState(GAME_STATE_SHUTDOWN)
Copied!
Added in version: 1.0

Game.setStorageValue(key, value)

Description: Insert value into globalStorageTable on specific key Parameters: Returns: Nothing Example:
1
Game.setStorageValue(1, 1000)
Copied!
Added in version: 1.0

Game.setWorldType(type)

Description: Sets the current world type. Parameters: Returns: true Example:
1
-- Change to hardcore pvp
2
Game.setWorldType(WORLD_TYPE_PVP_ENFORCED)
Copied!
Added in version: 1.0

Game.startRaid(raidName)

Description: Starts a raid if one with said name exist. Parameters: Returns: true if the raid started, nil otherwise. Example:
1
if Game.startRaid("test") then
2
-- Raid was started.
3
end
Copied!
Added in version: 1.0

Global

Available methods:

addEvent(callback, delay, ...)

Description: This function is used to run other functions at a later time. Parameters: Returns: The id associated with this event. Example:
1
-- Creates an event that prints "Hello World!" to the console.
2
addEvent(print, 1000, "Hello World!")
Copied!
Added in version: 1.0

stopEvent(eventid)

Description: This function is used to stop functions that should run later. Parameters: Returns: true if an event was stopped, false otherwise. Example:
1
-- Creates an event that should print "Hello World!" but it's stopped before that can happen.
2
local event = addEvent(print, 1000, "Hello World!")
3
stopEvent(event)
Copied!
Added in version: 1.0

os

Available methods:

mtime()

os.mtime()

Description: Returns the Unix time (epoch) in milliseconds Parameters: None Returns: The Unix time (epoch) in milliseconds Example:
1
print(os.mtime() .. " milliseconds have passed since the Unix epoch")
Copied!
Added in version: 1.0

table

Available methods:

table.create(arrayLength, keyLength)

Description: Creates a new table with specified length. Parameters: Returns: The created table. Example:
1
local t = table.create(5, 0)
2
for i = 1, #t do
3
t[i] = i + 1
4
end
Copied!
Added in version: 1.0
Last modified 1yr ago