• 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!

What does local & function mean?

Status
Not open for further replies.

Bird

Banned User
Joined
Mar 19, 2019
Messages
12
Reaction score
0
Sorry if i sound like a complete noob but what does local & function mean? Sometimes i see the word local in front of a word and other times i see local in front of the word function and then there are more words and parentheses and more words separated by commas.

I really want to learn this stuff but i am having a hard time understanding it and the link i was given earlier to learn this is too complicated for me to understand. :(
 
The 1st link didn't make any sense. The 2nd link links to other links and some of those links are dead links and the rest don't explain anything.
You asked what does Function&Local mean.
First link has exactly explaining of what does function mean on Part I
PART I - Functions...(What are they? What are they for?)

Functions are basicly just the thing which tells the server what you want to be happen with this Script.
There are many functions but you have to Split them into 2 Groups.

Group 1: The "Primary Functions" those functions are always listened at the very first start of a Script they tell what kind of action will be executed now.
Group 2: The "Secondary Functions" those functions are always ordered under the "Primary Function" but they are as important as the "Primary Functions".

Now we go into Details...

Let's start with the Primary Function.

Like I already stated those are the Functions which have to be ontop always. Let us go deeper into details so you'll understand why it is like that!

List of the "Primary Functions" NOTE (The Functions maybe variate depending on which server distro you use!)

Basic Ones:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
function onStepIn(cid, item, frompos, itemEx, topos)
function onStepOut(cid, item, frompos, itemEx, topos)
function onSay(cid, words, param)
function onEquip(cid, item, slot)
function onDeEquip(cid, item, slot)
function onAddItem(cid, moveitem, tileitem, position)
function onRemoveItem(cid, moveitem, tileitem, position)

Creaturescripts:

Lua:
function onLogin(cid)
function onLogout(cid)
function onJoinChannel(cid, channel, users)
function onLeaveChannel(cid, channel, users)
function onAdvance(cid, skill, oldLevel, newLevel)
function onLook(cid, thing, position, lookDistance)
function onSendMail((cid, receiver, open, itemBox)
function onReceiveMail(cid, sender, open, itemBox)
function onTradeRequest(cid, target, item)
function onTradeAccept(cid, target, item)
function onTextEdit(cid, item, newText)
function onReportBug(cid, comment)
function onThink(cid, interval)
function onDirection(cid, old, current)
function onOutfit(cid, old, current)
function onStatsChange(cid, attacker, type, combat, value)
function onAreaCombat(cid, ground, position, aggressive)
function onPush(cid, target)
function onTarget(cid, target)
function onFollow(cid, target)
function onCombat(cid, target)
function onAttack(cid, target)
function onCast(cid, target)
function onKill(cid, target, damage, flags)
function onDeath(cid, corpse, deathList)
function onPreprareDeath(cid, deathList)

Globalevents:

Lua:
function onStartUp()
function onShutdown()
function onGlobalSave()
function onRecord(current, old, cid)
function onTime(time)
function onThink(interval)

Those are the Functions which the Updated Distros have so far.

Let me explain you each function now...

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)

Like you can easy guess this will make something happen when you use something

example:

You pull a lever and a wall will be created.


Lua:
function onStepIn(cid, item, frompos, itemEx, topos)

This will make something happen when you walk on a specificated tile, yes you heard right this one will ONLY be executed when you walk on a tile.

example:

You walk on a tile and get an welcome message.


Lua:
function onStepOut(cid, item, frompos, itemEx, topos)

This one is just the difference from "onStepIn" this one ONLY works when you step from a specificated tile.

example:

You walk from a tile and will be teleported to another position.


Lua:
function onSay(cid, words, param)

This one will only work when a player says a specificated word which will execute the script then...

example:

The Player has to say "!Quest" to start an quest.


Lua:
function onEquip(cid, item, slot)

To get this in order to work you have to put an item into one of your equipment slots.

example:

You put an Crown armor into your Body Equipment Slot.


Lua:
function onDeEquip(cid, item, slot)

Almost same as "onEquip" but in order to get it work you have to put off an item from your Equipment Slot.

example:

You put the Crown armor off from your Body Equipment Slot.


Lua:
function onAddItem(cid, moveitem, tileitem, position)

This is one of the less used Functions but it's really usefull sometimes, you have to put an item on a specificated tile in order to get it to work.

example:

You put an Axe on a sacrfice table, the item will be gone and another item will be created.

Lua:
function onRemoveItem(cid, moveitem, tileitem, position)

This function is also not much used. You need to remove an item from a specificated tile in order to get it to work

example:

You pickup a a key from ground and a door will open.

Going to edit the post later to add the rest.

This was a little explanation of the "Primary Functions"
You should now be able to recognise what usage which function has.

"Secondary" List: -- Functions from tfs 0.3.6pl1
Lua:
//get*
    getCreatureHealth(cid)
    getCreatureMaxHealth(cid)
    getCreatureHideHealth(cid)
    getCreatureMana(cid)
    getCreatureMaxMana(cid)
    getCreatureSpeakType(cid)
    getCreatureMaster(cid)
    getCreatureSummons(cid)
    getCreatureOutfit(cid)
    getCreaturePosition(cid)
    getCreatureLookDirection(cid)
    getCreatureName(cid)
    getCreatureSpeed(cid) //TODO
    getCreatureBaseSpeed(cid) //TODO
    getCreatureTarget(cid) //TODO
    getCreatureByName(name)
    getCreatureSkullType(cid)
    getCreatureCondition(cid, condition[, subId]) //TODO
    getCreatureNoMove(cid) //TODO
    getMonsterInfo(name)
    getMonsterHealingSpells(name) //TODO
    getMonsterAttackSpells(name) //TODO
    getMonsterLootList(name) //TODO
    getMonsterSummonList(name) //TODO
    getMonsterTargetList(cid) //TODO
    getMonsterFriendList(cid) //TODO
    getPlayerByNameWildcard(name~[, ret = false]) //TODO
    getPlayerLossSkill(cid) //TODO
    getPlayerLossPercent(cid, lossType) //TODO
    getPlayerGUIDByName(name[, multiworld = false]) //TODO
    getPlayerNameByGUID(guid[, multiworld = false[, displayError = true]]) //TODO
    getPlayerFood(cid)
    getPlayerLevel(cid)
    getPlayerExperience(cid)
    getPlayerMagLevel(cid[, ignoreBuffs = false]) //TODO
    getPlayerSpentMana(cid) //TODO
    getPlayerAccess(cid)
    getPlayerGhostAccess(cid)
    getPlayerSkillLevel(cid, skillId)
    getPlayerSkillTries(cid, skillId) //TODO
    getPlayerTown(cid)
    getPlayerVocation(cid)
    getPlayerRequiredMana(cid, magicLevel) //TODO
    getPlayerRequiredSkillTries(cid, skillId, skillLevel) //TODO
    getPlayerItemCount(cid, itemid[, subType = -1])
    getPlayerSoul(cid)
    getPlayerAccountId(cid) //TODO
    getPlayerAccount(cid) //TODO
    getPlayerIp(cid) //TODO
    getPlayerFreeCap(cid)
    getPlayerLight(cid)
    getPlayerSlotItem(cid, slot)
    getPlayerWeapon(cid[, ignoreAmmo = false]) //TODO
    getPlayerItemById(cid, deepSearch, itemId[, subType = -1]) //TODO
    getPlayerDepotItems(cid, depotid)
    getPlayerGuildId(cid)
    getPlayerGuildName(cid)
    getPlayerGuildRank(cid)
    getPlayerGuildNick(cid)
    getPlayerGuildLevel(cid) //TODO: From here, all bottoms
    getPlayerSex(cid)
    getPlayerStorageValue(uid, key)
    getPlayerGUID(cid)
    getPlayerFlagValue(cid, flag)
    getPlayerCustomFlagValue(cid, flag)
    getPlayerPromotionLevel(cid)
    getPlayerGroupId(cid)
    getPlayerLearnedInstantSpell(cid, name)
    getPlayerInstantSpellCount(cid)
    getPlayerInstantSpellInfo(cid, index)
    getPlayerBlessing(cid, blessing)
    getPlayerStamina(cid)
    getPlayerExtraExpRate(cid)
    getPlayerPartner(cid)
    getPlayerParty(cid)
    getPlayerPremiumDays(cid)
    getPlayerBalance(cid)
    getPlayerMoney(cid)
    getPlayerSkullTicks(cid, type)
    getPlayerRates(cid)
    getPlayerLastLogin(cid)
    getPlayerLastLoginSaved(cid)
    getPlayerAccountManager(cid)
    getInstantSpellInfo(cid, name)
    getPlayersByAccountId(accountNumber)
    getPlayersByIp(ip[, mask = 0xFFFFFFFF])
    getChannelUsers(channelId)
    getPlayersOnline()
    getPartyMembers(lid)
    getAccountIdByName(name)
    getAccountByName(name)
    getAccountIdByAccount(accName)
    getAccountByAccountId(accId)
    getIpByName(name)
    getItemRWInfo(uid)
    getItemProtection(uid)
    getItemDescriptionsById(itemid)
    getItemWeightById(itemid, count[, precise])
    getItemDescriptions(uid)
    getItemWeight(uid[, precise])
    getItemAttack(uid)
    getItemExtraAttack(uid)
    getItemDefense(uid)
    getItemExtraDefense(uid)
    getItemArmor(uid)
    getItemAttackSpeed(uid)
    getItemHitChance(uid)
    getItemShootRange(uid)
    getItemIdByName(name[, displayError = true])
    getItemLevelDoor(itemid)
    getItemWeaponType(uid)
    getFluidSourceType(type)
    getContainerSize(uid)
    getContainerCap(uid)
    getContainerCapById(itemid)
    getContainerItem(uid, slot)
    getDepotId(uid)
    getTileItemById(pos, itemId[, subType = -1])
    getTileItemByType(pos, type)
    getTileThingByPos(pos)
    getTileInfo(pos)
    getTopCreature(pos)
    getClosestFreeTile(cid, targetpos[, extended = false[, ignoreHouse = true]])
    getThingFromPos(pos)
    getThing(uid)
    getThingPos(uid)
    getHouseInfo(id)
    getHouseAccessList(houseid, listid)
    getHouseByPlayerGUID(playerGUID)
    getHouseFromPos(pos)
    getTownId(townName)
    getTownName(townId)
    getTownTemplePosition(townId)
    getTownHouses(townId)
    getWorldType()
    getWorldTime()
    getWorldLight()
    getWorldCreatures(type) //0 players, 1 monsters, 2 npcs, 3 all
    getWorldUpTime()
    getHighscoreString(skillId)
    getVocationInfo(id)
    getGuildId(guildName)
    getGuildMotd(guildId)
    getSpectators(centerPos, rangex, rangey[, multifloor = false])
    getSearchString(fromPosition, toPosition[, fromIsCreature = false[, toIsCreature = false]])
    getWaypointPosition(name)
    getGameState()
    getNotationsCount(accId)
    getBanData(value)
    getBanList(type[, value])
    getBanReason(id)
    getBanAction(id[, ipBanishment])
    getGlobalStorageValue(valueid)
    getExperienceStage(level)
    getConfigFile()
    getConfigValue(key)
    getModList()
    loadmodlib(libName)
    domodlib(libName)
    getLogsDir()
    getDataDir()
    getWaypointList()
    getTalkActionList()
    getExperienceStageList()

    //set*
    setCreatureMaxHealth(cid, health)
    setCreatureMaxMana(cid, mana)
    setHouseOwner(houseid, ownerGUID)
    setHouseAccessList(houseid, listid, listtext)
    setItemName(uid)
    setItemPluralName(uid)
    setItemArticle(uid)
    setItemAttack(uid, attack)
    setItemExtraAttack(uid, extraattack)
    setItemDefense(uid, defense)
    setItemArmor(uid, armor)
    setItemExtraDefense(uid, extradefense)
    setItemAttackSpeed(uid, attackspeed)
    setItemHitChance(uid, hitChance)
    setItemShootRange(uid, shootRange)
    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(key, newValue)
    setWorldType(type)

    //do*
    doCreatureAddHealth(cid, health[, force])
    doCreatureAddMana(cid, mana)
    doCreatureSetDropLoot(cid, doDrop)
    doCreatureSetSkullType(cid, skull)
    doCreatureSetSpeakType
    doCreatureSetLookDirection(cid, dir)
    doPlayerSetMaxCapacity(cid, cap)
    doCreatureChangeOutfit(cid, outfit)
    doCreatureSay(uid, text, type[, ghost = false[, cid = 0[, pos]]])
    doCreatureSetNoMove(cid, cannotMove)
    doSetCreatureLight(cid, lightLevel, lightColor, time)
    doSetCreatureOutfit(cid, outfit, time)
    doRemoveCreature(cid[, executeLogout = true])
    doMoveCreature(cid, direction)
    doConvinceCreature(cid, target)
    doChallengeCreature(cid, target)
    doChangeSpeed(cid, delta)
    doSummonMonster(name, pos)
    doCreateMonster(name, pos)
    doMonsterChangeTarget(cid)
    doMonsterSetTarget(cid, target)
    doCreateNpc(name, pos)
    doSetMonsterOutfit(cid, name, time)
    doPlayerBroadcastMessage(cid, message[, type])
    doPlayerSetSex(cid, newSex)
    doPlayerSetTown(cid, townid)
    doPlayerSetVocation(cid, voc)
    doPlayerSetStorageValue(uid, key, newValue)
    doPlayerSetGroupId(cid, newGroupId)
    doPlayerSetPromotionLevel(cid, level)
    doPlayerSetStamina(cid, minutes)
    doPlayerSetBalance(cid, balance)
    doPlayerSetExtraExpRate(cid, value)
    doPlayerSetPartner(cid, guid)
    doPlayerRemoveItem(cid, itemid, count[, subtype])
    doPlayerAddExperience(cid, amount)
    doPlayerSetGuildId(cid, id)
    doPlayerSetGuildRank(cid, rank)
    doPlayerSetGuildNick(cid, nick)
    doPlayerAddOutfit(cid,looktype, addons)
    doPlayerRemoveOutfit(cid,looktype, addons)
    doPlayerSetRedSkullTicks(cid, amount)
    doPlayerSetLossPercent(cid, lossType, newPercent)
    doPlayerSetLossSkill(cid, doLose)
    doPlayerAddSkillTry(cid, skillid, n)
    doPlayerAddSpentMana(cid, amount)
    doPlayerAddSoul(cid, soul)
    doPlayerAddItem(uid, itemid[, count/subtype[, canDropOnMap = true]])
    doPlayerAddItemEx(cid, uid[, canDropOnMap = false])
    doPlayerSendTextMessage(cid, MessageClasses, message)
    doPlayerSendChannelMessage(cid, author, message, SpeakClasses, channel)
    doPlayerSendToChannel(cid, targetId, SpeakClasses, message, channel[, time])
    doPlayerAddMoney(cid, money)
    doPlayerRemoveMoney(cid, money)
    doPlayerTransferMoneyTo(cid, target, money)
    doPlayerPopupFYI(cid, message)
    doPlayerSendTutorial(cid, id)
    doPlayerAddMapMark(cid, pos, type[, description])
    doPlayerAddPremiumDays(cid, days)
    doPlayerAddBlessing(cid, blessing)
    doPlayerAddStamina(cid, minutes)
    doPlayerResetIdleTime(cid)
    doPlayerLearnInstantSpell(cid, name)
    doPlayerUnlearnInstantSpell(cid, name)
    doPlayerFeed(cid, food)
    doPlayerSendCancel(cid, text)
    doPlayerSendDefaultCancel(cid, ReturnValue)
    doPlayerSetRate(cid, type, value)
    doPlayerJoinParty(cid, lid)
    doPlayerSendOutfitWindow(cid)
    doPlayerSave(cid[, shallow = false])
    doCreateItem(itemid, type/count, pos)
    doCreateItemEx(itemid[, count/subtype])
    doAddContainerItemEx(uid, virtuid)
    doAddContainerItem(uid, itemid[, count/subtype])
    doChangeTypeItem(uid, newtype)
    doDecayItem(uid)
    doRemoveItem(uid[, count])
    doTransformItem(uid, toitemid[, count/subtype])
    doSetItemActionId(uid, actionid)
    doSetItemText(uid, text[, writer[, date]])
    doSetItemSpecialDescription(uid, desc)
    doSetItemOutfit(cid, item, time)
    doSetItemProtection(uid, value)
    doTileAddItemEx(pos, uid)
    doTileQueryAdd(uid, pos[, flags])
    doAddCondition(cid, condition)
    doRemoveCondition(cid, type[, subId])
    doRemoveConditions(cid[, onlyPersistent])
    doAreaCombatHealth(cid, type, pos, area, min, max, effect)
    doTargetCombatHealth(cid, target, type, min, max, effect)
    doAreaCombatMana(cid, pos, area, min, max, effect)
    doTargetCombatMana(cid, target, min, max, effect)
    doAreaCombatCondition(cid, pos, area, condition, effect)
    doTargetCombatCondition(cid, target, condition, effect)
    doAreaCombatDispel(cid, pos, area, type, effect)
    doTargetCombatDispel(cid, target, type, effect)
    doCombat(cid, combat, param)
    doTeleportThing(cid, newpos[, pushmove = true])
    doCreateTeleport(itemid, topos, createpos)
    doSendMagicEffect(pos, type[, player])
    doSendDistanceShoot(frompos, topos, type[, player])
    doSendAnimatedText(pos, text, color[, player])
    doShowTextDialog(cid, itemid, text)
    doRelocate(pos, toPos[, creatures = true])
    doBroadcastMessage(message, type)
    doWaypointAddTemporial(name, pos)
    doSetGameState(stateId)
    doAddIpBanishment(ip[, length[, comment[, admin]]])
    doAddNamelock(name[, reason[, action[, comment[, admin]]]])
    doAddBanishment(accId[, length[, reason[, action[, comment[, admin]]]]])
    doAddDeletion(accId[, reason[, action[, comment[, admin]]]]])
    doAddNotation(accId[, reason[, action[, comment[, admin]]]]])
    doRemoveIpBanishment(ip[, mask])
    doRemoveNamelock(name)
    doRemoveBanisment(accId)
    doRemoveDeletion(accId)
    doRemoveNotations(accId)
    doSaveServer()
    doReloadInfo(id[, cid])
    doCleanHouse(houseId)
    doCleanMap()
    doRefreshMap()

    //is*
    isCreature(cid)
    isMonster(uid)
    isNpc(uid)
    isPlayer(cid)
    isPlayerPzLocked(cid)
    isItemStackable(itemid)
    isItemRune(itemid)
    isItemMovable(itemid)
    isItemDoor(itemid)
    isItemContainer(itemid)
    isItemFluidContainer(itemid)
    isContainer(uid)
    isCorpse(uid)
    isMovable(uid)
    isSightClear(fromPos, toPos, floorCheck)
    isIpBanished(ip[, mask])
    isPlayerNamelocked(name)
    isAccountBanished(accId)
    isAccountDeleted(accId)
    isInArray({array}, value[, lower = true])

    //others
    registerCreatureEvent(uid, eventName)
    createCombatArea({area}[, {exArea}])
    createConditionObject(type[, ticks[, buff[, subId]]])
    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)
    canPlayerWearOutfit(cid, lookType, addons)
    executeRaid(name)
    addEvent(callback, delay, ...)
    stopEvent(eventid)
    hasProperty(uid)

    md5(str)
    sha1(str)

    //db table
    db.executeQuery(query)
    db.storeQuery(query)
    db.escapeString(str)
    db.escapeBlob(s, length)
    db.stringComparisonOperator()
    db.lastInsertId()

    //result table
    result.getDataInt(resId, s)
    result.getDataLong(resId, s)
    result.getDataString(resId, s)
    result.getDataStream(resId, s, length)
    result.next(resId)
    result.free(resId)

    //bit table
    #bit.cast
    bit.bnot(n)
    bit.band(type, n)
    bit.bor(type, n)
    bit.bxor(type, n)
    bit.lshift(type, n)
    bit.rshift(type, n)
    #bit.arshift
    #bit.ucast
    bit.ubnot(n)
    bit.uband(type, n)
    bit.ubor(type, n)
    bit.ubxor(type, n)
    bit.ulshift(type, n)
    bit.urshift(type, n)
    #bit.uarshift

    //compats
    table.getPos = table.find
    doSetCreatureDropLoot = doCreatureSetDropLoot
    doPlayerSay = doCreatureSay
    doPlayerAddMana = doCreatureAddMana
    playerLearnInstantSpell = doPlayerLearnInstantSpell
    doPlayerRemOutfit = doPlayerRemoveOutfit
    pay = doPlayerRemoveMoney
    broadcastMessage = doBroadcastMessage
    getPlayerName = getCreatureName
    getPlayerPosition = getCreaturePosition
    getCreaturePos = getCreaturePosition
    creatureGetPosition = getCreaturePosition
    getPlayerMana = getCreatureMana
    getPlayerMaxMana = getCreatureMaxMana
    hasCondition = getCreatureCondition
    isMoveable = isMovable
    isItemMoveable = isItemMovable
    saveData = saveServer
    savePlayers = saveServer
    getPlayerSkill = getPlayerSkillLevel
    getPlayerSkullType = getCreatureSkullType
    getCreatureSkull = getCreatureSkullType
    getAccountNumberByName = getAccountIdByName
    getIPByName = getIpByName
    getPlayersByIP = getPlayersByIp
    getThingfromPos = getThingFromPos
    getPlayersByAccountNumber = getPlayersByAccountId
    getIPByPlayerName = getIpByName
    getPlayersByIPNumber = getPlayersByIp
    getAccountNumberByPlayerName = getAccountIdByName
    convertIntToIP = doConvertIntegerToIp
    convertIPToInt = doConvertIpToInteger
    queryTileAddThing = doTileQueryAdd
    getTileHouseInfo = getHouseFromPos
    executeRaid = doExecuteRaid
    saveServer = doSaveServer
    cleanHouse = doCleanHouse
    cleanMap = doCleanMap
    shutdown = doShutdown
    mayNotMove = doCreatureSetNoMove
    doPlayerSetNoMove = doCreatureSetNoMove
    getPlayerNoMove = getCreatureNoMove
    getConfigInfo = getConfigValue
    doPlayerAddExp = doPlayerAddExperience
    isInArea = isInRange
    doPlayerSetSkillRate = doPlayerSetRate
    getCreatureLookDir = getCreatureLookDirection
    getPlayerLookDir = getCreatureLookDirection
    getPlayerLookDirection = getCreatureLookDirection
    doCreatureSetLookDir = doCreatureSetLookDirection
    getPlayerLookPos = getCreatureLookPosition
    setPlayerStamina = doPlayerSetStamina
    setPlayerPromotionLevel = doPlayerSetPromotionLevel
    setPlayerGroupId = doPlayerSetGroupId
    setPlayerPartner = doPlayerSetPartner
    setPlayerStorageValue = doPlayerSetStorageValue
    setPlayerBalance = doPlayerSetBalance
    doAddMapMark = doPlayerAddMapMark
    doSendTutorial = doPlayerSendTutorial

    //lua-made functions
    doPlayerGiveItem(cid, itemid, amount, subType)
    doPlayerTakeItem(cid, itemid, amount)
    doPlayerBuyItem(cid, itemid, count, cost, charges)
    doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
    doPlayerSellItem(cid, itemid, count, cost)
    doPlayerWithdrawMoney(cid, money)
    doPlayerDepositMoney(cid, money)
    comparePos(pos, posEx)
    isInRange(pos, fromPos, toPos)
    getArea(pos, rangeX, rangeY)
    isPremium(cid)
    getMonthDayEnding(day)
    getMonthString(m)
    getArticle(str)
    isNumber(str)
    getDistanceBetween(firstPosition, secondPosition)
    doPlayerAddAddons(cid, addon)
    isSorcerer(cid)
    isDruid(cid)
    isPaladin(cid)
    isKnight(cid)
    isRookie(cid)
    getDirectionTo(pos, posEx)
    getCreatureLookPosition(cid)
    getPosByDir(fromPosition, direction, size)
    doPlayerWithdrawAllMoney(cid)
    doPlayerDepositAllMoney(cid)
    doPlayerTransferAllMoneyTo(cid, target)
    doPlayerAddLevel(cid, amount, round)
    doPlayerAddMagLevel(cid, amount)
    doPlayerAddSkill(cid, amount)
    playerExists(name)
    getTibiaTime()
    doWriteLogFile(file, text)
    isInArea(pos, fromPos, toPos)
    getExperienceForLevel(lv)
    doMutePlayer(cid, time)
    getPlayerGroupName(cid)
    getPlayerVocationName(cid)
    getPromotedVocation(vid)
    doPlayerRemovePremiumDays(cid, days)
    getPlayerMasterPos(cid)
    getHouseOwner(houseId)
    getHouseName(houseId)
    getHouseEntry(houseId)
    getHouseRent(houseId)
    getHousePrice(houseId)
    getHouseTown(houseId)
    getHouseTilesCount(houseId)
    getItemNameById(itemid)
    getItemPluralNameById(itemid)
    getItemArticleById(itemid)
    getItemName(uid)
    getItemPluralName(uid)
    getItemArticle(uid)
    getItemText(uid)
    getItemSpecialDescription(uid)
    getItemWriter(uid)
    getItemDate(uid)
    getTilePzInfo(pos)
    getTileZoneInfo(pos)
    debugPrint(text)
    doShutdown()
    doSummonCreature(name, pos)
    getOnlinePlayers()
    getPlayerByName(name)
    isPlayerGhost(cid)
    getPlayerFrags(cid)
    getPartyLeader(cid)
    isInParty(cid)
    isPrivateChannel(channelId)
    doConvertIntegerToIp(int, mask)
    doConvertIpToInteger(int, mask)
    getBooleanFromString(str)
    doCopyItem(item, attributes)
    exhaustion.check(cid, storage)
    exhaustion.get(cid, storage)
    exhaustion.set(cid, storage, time)
    exhaustion.make(cid, storage, time)
    table.find(table, value)
    table.isStrIn(txt, str)
    table.countElements(table, item)
    table.getCombinations(table, num)
    string.split(str)
    string.trim(str)
    string.explode(str, sep)
 
