-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Functions
createItem(itemId, count[, position])
createContainer(itemId, size[, position])
createMonster(monsterName, position, extended = false, force = false)
createNpc(npcName, position, extended = false, force = false)
createTile(x, y, z[, isDynamic = false])
createTile(position[, isDynamic = false])
getExperienceStage(level)
getGameState()
getHouses()
getMonsterCount()
getMonsterTypes()
getNpcCount()
getPlayerCount()
getPlayers()
getReturnMessage(value)
getSpectators(position, multifloor = false, onlyPlayer = false, minRangeX = 0, maxRangeX = 0, minRangeY = 0, maxRangeY = 0)
getTowns()
getWorldType()
loadMap(path)
setGameState(state)
setWorldType(type)
startRaid(raidName)
create(arrayLength, keyLength)
Description: Creates an item.
Parameters:Returns: The item created. (userdata)
- itemId - Id of the item to be created
- count - How many are we creating?
- position - Where do we place it? (optional)
Example:
-- Create an item somewhere on the map.
local item = Game.createItem(2400, 1, Position(100, 100, 7))
--
-- Create a temporary item that is given to a player (if it isn't moved from creation it will be deleted)
local player = Player(...)
player:addItemEx(Game.createItem(2400, 1))
[To the top] Added in version: 1.0
Description: Creates a container with given size.
Parameters:Returns: The container created. (userdata)
- itemId - Id of the item to be created
- size - Size of the container
- position - Where do we place it? (optional)
Example:
-- Create an amulet of loss as a container with size 5 at position: x 100, y 100, z 7.
local item = Game.createContainer(ITEM_AMULETOFLOSS, 5, Position(100, 100, 7))
--
-- Create a temporary container that is given to a player (if it isn't moved from creation it will be deleted)
local player = Player(...)
player:addItemEx(Game.createContainer(ITEM_AMULETOFLOSS, 5))
[To the top] Added in version: 1.1
Description: Creates a monster.
Parameters:Returns: The monster created. (userdata)
- monsterName - Name of the monster to be created
- position - Where do we place it?
- extended - Extend the range? (optional, default: false)
- force - Will it be created even if it cannot stand at the position? (optional, default: false)
Example:
-- This should always create this monster.
local monster = Game.createMonster("demon", Position(100, 100, 7), false, true)
if not monster then
-- Something went wrong?
end
[To the top] Added in version: 1.0
Description: Creates a npc.
Parameters:Returns: The npc created. (userdata)
- npcName - Name of the npc to be created
- position - Where do we place it?
- extended - Extend the range? (optional, default: false)
- force - Will it be created even if it cannot stand at the position? (optional, default: false)
Example:
-- This may possibly not create the npc.
local npc = Game.createMonster("some npc", Position(100, 100, 7), false, false)
if not npc then
-- Something is probably blocking that position and around it aswell
end
[To the top] Added in version: 1.0
Description: Creates a tile if it can.
Parameters:Returns: The tile created or the previous existing one. (userdata)
- x - X coordinate
- y - Y coordinate
- z - Z coordinate
- isDynamic - Is this tile dynamic? (optional, default: false)
Example:
local tile = Game.createTile(100, 100, 7)
local ground = tile:getGround()
if ground then
print(ground:getName())
end
[To the top] Added in version: 1.0
Description: Creates a tile if it can.
Parameters:Returns: The tile created or the previous existing one. (userdata)
- position - Location of the tile.
- isDynamic - Is this tile dynamic? (optional, default: false)
Example:
local tile = Game.createTile(Position(100, 100, 7))
local ground = tile:getGround()
if ground then
print(ground:getName())
end
[To the top] Added in version: 1.0
Description: Find the experience rate related to a certain level.
Parameters:Returns: The experience rate related to the specified level.
- level - Level to get the stage with.
Example:
-- Print the experience rate for level 8 to the console
print(Game.getExperienceStage(8))
[To the top] Added in version: 1.0
Description: Gets the current gamestate.
Parameters: None
Returns: Current gamestate on the server.
Example:
print(Game.getGameState())
[To the top] Added in version: 1.0
Description: Get all houses.
Parameters: None
Returns: A table containing all houses (userdata).
Example:
-- This prints the names of all houses that exist on the server
local houses = Game.getHouses()
for i = 1, #houses do
print(houses[i]:getName())
end
[To the top] Added in version: 1.0
Description: Find the total amount of monsters on the server.
Parameters: None
Returns: Total amount of monsters on the server.
Example:
print(Game.getMonsterCount())
[To the top] Added in version: 1.0
Description: List all loaded monster types on the server.
Parameters: None
Returns: List of monster types in the server.
Example:
for name, monstertype in pairs(Game.getMonsterTypes()) do
print(" - Name: " .. name
.. " - Health: " .. monstertype:getMaxHealth()
.. " - Armor: " .. monstertype:getArmor()
)
end
[To the top] Added in version: 1.3
Description: Find the total amount of npcs on the server.
Parameters: None
Returns: Total amount of npcs on the server.
Example:
print(Game.getNpcCount())
[To the top] Added in version: 1.0
Description: Find the total amount of players on the server.
Parameters: None
Returns: Total amount of players on the server.
Example:
print(Game.getPlayerCount())
[To the top] Added in version: 1.0
Description: Get all connected players.
Parameters: None
Returns: A table containing all connected players (userdata).
Example:
-- This prints the names of all players connected to the server
local players = Game.getPlayers()
for i = 1, #players do
print(players[i]:getName())
end
[To the top] Added in version: 1.0
Description: Gets a message associated with the value.
Parameters:Returns: true
- value - Internal return value
Example:
-- This makes no sense but its an example.
local player = Player(...)
player:say(Game.getReturnMessage(RETURNVALUE_YOUARENOTTHEOWNER), TALKTYPE_SAY)
[To the top] 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 around center position.
Parameters:Returns: A table containing creatures found (userdata).
- position - Center position
- multifloor - Search multiple floors? (optional, default: false)
- onlyPlayer - Find only players? (optional, default: false)
- minRangeX - Maximum range to the west in x axis (optional, default: 0)
- maxRangeX - Maximum range to the east in x axis (optional, default: 0)
- minRangeY - Maximum range to the north on the y axis (optional, default: 0)
- maxRangeY - Maximum range to the south on the y axis (optional, default: 0)
Example:
-- This finds all players in a 5x5 area around (100, 100, 7)
-- (98-102, 98-102, 7)
local spectators = Game.getSpectators(Position(100, 100, 7), false, true, 2, 2, 2, 2)
for i = 1, #spectators do
local spectator = spectators[i]
spectator:say(spectator:getName(), TALKTYPE_SAY)
end
[To the top] Added in version: 1.0
Description: Get all towns.
Parameters: None
Returns: A table containing all towns (userdata).
Example:
-- This prints the names of all towns that exist on the server
local towns = Game.getTowns()
for i = 1, #towns do
print(towns[i]:getName())
end
[To the top] Added in version: 1.0
Description: Gets the current world type.
Parameters: None
Returns: Current gamestate on the server.
Example:
print(Game.getWorldType())
[To the top] Added in version: 1.0
Description: This loads a new map chunk.
Parameters:Returns: Nothing
- path - File path to the map.
Example:
Game.loadMap("data/map/some_other_map.otbm")
[To the top] Added in version: 1.0
Description: Sets the current gamestate.
Parameters:Returns: true
- state - The new gamestate
Example:
-- Shutdown the server
Game.setGameState(GAME_STATE_SHUTDOWN)
[To the top] Added in version: 1.0
Description: Sets the current world type.
Parameters:Returns: true
- type - The new world type
Example:
-- Change to hardcore pvp
Game.setWorldType(WORLD_TYPE_PVP_ENFORCED)
[To the top] Added in version: 1.0
Description: Starts a raid if one with said name exist.
Parameters:Returns: true if the raid started, nil otherwise.
- raidName - Name of the raid.
Example:
if Game.startRaid("test") then
-- Raid was started.
end
[To the top] Added in version: 1.0
addEvent(callback, delay, ...)
stopEvent(eventid)
Description: This function is used to run other functions at a later time.
Parameters:Returns: The id associated with this event.
- callback - The function that should run at a later time.
- delay - Time before the callback runs in milliseconds.
- ... - This can expand into any amount of variables, they are sent to the callback when it runs. (optional)
Example:
-- Creates an event that prints "Hello World!" to the console.
addEvent(print, 1000, "Hello World!")
[To the top] Added in version: 1.0
Description: This function is used to stop functions that should run later.
Parameters:Returns: true if an event was stopped, false otherwise.
- eventid - The event id to stop.
Example:
-- Creates an event that should print "Hello World!" but it's stopped before that can happen.
local event = addEvent(print, 1000, "Hello World!")
stopEvent(event)
[To the top] Added in version: 1.0
Description: Returns the Unix time (epoch) in milliseconds
Parameters: None
Returns: The Unix time (epoch) in milliseconds
Example:
print(os.mtime() .. " milliseconds have passed since the Unix epoch")
[To the top] Added in version: 1.0
Description: Creates a new table with specified length.
Parameters:Returns: The created table.
- arrayLength - Ordered indexes (1, 2, ...arrayLength)
- keyLength - Unordered indexes (anything that does not follow the above)
Example:
local t = table.create(5, 0)
for i = 1, #t do
t[i] = i + 1
end
[To the top] Added in version: 1.0