Skip to content

LuaAPI All Functions

itvnnnd87 edited this page Oct 24, 2026 · 1 revision

All functions

Every function of the TSWMU LuaAPI on one page. Click a name to see its arguments, details and an example.

307 functions.

Characters and coins (112)

Function What it does
Player.IsOnline true if aIndex is a character that is in game.
Player.IsOffline true if the character is in offline mode (off-attack / off-store): it stays in game but nobody is playing it.
Player.GetName Character name.
Player.GetAccount Account name (login) of the character.
Player.GetAccountID Account ID number in the database.
Player.GetCharacterID Character ID number in the database.
Player.GetIndexByName aIndex of the in-game character with this name (upper / lower case does not matter).
Player.GetClass Character class, one of the CLASS_* constants (CLASS_DW, CLASS_DK, CLASS_FE ...).
Player.GetDBClass Class value stored in the database.
Player.GetEvolution Number of class evolutions done, from 0 (none) to 3.
Player.GetVIP VIP level of the account.
Player.GetVIPExpire Time when the VIP ends, as a Unix timestamp (seconds, same unit as os.time()).
Player.GetAuthority Authority value of the character (the value that marks normal players and GMs).
Player.IsGameMaster true for a GM character whose GM rights are switched on (.auth).
Player.HasAdminFlag true if the character is a GM and has the admin right flag.
Player.GetCodePage Code page of the player's client, which tells the client language.
Player.GetIP IP address of the player.
Player.GetMac MAC address sent by the player's client.
Player.GetDiskSerial Serial number of the player's disk, as a number.
Player.GetHardwareId Machine ID: MAC address and disk serial (8 hex digits) joined by -.
Player.GetLevel Normal level of the character.
Player.GetMasterLevel Master level of the character (0 if not a master yet).
Player.GetMajesticLevel Majestic level of the character.
Player.GetTotalLevel Normal + Master + Majestic level.
Player.GetLevelUpPoint Unspent stat points (normal level).
Player.GetMasterPoint Unspent Master skill tree points.
Player.GetMajesticPoint Unspent Majestic skill tree points.
Player.GetUsedMasterPoints Points spent in the Master skill tree (sum of the levels of all Master skills).
Player.GetExperience Current experience.
Player.GetNextExperience Experience needed for the next level.
Player.GetLastGainedExp Amount of the last experience the character received.
Player.GetReset Reset count of the character.
Player.GetStat Base stat (the points the character has put in).
Player.GetAddStat Stat added by items, buffs and other bonuses.
Player.GetTotalStat Base stat + added stat.
Player.GetDefaultStat Starting value of the stat for the character's class.
Player.GetMoney Zen in the inventory.
Player.GetRuud Ruud of the character.
Player.GetTradeZen Zen the character has placed in the open trade window, 0 if no trade is open.
Player.GetPKCount Kill count used for the PK status.
Player.GetPKLevel PK level, 0..6: 3 is normal, values above 3 are murderer levels (6 = murderer level 3), values below 3 are hero levels.
Player.GetPKTimer PK points left: how much the character still has to "pay" before the PK status ends.
Player.GetPKTotalCount Total number of players this character has killed (statistics, does not go down).
Player.GetMuteTime Seconds of chat ban left, 0 if the character is not muted.
Player.GetPartyNumber Party number, -1 if the character is not in a party.
Player.GetGuildNumber Guild number, 0 if the character has no guild.
Player.GetGuildName Guild name, "" if the character has no guild.
Player.GetGuildStatus Rank in the guild: 128 guild master, 64 assistant, 32 battle master, 0 member, -1 no guild.
Player.GetGuildUnionNumber Alliance number of the character's guild, 0 if no guild or no alliance.
Player.GetGuildUnionName Name of the alliance (the alliance master guild), "" if none.
Player.GetGuildRelationship Guild relationship between two characters: 0 none, 1 alliance, 2 rival, 4 alliance master, 8 rival master.
Player.GetGensFamily Gens family: 0 none, 1 Duprian, 2 Vanert.
Player.GetGensRank Gens ranking position.
Player.GetGensSymbol Gens symbol level (the badge level).
Player.GetGensContribution Gens contribution points.
Player.GetCastleSiegeSide Castle Siege side: 0 none, 1 defense, 2 or more attack sides.
Player.GetQuestState State of a class-change quest: 0 not started, 1 accepted, 2 complete, 3 cleared, 255 when the quest does not exist or the character has no data for it.
Player.GetSkin Transformation (monster class the character looks like), -1 if none.
Player.GetInterface Name of the window the character has open, "interface_none" if no window is open (for example "interface_shop", "interface_warehouse", "interface_chaos_machine").
Player.GetAccumulatedDamage Damage counter the server uses to wear down weapon durability.
Player.GetDeathLocation Place of the last death in this login session: 3 numbers.
Player.GetItem Item in an inventory slot (equipment slots included), as an item table (Item functions).
Player.IsActionBlocked true if the action is blocked by Player.BlockAction.
Player.SetLevel Sets the normal level (1 to the server maximum).
Player.SetMasterLevel Sets the Master level (0 to the server maximum).
Player.SetMajesticLevel Sets the Majestic level (0 to the server maximum).
Player.SetLevelUpPoint Sets the unspent stat points.
Player.SetMasterPoint Sets the unspent Master points and updates the client.
Player.SetMajesticPoint Sets the unspent Majestic points and updates the client.
Player.SetStat Sets a base stat (STAT_*).
Player.SetMoney Sets the Zen and updates the client.
Player.SetRuud Sets the Ruud and updates the client.
Player.AddRuud Adds Ruud; a negative amount takes Ruud.
Player.SetReset Sets the reset count.
Player.SetPKCount Sets the PK kill count.
Player.SetPKLevel Sets the PK level, 0..6 (3 = normal, 6 = murderer level 3), and updates the name colour.
Player.SetPKTimer Sets the PK points left (see Player.GetPKTimer).
Player.SetChatMute Bans the character from chat for seconds (at most 10 years).
Player.SetSkin Transforms the character into a monster look, -1 removes the transformation.
Player.SetVIP Sets the account VIP level (-1 = no VIP, up to 255) and the end time (Unix timestamp).
Player.GiveExperience Gives experience like killing a monster (buff bonuses are not applied).
Player.BlockAction Blocks (block = true, the default) or allows (false) an action for the character.
Player.ReCalc Recalculates all stats (after changing points, items or the option table) and updates the client.
Player.SendInfo Recalculates the stats and resends all character information (position, experience, points, Zen, HP / MP, PK, resets, levels).
Player.SendLevelUp Sends the normal level, free points and max HP / MP to the client.
Player.SendMasterLevelUp Sends the Master level-up effect and Master data to the client.
Player.SendLevels Resends the levels and points of all 3 level types (normal, Master, Majestic).
Player.SendStats Resends the character stats to the client.
Player.SendMoney Resends the Zen amount to the client.
Player.SendLife Resends HP to the client.
Player.SendMana Resends MP to the client.
Player.SendCommand Sends a command packet from the server to the game client: the client shows an event message or window.
Player.SendEventTimer Shows a timer in the screen corner.
Player.Fireworks Fireworks on the character.
Player.ActionSend The character does an emote (greeting, clapping ...) towards targetIndex (the character itself if the target is not valid).
Player.SetWindowText Changes the game window title of the player's client (UTF-8, up to 255 bytes).
Player.Disconnect Disconnects the player at once.
Player.Logout Closes the game for the player.
Player.Save Saves the character to the database now.
Player.CheckItemAction true if creating or deleting items is safe now: no trade, no open window, not teleporting and not moving between servers.
Player.MoveGate Moves the character to a gate (teleport gate number).
Player.MoveTo Teleports the character to map, x, y (x and y 0..255).
Player.OpenWarehouse Opens the warehouse without an NPC.
Player.ResetMasterTree Resets the Master skill tree and gives the Master points back.
Player.ResetMajesticTree Resets the Majestic skill tree.
Player.SummonMonster Creates a monster that follows and fights for the character.
Player.KillSummon Removes the character's summoned monster.
Coin.Get Table { WCoinC, WCoinP, GoblinPoint }.
Coin.Add Adds coins, saves to the database at once and updates the client.
Coin.Sub Takes coins, saves to the database at once and updates the client.
Player.GetOptionTable Table with all 45 fields; a field that was never set is 0.
Player.SetOptionTable Stores the values.