And has exactly explaining of what does local mean on Part IV
PART IV -- Local and Global Statements...(What are they for? When shall I use them?)

Both statements look almost the same with the difference that you have to write

Code:
local test = 1 -- In order to use a local statement and
test = 1 -- To use the Global

There is not much difference between them if you write them but they make a huge difference...

"local" is used in order for just inside a Script and the "global" is used to be executed for every file depending on your server!

Let's say it like this, if you use an "local" statement (local word = hello) then if i would write "word" in a script it would be seen as "hello" but ONLY in this Script!
If I would use an "global" statement, then everytime I write "word" it would mean "hello".

Question: Why shall I even use local or global statements? Isn't it easier to just write in what you want?
Answer: No it isn't! it can save up a lot of time if you have to use same things twice or even more!

example:

We add that the player recovers 500 mana/hp

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1945 and getPlayerLevel(cid) >= 50 then
        doPlayerSendTextMessage(cid,21,"It works !")
        doTransformItem(item.uid, item.itemid + 1)
        doCreatureAddMana(cid,500)
        doCreatureAddHealth(cid,500)
    elseif item.itemid == 1946 and getPlayerLevel(cid) >= 50 then
        doPlayerSendTextMessage(cid,21,"You pulled it back!")
        doTransformItem(item.uid, item.itemid - 1)
        doCreatureAddMana(cid,500)
        doCreatureAddHealth(cid,500)
    else
        doPlayerSendCancel(cid,"You don't have the required level to use this.")
    end
    return TRUE
