Functions - RodrigoOt/forgottenserver GitHub Wiki
###Game
####Available methods:
[createItem(itemId, count[, position])](#Game.createItem{itemId, count[, position]})
[createContainer(itemId, size[, position])](#Game.createContainer{itemId, size[, position]})
[createMonster(monsterName, position[, extended = false[, force = false]])](#Game.createMonster{monsterName, position[, extended = false[, force = false]]})
[createNpc(npcName, position[, extended = false[, force = false]])](#Game.createNpc{npcName, position[, extended = false[, force = false]]})
[createTile(x, y, z[, isDynamic = false])](#Game.createTile{x, y, z[, isDynamic = false]})
[createTile(position[, isDynamic = false])](#Game.createTile{position[, isDynamic = false]})
getExperienceStage(level)
getGameState()
getHouses()
getMonsterCount()
getNpcCount()
getPlayerCount()
getPlayers()
getReturnMessage(value)
[getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])](#Game.getSpectators{position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]]})
getTowns()
getWorldType()
loadMap(path)
setGameState(state)
setWorldType(type)
startRaid(raidName)
###### Game.createItem(itemId, count[, position]) > **Description:** Creates an item. > **Parameters:**
- _itemId_ - _Id of the item to be created_
- _count_ - _How many are we creating?_
- _position_ - _Where do we place it? (optional)_
###### Game.createContainer(itemId, size[, position]) > **Description:** Creates a container with given size. > **Parameters:**
- _itemId_ - _Id of the item to be created_
- _size_ - _Size of the container_
- _position_ - _Where do we place it? (optional)_
###### Game.createMonster(monsterName, position[, extended = false[, force = false]]) > **Description:** Creates a monster. > **Parameters:**
- _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)_
###### Game.createNpc(npcName, position[, extended = false[, force = false]]) > **Description:** Creates a npc. > **Parameters:**
- _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)_
###### Game.createTile(x, y, z[, isDynamic = false]) > **Description:** Creates a tile if it can. > **Parameters:**
- _x_ - _X coordinate_
- _y_ - _Y coordinate_
- _z_ - _Z coordinate_
- _isDynamic_ - _Is this tile dynamic? (optional, default: false)_
###### Game.createTile(position[, isDynamic = false]) > **Description:** Creates a tile if it can. > **Parameters:**
- _position_ - _Location of the tile._
- _isDynamic_ - _Is this tile dynamic? (optional, default: false)_
###### Game.getExperienceStage(level) > **Description:** Find the experience rate related to a certain level. > **Parameters:**
- _level_ - _Level to get the stage with._
###### Game.getGameState() > **Description:** Gets the current gamestate. > **Parameters:** None > **Returns:** Current gamestate on the server. > **Example:** ```Lua print(Game.getGameState()) ``` > **Added in version:** 1.0
###### Game.getHouses() > **Description:** Get all houses. > **Parameters:** None > **Returns:** A table containing all houses (userdata). > **Example:** ```Lua -- 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 ``` > **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:** ```Lua print(Game.getMonsterCount()) ``` > **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:** ```Lua print(Game.getNpcCount()) ``` > **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:** ```Lua print(Game.getPlayerCount()) ``` > **Added in version:** 1.0
###### Game.getPlayers() > **Description:** Get all connected players. > **Parameters:** None > **Returns:** A table containing all connected players (userdata). > **Example:** ```Lua -- 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 ``` > **Added in version:** 1.0
###### Game.getReturnMessage(value) > **Description:** Gets a message associated with the value. > **Parameters:**
- _value_ - _Internal return value_
###### Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]]) > **Description:** Get all creatures in the area. > **Parameters:**
- _position_ - _Center position_
- _multifloor_ - _Search multiple floors? (optional, default: false)_
- _onlyPlayer_ - _Find only players? (optional, default: false)_
- _minRangeX_ - _Minimum range on the x axis (optional, default: 0)_
- _maxRangeX_ - _Maximum range on the x axis (optional, default: 0)_
- _minRangeY_ - _Minimum range on the y axis (optional, default: 0)_
- _maxRangeY_ - _Maximum range on the y axis (optional, default: 0)_
###### Game.getTowns() > **Description:** Get all towns. > **Parameters:** None > **Returns:** A table containing all towns (userdata). > **Example:** ```Lua -- 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 ``` > **Added in version:** 1.0
###### Game.getWorldType() > **Description:** Gets the current world type. > **Parameters:** None > **Returns:** Current gamestate on the server. > **Example:** ```Lua print(Game.getWorldType()) ``` > **Added in version:** 1.0
###### Game.loadMap(path) > **Description:** This loads a new map chunk. > **Parameters:**
- _path_ - _File path to the map._
###### Game.setGameState(state) > **Description:** Sets the current gamestate. > **Parameters:**
- _state_ - _The new gamestate_
###### Game.setWorldType(type) > **Description:** Sets the current world type. > **Parameters:**
- _type_ - _The new world type_
###### Game.startRaid(raidName) > **Description:** Starts a raid if one with said name exist. > **Parameters:**
- _raidName_ - _Name of the raid._
###Global
####Available methods:
[addEvent(callback, delay, ...)](#addEvent{callback, delay, ...})
stopEvent(eventid)
###### addEvent(callback, delay, ...) > **Description:** This function is used to run other functions at a later time. > **Parameters:**
- _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)_
###### stopEvent(eventid) > **Description:** This function is used to stop functions that should run later. > **Parameters:**
- _eventid_ - _The event id to stop._
###os ####Available methods: mtime()
###### os.mtime() > **Description:** Returns the Unix time (epoch) in milliseconds > **Parameters:** None > **Returns:** The Unix time (epoch) in milliseconds > **Example:** ```Lua print(os.mtime() .. " milliseconds have passed since the Unix epoch") ``` > **Added in version:** 1.0
###table ####Available methods: [create(arrayLength, keyLength)](#table.create{arrayLength, keyLength})
###### table.create(arrayLength, keyLength) > **Description:** Creates a new table with specified length. > **Parameters:**
- _arrayLength_ - _Ordered indexes (1, 2, ...arrayLength)_
- _keyLength_ - _Unordered indexes (anything that does not follow the above)_