Server, objects, monsters, maps, messages, config, log, util (81)

Function What it does
Server.GetCode Code of this GameServer (the ServerCode of its configuration).
Server.GetName Name of this GameServer (ServerName in its configuration).
Server.GetOnlineCount Number of players on this GameServer.
Server.GetMaxUser Maximum number of players this GameServer accepts.
Server.GetVersion Client version accepted by the server, as five numbers separated by dots (A.BB.CC.D.E, for example "1.04.xx.x.x").
Server.GetMode Server type: 0 PvP, 1 non-PvP, 2 Golden PvP, 3 Golden non-PvP.
Server.IsNonPvP true when PvP is turned off on this GameServer.
Server.GetClassPointsPerLevel Level-up points a character class gets on each new level.
Server.Is28Option Always true: the +28 item option is always on in this version.
Server.GetLanguage Name of the language file the server uses (from the Lang folder).
Object.GetUserRange Two values: the lowest and the highest character index.
Object.GetMonsterRange Two values: the lowest and the highest monster index.
Object.GetSummonRange Two values: the lowest and the highest index used by summoned monsters.
Object.GetMaxIndex Highest object index on this GameServer.
Object.GetMaxItem Maximum number of items that can lie on the ground of one map.
Object.GetType Kind of object: 0 empty (OBJECT_NONE), 1 character (OBJECT_USER), 2 monster (OBJECT_MONSTER), 3 NPC (OBJECT_NPC), 5 item on the ground (OBJECT_ITEM).
Object.GetConnectStatus 0 empty (OBJECT_OFFLINE), 1 connected (OBJECT_CONNECTED), 2 logged in (OBJECT_LOGGED), 3 in game (OBJECT_ONLINE).
Object.GetName Name of the character, monster or NPC.
Object.GetClass Character class (CLASS_*) or monster ID.
Object.GetMap Map number where the object is (MAP_*).
Object.GetX X position (cell, 0..255) of the object.
Object.GetY Y position (cell, 0..255) of the object.
Object.GetDirection Direction the object is facing, 0..7.
Object.GetTarget For a monster: the object it is attacking.
Object.IsLive true if the character or monster exists and is alive.
Object.Warp Moves a character or monster to x, y (each clamped to 0..255) inside its current map.
Object.Kill Kills a character or monster.
Object.ViewportCreate Shows the object again to the players around it.
Object.ViewportDestroy Hides the object from the players around it.
Object.ForEachPlayer Calls callback(aIndex) for every character in game on this GameServer.
Object.ForEachPlayerOnMap Calls callback(aIndex) for every character in game on one map.
Object.ForEach Calls callback(index) for every character, monster and NPC that exists.
Object.ForEachMonster Calls callback(index) for every monster that is alive in the world, on every map.
Object.ForEachMonsterOnMap Calls callback(index) for every living monster on one map.
Object.ForEachMonsterByClass Calls callback(index) for every living monster of one class (monster ID), on every map.
Object.ForEachPartyMember Calls callback(aIndex) for every party member in game on this GameServer.
Object.ForEachGuildMember Calls callback(aIndex) for every guild member in game on this GameServer.
Object.ForEachNearby Calls callback(index) for every living character and monster in game on the same map (and instance) within range cells (0..255) of the object.
Object.CountPlayersOnMap Number of characters in game on a map.
Object.CountMonstersOnMap Number of living monsters on a map.
Object.GetPower Current value of HP, MP, SD or AG.
Object.GetMaxPower Maximum value (base + added part).
Object.GetAddPower Only the added part of the maximum (from items, buffs ...).
Object.SetPower Sets the current value.
Object.SetMaxPower Sets the maximum (at least 1); if the current value is higher it is lowered to the new maximum, then both are sent to the client.
Object.GetCombatStat Current value of a combat stat (names in the table above).
Object.SetCombatStat Sets a combat stat until the next stat calculation.
Monster.Create Spawns a monster and returns its index (-1 on error).
Monster.CreateInArea Spawns count monsters (1..200, default 1) at random points of the area x1, y1 - x2, y2.
Monster.CreateEx Spawns a monster with custom stats and returns its index (-1 on error).
Monster.Delete Removes a monster spawned by a script or a GM command.
Monster.GetTopDamageDealer Index of the character that did the most damage to the monster, -1 if none.
Monster.GetAttr Data of a monster class from Monster.xml, or nil if the class does not exist.
Monster.WatchRespawn Turns the onMonsterRespawn event on (true, default) or off (false) for one monster class.
Skill.Watch Turns the onUseSkill event on (true, default) or off (false) for one skill number.
Party.GetCount Number of members in the party.
Party.GetMember Index of member n (1..5, 1 = leader).
Map.GetName Name of the map.
Map.Exists true if the map is hosted on this GameServer.
Map.GetAttr Attribute bits of a cell: 1 safe zone, 2 standing, 4 / 8 / 16 blocked.
Map.CheckAttr true if the cell has any of the bits of attr.
Map.Fireworks Fireworks at a point, shown to the players near it.
Message.Send Sends a message to one player.
Message.SendAll Sends a message to everyone on this GameServer.
Message.SendGlobal Sends a message to every GameServer through Server_Link (this one included).
Message.Box Shows a message box in the centre of the screen of one player.
Message.BoxAll Shows a message box to every player in game on this GameServer.
Message.NpcSay The NPC (or monster) says text to one player.
Message.Post Shows a /post style line, sent by name, to everyone on this GameServer.
Message.GetText Text number id from the server language file.
Config.ReadNumber Number from an INI file.
Config.ReadString Text from an INI file.
Config.SaveString Writes a value to an INI file.
Log.Add Writes a normal line to the GameServer log (with a [Lua] prefix).
Log.AddC Writes a line to the GameServer log: 1 = red (error), 3 = yellow (warning), anything else = normal.
Util.Random Random integer in [min, max] (both included).
Util.LargeRandom Random integer in [0, 4294967295].
Util.GetTick Milliseconds since the machine started.
Util.ArgNumber Word number pos (starting at 0) of text as a number.
Util.ArgString Word number pos (starting at 0) of text.
Event.Refresh Tells the GameServer which on... event functions now exist, so it starts sending them.