end

Seems fine...but what if I want to change the ammount to 750 now? I would have to edit every single number again...
This is basicly why we use local/global statements.

example:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local gain = 750
    if item.itemid == 1945 and getPlayerLevel(cid) >= 50 then
        doPlayerSendTextMessage(cid,21,"It works !")
        doTransformItem(item.uid, item.itemid + 1)
        doCreatureAddMana(cid,gain)
        doCreatureAddHealth(cid,gain)
    elseif item.itemid == 1946 and getPlayerLevel(cid) >= 50 then
        doPlayerSendTextMessage(cid,21,"You pulled it back!")
        doTransformItem(item.uid, item.itemid - 1)
        doCreatureAddMana(cid,gain)
        doCreatureAddHealth(cid,gain)
    else
        doPlayerSendCancel(cid,"You don't have the required level to use this.")
    end
    return TRUE
end

So if I would like to change the number now again I would just have to change the number behind the statement!
And the next 2 links are full online tutorials about LUA scripting and both works fine, if it doesn't load or seem to be dead its your connection because I am using these 2 links to understand LUA ATM
Last 2 links are full list of TFS 1.x abilities/functions (Which is the most updated/used ATM) and those functions will be used in scripting for your server.

Can't make a reply with more than 25k letters, That's why I needed to reply twice.
 
