• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Scripting Reference

Drakkhan

Illuria Project Lead
Joined
Oct 3, 2013
Messages
141
Reaction score
22
Where does one find a list of functions available in .lua scripts for a specific server?

For Example:
Say I'm using The Forgotten Sever - Version 0.2.15, where can I find a list for other functions like:

onUse(cid, item, fromPosition, itemEx, toPosition)

as well as when they apply, and what the input variables relate to?


Thanks!
 
There isn't any documentation on that as far as I know.

For actions there is only the onUse(cid, item, fromPosition, itemEx, toPosition) event.

cid = creature id
item = table of the item you are using with uid (unique id), itemid, type (subtype) and actionid
fromPosition = position table with x, y and z (the position you are using the item from for items with "Use with...")
itemEx = table of the item you select with "Use with..."
toPosition = position table with x, y and z (the position you are using the item on for items with "Use with...")
 
Thanks much for your timely reply!

How does anyone learn the meaning of such functions without documentation on what they are used for? Have you seen so many examples that you've been able to deduce each of them?

Also, where might one find the script for commands such as "/a" and "!buyhouse" found in the "commands.xml" file?
 
You can use the source codes for your server. Means, search for your sources and then for "luascript.cpp". There is the list of ALL functions that your server supports. In fact, it is the list, your server uses, so there is a lot of code/info you don't need/understand. You need to filter this code and there you got all your functions
 
@Fermantor, thank you! I'll look into this.. possibly even write a tutorial on the subject.. the closest thing I could come up with was:

http://otland.net/threads/scripting-guide.74030/

which is EXCELLENT, but not complete.

Update here.. for The Forgotten Server 0.2.14-0.2.15 (Mystic Spirit) there is a text file that lists all the supported functions. Big props to that team! In case someone finds this thread via a search for what I was looking for, here is a list of MY server's functions:
Code:
    //*GET
   
        getPlayerMasterPos(cid)
        getPlayerLossPercent(cid)
        getItemIdByName(name)
        getTownName(townId)
        getTownTemplePosition(townId)
        getPlayersByAccountNumber(accountNumber)
        getAccountNumberByPlayerName(name)
        getIPByPlayerName(name)
        getPlayersByIPAddress(ip[, mask = 0xFFFFFFFF])
        getFluidSourceType(type)
        getItemDescriptions(itemid)
        getItemWeightByUID(uid)
        getContainerCapById(itemid)
        getDepotId(uid)
        getHouseTilesSize(houseid)
        getHighscoreString(skillId)
        getPartyMembers(leaderId)
        getCreatureMaster(cid) - Returns: returns the creature's master or itself if the creature isn't a summon
        getMonsterTargetList(cid)
        getMonsterFriendList(cid)
        getPlayerByName(name)
        getPlayerGUIDByName(name)   
        getPlayerLearnedInstantSpell(cid, name)
        getPlayerInstantSpellCount(cid)
        getPlayerInstantSpellInfo(cid, index)
        getPlayerMount(cid, mountid)
        getWorldType()
        getWorldTime()
        getWorldLight()
        getWorldCreatures(type) - Types: 0 players, 1 monsters, 2 npcs, 3 all Returns: Amount
        getWorldUpTime()
        getGuildId(guild_name)
        getPlayerSex(cid)
        getContainerSize(uid)
        getContainerCap(uid)
        getContainerItem(uid, slot)
        getInstantSpellInfoByName(cid, name)
        getInstantSpellWords(name)
        getGlobalStorageValue(valueid)
        getHouseOwner(houseid)
        getHouseName(houseid)
        getHouseEntry(houseid)
        getHouseRent(houseid)
        getHouseTown(houseid)
        getHouseAccessList(houseid, listid)
        getHouseByPlayerGUID(playerGUID)
        getCreatureOutfit(cid)
        getCreaturePosition(cid)
        getCreatureName(cid)
        getCreatureSpeed(cid)
        getCreatureBaseSpeed(cid)
        getCreatureTarget(cid)
        getTilePzInfo(pos) - Returns: 1 is pz. 0 no pz.
        getTileHouseInfo(pos) - Returns: 0 no house. != 0 house id
        getItemRWInfo(uid)
        getThingfromPos(pos)
        getThing(uid)
        getCreatureCondition(cid, condition)
        getItemName(itemid)
        getItemWeight(itemid, count)
        getPlayerPremiumDays(cid)
        getPlayerSkullType(cid)
        getPromotedVocation(vocation)
        getPlayerBlessing(cid, blessing)
        getTileThingByTopOrder(pos, topOrder)
        getTileItemByType(pos, type)
        getTopCreature(pos)
        getTileThingByPos(pos)
        getTileItemById(pos, itemId, <optional> subType)
        getOnlinePlayers()
        getTileInfo(pos) 
        getThingPos(uid)
        getSpectators(centerPos, rangex, rangey, multifloor)
        getPlayerStorageValue(uid, valueid)
        getPlayerItemById(cid, deepSearch, itemId, <optional> subType)
        getPlayerIp(cid)
        getPlayerGuildLevel(cid)
        getCreatureSummons(cid) - Returns: returns a table with all the summons of the creature
        getWaypointPosition(name)