Inventory, warehouse, items, buffs (48)

Function What it does
Inventory.GetSizes Three values: number of equipment slots (12), end of the main inventory (76), total number of inventory slots (239).
Inventory.CountItem Number of items with this code in the inventory.
Inventory.FreeSlots Number of free 1x1 cells in the inventory.
Inventory.HasSpaceForItem true if one item of this code fits in the inventory (uses the item size).
Inventory.HasSpace true if an item of width x height cells fits.
Inventory.DeleteSlot Deletes the item in one slot, equipment slots included (stats and the character look are updated).
Inventory.DeleteItems Deletes exactly count items (default 1) of this code.
Inventory.SetItem Changes only the fields given in the table: Level, Durability, Skill, Luck, Option, Exc, Ancient, Harmony, Option380, Sockets, SocketBonus.
Inventory.SendSlot Sends one inventory slot to the client again.
Inventory.SendList Sends the whole inventory to the client again.
Inventory.ReduceDurability Lowers the durability of the item in slot by amount (at most 255 at once), like normal wear.
Warehouse.GetItem Item in a warehouse slot.
Warehouse.CountItem Number of items with this code in the warehouse.
EventInventory.GetSize Number of slots of the event inventory.
EventInventory.GetItem Item in an event inventory slot, nil if empty or out of range.
EventInventory.CountItem Number of items with this code in the event inventory.
MuunInventory.GetSizes Two values: equipped Muun slots (3), total Muun inventory slots (103).
MuunInventory.GetItem Item in a Muun inventory slot (equipped slots included), nil if empty or out of range.
MuunInventory.CountItem Number of items with this code in the Muun inventory.
MuunInventory.DeleteSlot Deletes a Muun from the Muun inventory and updates the client.
Item.Give Creates the item in the right inventory (main, event or Muun).
Item.Drop Drops the item on the ground.
Item.GiveBag Opens a random item bag (ItemBag GUID number or name) into the inventory.
Item.DropBag Drops the items of a random item bag on the ground; the character is the owner.
Item.GremoryAdd Sends the item to the Gremory Case.
Item.GremoryFreeSlots Free slots of the Gremory Case.
Item.IsValid true if the item exists in the item list.
Item.GetName Item name from the item list, "" for an unknown code.
Item.GetKindA The KindA value of the item in the item list (0 for an unknown code).
Item.GetKindB The KindB value of the item in the item list (0 for an unknown code).
Item.GetSize Two values: width and height in inventory cells (0, 0 for an unknown code).
Item.IsSocket true if the item is a socket item.
Item.IsExcSocketAccessory true if the item is a socket pendant or ring.
Item.IsElemental true if the item is a pentagram or an errtel (elemental items).
Item.IsPentagram true if the pentagram system knows this code as a pentagram item.
Item.IsMasterPentagram true if the item is a pentagram with mastery.
Item.IsPentagramJewel true if the item is an errtel (pentagram jewel).
Item.IsMasterPentagramJewel true if the item is an errtel with mastery.
Item.GetMaxStack Maximum stack size (0 = not stackable).
Item.RandomAncientOption A random ancient option value for this item, to use as Ancient when creating it (0 = the item has no set).
Item.RandomLevel Random level in [min, max].
Item.GetGroundItem Item on the ground of a map; the table also has X and Y.
Buff.Add Adds a buff for seconds seconds.
Buff.AddItem Adds the buff of an item (potions, scrolls ...) for seconds seconds.
Buff.AddCashShop Adds the buff of a cash shop item.
Buff.Remove Removes a buff.
Buff.Has true if the buff is active on the character or monster.
Buff.Clear Removes the combat buffs; all = true: cash shop buffs too.