Local and function are two completely different keywords and have no relation.
Local defines the scope of the following variable or function.
A function is a chunk of code that can be called to be reused infinitely.
A local variable is only usable within the scope it is defined, same thing with a local function.
If there is no local in front of a variable or function, it is put in the global table _G.
Just read Programming in Lua if you really want to learn. Programming in Lua (first edition) (https://www.lua.org/pil/contents.html)

Last 2 links are full list of TFS 1.x abilities/functions (Which is the most updated/used ATM) and those functions will be used in scripting for your server.
The abilities I made were not part of official TFS, it requires a source edit and should not be referenced for a list of abilities in TFS.
 
Local and function are two completely different keywords and have no relation.
Local defines the scope of the following variable or function.
A function is a chunk of code that can be called to be reused infinitely.
A local variable is only usable within the scope it is defined, same thing with a local function.
If there is no local in front of a variable or function, it is put in the global table _G.
Just read Programming in Lua if you really want to learn. Programming in Lua (first edition) (https://www.lua.org/pil/contents.html)


The abilities I made were not part of official TFS, it requires a source edit and should not be referenced for a list of abilities in TFS.
You keep mentioning the word scope what is scope and what is a table and _G? Can you provide some examples? I don't have any experience with any of this. How do i go from reading that large book to working with the scripts?
 
You keep mentioning the word scope what is scope and what is a table and _G? Can you provide some examples? I don't have any experience with any of this. How do i go from reading that large book to working with the scripts?
There's no magical transition from reading that and working with scripts, all you need is programming basics and a general understanding of Lua to edit and create your own scripts in TFS.
 
The abilities I made were not part of official TFS, it requires a source edit and should not be referenced for a list of abilities in TFS.
Ah I didn't notice it was custom ones because I usually google for like TFS 1.3 "Functions/Attributes" etc, edited the main reply.
 
Took the time to write some basics for you <3 :

Usually when you see the word local in a script, its defining that word, so when you use that word later on in the script it will check what it actually means. Local is not something you have to use, but it just makes things easier and you dont have to write things all over all the time, its kinda like a shortcut to call either numbers or words. example
Lua:
 local teleportlocation = {x=1000, y=1000, z=1000}
now instead of actually writing the xyz coordinates directly into where you want it you can instead use teleportlocation
Like this

Lua:
 doTeleportThing(cid, teleportlocation)

This makes it easier for other people to edit scripts that are already made or change a lot of values all at once.

In order to make the script actually do something you need to define what functions are going to be used. Do you want it to happen when you pull a lever, or enter a certain tile? This basically "activates" the script and you have to attach it to either itemID, ActionID or UniqueID, this is ofc done in actions.xml

Example:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition) --- this describes the action of right clicking an item
local teleportlocation = {x=1000, y=1000, z=1000}
if getPlayerLevel(cid) >= 8 then --- if the player is equal or higher than 8 then
  doTeleportThing(cid, teleportlocation) --- teleports the player to the local teleportlocation
  end
end

If you dont have the local "config" there it would look like this:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition) --- this describes the action of right clicking or using an item
if getPlayerLevel(cid) >= 8 then --- if the player is equal or higher than 8 then
  doTeleportThing(cid, 1000, 1000, 7) --- teleports the player to the teleportlocation
  end