//*DO
   
        doPlayerAddBlessing(cid, blessing)
        doPlayerPopupFYI(cid, message)
        doCombat(cid, combat, param)
        doPlayerRemovePremiumDays(cid, days)
        doPlayerAddPremiumDays(cid, days)
        doPlayerSetSex(cid, newSex)
        doSetCreatureOutfit(cid, outfit, time)
        doSetItemOutfit(cid, item, time)
        doSetMonsterOutfit(cid, name, time)
        doChangeSpeed(cid, delta)
        doAddContainerItem(uid, itemid, <optional> count/subtype)
        doChallengeCreature(cid, target)
        doTargetCombatDispel(cid, target, type, effect)
        doAreaCombatDispel(cid, pos, area, type, effect)
        doTargetCombatCondition(cid, target, condition, effect)
        doAreaCombatCondition(cid, pos, area, condition, effect)
        doTargetCombatMana(cid, target, min, max, effect)
        doAreaCombatMana(cid, pos, area, min, max, effect)
        doTargetCombatHealth(cid, target, type, min, max, effect)
        doAreaCombatHealth(cid, type, pos, area, min, max, effect)
        doSetCreatureDropLoot(cid, doDrop)
        doSetCreatureLight(cid, lightLevel, lightColor, time)
        doPlayerRemoveMount(cid, mountid)
        doPlayerAddMount(cid, mountid)
        doPlayerRemOutfit(cid,looktype,addons)
        doPlayerAddOutfit(cid,looktype,addons)
        doPlayerSetGuildNick(cid, nick)
        doPlayerSetGuildRank(cid, rank)
        doPlayerSetGuildId(cid, id)
        doPlayerAddExp(cid,exp)
        doPlayerRemoveItem(cid,itemid,count)
        doPlayerSetVocation(cid,voc)
        doPlayerSetTown(cid, townid)
        doMoveCreature(cid, direction)
        doRemoveCreature(cid)
        doConvinceCreature(cid, target)
        doSummonCreature(name, pos)
        doCreateTeleport(itemid, topos, createpos)
        doTileAddItemEx(pos, uid)
        doCreateItemEx(itemid, <optional> count/subtype) - Returns: Returns uid of the created item, only works on tiles.
        doCreateItem(itemid, type/count, pos) - Returns: Returns uid of the created item, only works on tiles.
        doDecayItem(uid)
        doShowTextDialog(cid, itemid, text)
        doPlayerRemoveMoney(cid, money)
        doPlayerSendTextMessage(cid, MessageClasses, message)
        doPlayerAddItemEx(cid, uid, <optional: default: 0> useCidPosOnFail)
        doPlayerAddItem(uid, itemid, <optional> count/subtype) - Returns: Returns uid of the created item
        doPlayerAddSoul(cid, soul)
        doPlayerAddManaSpent(cid, mana)
        doPlayerAddMana(cid, mana)
        doCreatureAddHealth(cid, health)
        doPlayerAddSkillTry(cid, skillid, n)
        doSendAnimatedText(pos, text, color)
        doSetItemSpecialDescription(uid, desc)
        doSetItemText(uid, text)
        doSetItemActionId(uid, actionid)
        doChangeTypeItem(uid, newtype)
        doSendDistanceShoot(frompos, topos, type)
        doSendMagicEffect(pos, type)
        doCreatureSay(cid, text, type)
        doTransformItem(uid, toitemid, <optional> count/subtype)
        doTeleportThing(cid, newpos, <optional> pushmove)
        doPlayerSendDefaultCancel(cid, ReturnValue)
        doRemoveCondition(cid, type)
        doAddCondition(cid, condition)
        doMonsterChangeTarget(cid)
        doSetMonsterTarget(cid, target)
        doCreatureChangeOutfit(cid, outfit)
        doCreateNpc(name, pos)
        doRelocate(pos, posTo) - Returns: Moves all moveable objects from pos to posTo
        doAddContainerItemEx(uid, virtuid)
        doSendTutorial(cid, tutorialid)
        doCreatureSetLookDir(cid, direction)       
        doPlayerFeed(cid, food)
        doRemoveItem(uid, <optional> n)
        doAddMapMark(cid, pos, type, <optional> description)    
        doPlayerAddMoney(cid, money)
        doPlayerChangeName(cid, newName) 
        doSetCreatureDirection(cid, direction)
        doWaypointAddTemporial(name, pos)
   
    //*SET
   
        setHouseAccessList(houseid, listid, listtext)
        setHouseOwner(houseid, ownerGUID)
        setCombatArea(combat, area)
        setCombatCondition(combat, condition)
        setCombatParam(combat, key, value)
        setConditionParam(condition, key, value)
        setCombatCallBack(combat, key, function_name)
        setCombatFormula(combat, type, mina, minb, maxa, maxb)
        setConditionFormula(combat, mina, minb, maxa, maxb)
        setGlobalStorageValue(valueid, newvalue)
        setPlayerGroupId(cid, newGroupId)
        setPlayerStorageValue(uid, valueid, newvalue)

    //*IS
       
        isPlayer(cid)
        isCreature(cid)
        isContainer(uid)
        isMoveable(uid)
        isSightClear(fromPos, toPos, floorCheck)
        isValidUID(uid)
        isPlayerGhost(cid)
        isPlayerPzLocked(cid)
        isDepot(uid)
        isCorpse(uid)
        isMovable(uid)
        isItemMovable(itemid)
        isItemMoveable(itemid)
        isItemStackable(itemid)
        isItemRune(itemid)
        isItemDoor(itemid)
        isItemContainer(itemid)
        isItemFluidContainer(itemid)
        isInArray(array, value)
       
    //*MISC
   
        broadcastMessage(message, type)
        createCombatArea( {area}, <optional> {extArea} )
        canPlayerWearOutfit(cid, looktype, addons)
        hasProperty(uid, prop)
        refreshMap()
        cleanMap()
        createConditionObject(type)
        addDamageCondition(condition, rounds, time, value)
        addOutfitCondition(condition, lookTypeEx, lookType, lookHead, lookBody, lookLegs, lookFeet)
        createCombatObject()
        numberToVariant(number)
        stringToVariant(string)
        positionToVariant(pos)
        targetPositionToVariant(pos)
        variantToNumber(var)
        variantToString(var)
        variantToPosition(var)
        debugPrint(text)
        addEvent(callback, delay, parameter)
        stopEvent(eventid)
        mayNotLogout(cid, value)
        mayNotMove(cid, value)
        saveData()
        saveServer(), does the same thing as saveData()
        escapeString(str)
        registerCreatureEvent(uid, eventName)
        queryTileAddThing(uid, pos, <optional> flags)
        playerLearnInstantSpell(cid, name)
        canPlayerLearnInstantSpell(cid, name)

TFS 0.2.15: http://otland.net/threads/9-80-9-86-the-forgotten-server-v0-2-15-mystic-spirit.188228/

TFS 0.2.14: http://otland.net/threads/9-60-9-61-the-forgotten-server-v0-2-14-mystic-spirit.166619/
 
Last edited by a moderator:
The commands in commands.xml are hardcoded in the source code, in commands.cpp. We are working on moving them to talkactions to let the end-users customize them with TFS 1.0 (which is based on 0.2.15).

About the Lua functions, most of these are being deprecated (they will still work though, so use them if you prefer them) in favor of metatable "classes" in TFS 1.0. @Evan has been working on documentation for the new system, you can see his draft in his GitHub fork here: https://github.com/EvanMC/forgottenserver/wiki/Script-System

The official repository for TFS 1.0 is at https://github.com/otland/forgottenserver
 
Back
Top