Database (3)

Function What it does
DB.Query Sends a query that returns rows.
DB.Execute Runs an INSERT / UPDATE / DELETE in the background.
DB.Escape Returns text with the special characters escaped, ready to be put between quotes ('...') in SQL.

Files (5)

Function What it does
File.Exists true if the file exists.
File.ReadText Table of lines: `{ "line 1", "line 2", ...
File.ReadIni Returns { [Section] = { Key = "Value" } }.
File.ReadXml Returns the root tag as:
LoadScript Runs a Lua file every time it is called (path rules as above).

Lua library (47)

Function What it does
Helpers.MakeItemId Builds an item code from its group and its index inside the group (group * 512 + index).
Helpers.GetItemType Returns the group of an item code (math.floor(itemCode / 512)).
Helpers.GetItemIndex Returns the index of an item code inside its group (itemCode % 512).
Helpers.RGB Returns a colour value: r + g * 256 + b * 65536.
Coin.IsValidType true if coinType is 0, 1, 2 or 3.
Coin.GetName Returns "Zen", "WCoin", "Goblin Point" or "Ruud", and "" for an unknown type.
Coin.GetByType Returns how much of that currency the character has.
Coin.Check true if the character has at least amount.
Coin.Charge Takes amount if the character has enough.
Coin.Give Gives amount.
ActionTick.Set Stores a value in slot 0, 1 or 2 of the character (name up to 15 characters).
ActionTick.Get Returns the stored value, 0 if nothing is stored.
ActionTick.GetName Returns the stored name, "" if nothing is stored.
ActionTick.Clear Empties the slot.
Scheduler.LoadFromXML Loads the schedule (path like File.ReadXml).
Scheduler.GetEventCount Number of Event lines loaded.
Scheduler.HasSecondPrecisionEvents true if a Start line uses Second (the schedule is then checked every second instead of once per minute).
Scheduler.GetEventName Returns the Name of the event, "" if no event has this type.
Scheduler.CheckEventNotices Events whose start is exactly NoticePeriod seconds away now: `{ { type = ..., secondsRemaining = ...
Scheduler.CheckEventStarts Events starting now that are not active yet: `{ type, ...
Scheduler.CheckEventEnds Active events whose Duration has passed: `{ type, ...
Scheduler.IsEventActive true between the start and the end of the event.
Scheduler.GetElapsedTime Seconds since the start, -1 if the event is not active.
Scheduler.GetRemainingTime Seconds until the end, -1 if the event is not active or has no Duration.
Scheduler.GetProgress 0..100 (percent of Duration already passed), -1 if the event is not active or has no Duration.
Scheduler.StopEvent Ends an active event now and sends onScheduleEnd to the modules.
EventMonsterTracker.SpawnAndRegister Spawns one monster at a random point of the area x1, y1 ..
EventMonsterTracker.SpawnWaveAndRegister Spawns count monsters (up to 500), each at a random point of the area, and tracks them.
EventMonsterTracker.Register Tracks a monster you spawned yourself.
EventMonsterTracker.RegisterNPC Same as Register with type = OBJECT_TYPE_NPC.
EventMonsterTracker.Unregister Stops tracking the object (does not remove it).
EventMonsterTracker.IsTracked true if the object is tracked for this event.
EventMonsterTracker.GetObjectInfo Returns `{ class = ..., type = ...
EventMonsterTracker.GetMonsterClass Returns the registered class, -1 if the object is not tracked.
EventMonsterTracker.GetMonsters Returns the list of tracked indexes of the event, optionally only monsters or only NPCs.
EventMonsterTracker.GetCount Number of tracked objects of the event (with the same filter as GetMonsters).
EventMonsterTracker.CleanupEvent Deletes the tracked objects that still exist (Monster.Delete) and stops tracking them.
EventMonsterTracker.CleanupMonsters Same as CleanupEvent(eventType, OBJECT_TYPE_MONSTER): removes the monsters, keeps the NPCs.
EventMonsterTracker.CleanupNPCs Same as CleanupEvent(eventType, OBJECT_TYPE_NPC): removes the NPCs, keeps the monsters.
EventMonsterTracker.CleanupDead Stops tracking the objects that died or disappeared (removes nothing).
EventMonsterTracker.GetActiveEvents List of the events that still have tracked objects.
EventMonsterTracker.ClearAll Forgets every event (removes nothing).
OptionBonus.Set Sets the bonuses of source (any name, usually the module name).
OptionBonus.Get Returns a copy of the bonuses of source, {} if it has none.
Player.GetObject Returns the object of the character, nil if aIndex is not an online character.
Player.GetObjectByName Same as Player.GetObject, found by character name.
Player.IsObjectValid true while the object still points to the same character in game.

Timers (9)

Function What it does
Timer.Create Runs the function once after seconds, then the timer is removed.
Timer.CreateRepeating Runs the function every seconds until the timer is removed.
Timer.RepeatNTimes Runs the function every seconds, times times (n = 1..times), then the timer is removed.
Timer.Remove Removes the timer.
Timer.Exists true if the timer still exists (paused timers included).
Timer.GetRemaining Seconds until the next run, 0 if the timer does not exist.
Timer.Stop Pauses the timer (it keeps its remaining time).
Timer.Start Resumes a paused timer.
Timer.IsActive true if the timer exists and is not paused.

Module system (2)

Function What it does
BridgeFunctionAttach Attaches the global function named functionName to a module event ("OnCharacterEntry", "OnItemDrop" ...).
BridgeDispatch Runs the functions attached to event (the global event name, for example "onItemDrop") with the given arguments, each one isolated from errors.

Next: Folder structure

Clone this wiki locally