end

You should note that different tfs versions have different types of codes this type of code is for tfs 0.x, thats why some codes look different.
 
Last edited:
Took the time to write some basics for you <3 :

Usually when you see the word local in a script, its defining that word, so when you use that word later on in the script it will check what it actually means. Local is not something you have to use, but it just makes things easier and you dont have to write things all over all the time, its kinda like a shortcut to call either numbers or words. example
Lua:
 local teleportlocation = {x=1000, y=1000, z=1000}
now instead of actually writing the xyz coordinates directly into where you want it you can instead use teleportlocation
Like this

Lua:
 doTeleportThing(cid, teleportlocation)

This makes it easier for other people to edit scripts that are already made or change a lot of values all at once.

In order to make the script actually do something you need to define what functions are going to be used. Do you want it to happen when you pull a lever, or enter a certain tile? This basically "activates" the script and you have to attach it to either itemID, ActionID or UniqueID, this is ofc done in actions.xml

Example:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition) --- this describes the action of right clicking an item
local teleportlocation = {x=1000, y=1000, z=1000}
if getPlayerLevel(cid) >= 8 then --- if the player is equal or higher than 8 then
  doTeleportThing(cid, teleportlocation) --- teleports the player to the local teleportlocation
  end
end

If you dont have the local "config" there it would look like this:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition) --- this describes the action of right clicking or using an item
if getPlayerLevel(cid) >= 8 then --- if the player is equal or higher than 8 then
  doTeleportThing(cid, 1000, 1000, 7) --- teleports the player to the teleportlocation
  end
end

You should note that different tfs versions have different types of codes this type of code is for tfs 0.x, thats why some codes look different.
Yea but what is the significance of using local in front of this word? So is teleportlocation a shortcut to that thing on the right & why haven't you placed local again where you put teleportlocation? I appreciate the example but i am having a hard time following along. And why wasn't the thing on the right of teleportlocation added to doTeleportThing in the second example?
 
Yea but what is the significance of using local in front of this word? So is teleportlocation a shortcut to that thing on the right & why haven't you placed local again where you put teleportlocation? I appreciate the example but i am having a hard time following along. And why wasn't the thing on the right of teleportlocation added to doTeleportThing in the second example?
When you write
Lua:
local teleportlocation = {}
it means that the word "teleportloctation" is now a replacement for the thing that comes after it,
You are basically saying that teleportlocation EQUALS or is the same as {x=1000, y=1000, z=1000}
you could say that the word local enables you to use the word that comes after instead of having to write the extra "code".

If you dont have the word local in front, then it becomes a global value and thats just gonna make a mess
the word local binds it to that lua file only
Lua:
 teleportlocation = {}
Would also work, but it would probably not be wise to do so, if you are planning on using that same word again in another script.
 
Yea but what is the significance of using local in front of this word?
If you have 2 lua scripts (separated files):
  • config.lua
  • system.lua

Inside config.lua
Lua:
local CONFIG_VERSION = "1.0.0"
SYSTEM_CONFIG = {
    foo = "bar"
}

Inside system.lua
Lua:
dofile("config.lua")

function onStart()
    print("Config loaded" .. CONFIG_VERSION) -- failed, CONFIG_VERSION is local
    print("foo = " .. SYSTEM_CONFIG.foo) -- worked, SYSTEM_CONFIG is global
end

Same thing goes with functions. If you use local function foobar() then it's scoped only to the file it's inside.
 
When you write
Lua:
local teleportlocation = {}
it means that the word "teleportloctation" is now a replacement for the thing that comes after it,
You are basically saying that teleportlocation EQUALS or is the same as {x=1000, y=1000, z=1000}
you could say that the word local enables you to use the word that comes after instead of having to write the extra "code".

If you dont have the word local in front, then it becomes a global value and thats just gonna make a mess
the word local binds it to that lua file only
Lua:
 teleportlocation = {}
Would also work, but it would probably not be wise to do so, if you are planning on using that same word again in another script.
What does {} mean?
 
Empty array. Google for Lua tutorials. This thread will be 20 pages if you continue to ask such basic stuff.
I thought that is what support was for to ask questions?
{} This just means that its constructing a "table" and only the things inside this will be included.
Why does the person above you call it an array and you call it a table? Now I am really confused! lol
 
Status
Not open for further replies.
Back
Top