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

Lua Special Description on look player

Mr Erimyth

Member
Joined
Apr 8, 2009
Messages
163
Reaction score
11
Location
Brazil
Hello ... Anyone can help me ? i using Tfs 1.3

I need make system Special description on look.

Exemple, player get storage XXXXXXX
If Player have this storage win a new description on Look.

Storage: 14960 - Description on look: Scout of Tibia
Storage: 14961 - Description on look: Sentinel of Tibia
Storage: 14962 - Description on look: Steward of Tibia
Storage: 14963 - Description on look: Warden of Tibia
Storage: 14964 - Description on look: Squire of Tibia
Storage: 14965 - Description on look: Warrior of Tibia
Storage: 14966 - Description on look: Keeper of Tibia
Storage :14967 - Description on look: Guardian of Tibia
Storage: 14968 - Description on look: Sage of Tibia
 
Solution
This thread should be in "Requests".

Add to data\events\scripts\player.lua:

Lua:
local titles = {
    {storageID = 14960, title = "Scout"},
    {storageID = 14961, title = "Sentinel"},
    {storageID = 14962, title = "Steward"},
    {storageID = 14963, title = "Warden"},
    {storageID = 14964, title = "Squire"},
    {storageID = 14965, title = "Warrior"},
    {storageID = 14966, title = "Keeper"},
    {storageID = 14967, title = "Guardian"},
    {storageID = 14968, title = "Sage"},
}

local function getTitle(uid)
    local player = Player(uid)
    if not player then return false end
  
    for i = #titles, 1, -1 do
        if player:getStorageValue(titles[i].storageID) == 1 then
            return titles[i].title
        end
    end...
This thread should be in "Requests".

Add to data\events\scripts\player.lua:

Lua:
local titles = {
    {storageID = 14960, title = "Scout"},
    {storageID = 14961, title = "Sentinel"},
    {storageID = 14962, title = "Steward"},
    {storageID = 14963, title = "Warden"},
    {storageID = 14964, title = "Squire"},
    {storageID = 14965, title = "Warrior"},
    {storageID = 14966, title = "Keeper"},
    {storageID = 14967, title = "Guardian"},
    {storageID = 14968, title = "Sage"},
}

local function getTitle(uid)
    local player = Player(uid)
    if not player then return false end
  
    for i = #titles, 1, -1 do
        if player:getStorageValue(titles[i].storageID) == 1 then
            return titles[i].title
        end
    end
    return false
end

Add inside function "Player:eek:nLook" (also player.lua file):

Lua:
local title = getTitle(thing.uid)
if title then description  = description  .. title .. " of Tibia." end
 
Solution
@Frija Dont work :(

20:58 The storage with id: 14960 from player ratazana is: 1.

20:58 You see Ratazana (Level 1). He has no vocation.
Health: 150 / 150.
 
Last edited:
Move
Lua:
local title = getTitle(thing.uid)
if title then description  = description  .. title .. " of Tibia." end
before line nr. 158 "self:sendTextMessage(MESSAGE_INFO_DESCR, description)"
 
@Mr Erimyth , @Frija
This script show on your character "You are " + title and other character show "She is " + title or "He is " + title (function: thing:getSex() )

Lua:
local title = getTitle(thing.uid)
if distance == 1 then
if thing:getSex() == 0 then
if title then description = description  .. " She is " .. title .. " of Tibia." end
else
if title then description = description  .. " He is " ..title .. " of Tibia." end
end
else
if title then description = description  .. " You are " .. title .. " of Tibia." end
end
 
Last edited:
It would be better to use just one single storage value for all this titles. It is more optimized, and doesn't use useless memory.

Like this:
Code:
local storageID = 14960
local titles = {
    [1] = "Scout",
    [2] = "Sentinel",
    [3] = "Steward",
    [4] = "Warden",
    [5] = "Squire",
    [6] = "Warrior",
    [7] = "Keeper",
    [8] = "Guardian",
    [9] = "Sage"
}

local function getTitle(cid)
    local player = Player(cid)
    if not player then return "" end

    local value = player:getStorageValue(storageID)
    if(value == -1 or not titles[value]) then
        return ""
    end
  
    return titles[value]
end

It also returns empty string when title is not yet set, so you can use it in strings concentrate. Not sure how it worked before with return false, but maybe some lua notice?
 
It would be better to use just one single storage value for all this titles. It is more optimized, and doesn't use useless memory.

Like this:
Code:
local storageID = 14960
local titles = {
    [1] = "Scout",
    [2] = "Sentinel",
    [3] = "Steward",
    [4] = "Warden",
    [5] = "Squire",
    [6] = "Warrior",
    [7] = "Keeper",
    [8] = "Guardian",
    [9] = "Sage"
}

local function getTitle(cid)
    local player = Player(cid)
    if not player then return "" end

    local value = player:getStorageValue(storageID)
    if(value == -1 or not titles[value]) then
        return ""
    end
 
    return titles[value]
end

It also returns empty string when title is not yet set, so you can use it in strings concentrate. Not sure how it worked before with return false, but maybe some lua notice?

I'll check tommorow. I have a question to this ... Where to add bonus skill?
Loyalty System

I checked it and change the code to work
Lua:
local storageID = 14960
local titles = {
    [1] = "Scout",
    [2] = "Sentinel",
    [3] = "Steward",
    [4] = "Warden",
    [5] = "Squire",
    [6] = "Warrior",
    [7] = "Keeper",
    [8] = "Guardian",
    [9] = "Sage"
}
local function getTitle(cid)
    local player = Player(cid)
    if not player then return false end
    local value = player:getStorageValue(storageID)
    if(value == -1 or not titles[value]) then
        return false
    end
    return titles[value]
end
 
Last edited by a moderator:
I'll check tommorow. I have a question to this ... Where to add bonus skill?
Loyalty System
Maybe this will be helpful.
Lua:
-- this goes inside of player.lua
loyaltyStorage = 14960
titles = {
    [50] = "Scout",
    [100] = "Sentinel",
    [200] = "Steward",
    [400] = "Warden",
    [1000] = "Squire",
    [2000] = "Warrior",
    [3000] = "Keeper",
    [4000] = "Guardian",
    [5000] = "Sage"
}

function Player:getTitle(cid)
    if self:getId() ~= cid then
        return ""
    end
  
    local value = self:getStorageValue(loyaltyStorage)
    if(value == -1 or not titles[value]) then
        return ""
    end
    return "\nThe " .. titles[value] .. " of Tibia.\n"
end
--[[
    used in scripts
    player:setLoyaltyPoints(value)
    where value is one of index's of titles
]]
function Player:setLoyaltyPoints(value)
    if title[value] and value ~= self:getStorageValue(loyaltyStorage)then
        self:setStorageValue(loyaltyStorage, value)
    end
end
--[[
    used in scripts
    player:getLoyaltyPoints()
    returns the current loyalty point value
    if none is set then it returns 0
]]
function Player:getLoyaltyPoints()
    local points = self:getStorageValue(loyaltyStorage)
    return points > 0 and points or 0
end

function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance) .. self:getTitle(thing.uid)

I just looked over the wiki and realized I really didn't understand how the loyalty system worked initially. The code above might be useless :(
 
Last edited:
Maybe this will be helpful.
Lua:
-- this goes inside of player.lua
loyaltyStorage = 14960
titles = {
    [50] = "Scout",
    [100] = "Sentinel",
    [200] = "Steward",
    [400] = "Warden",
    [1000] = "Squire",
    [2000] = "Warrior",
    [3000] = "Keeper",
    [4000] = "Guardian",
    [5000] = "Sage"
}

function Player:getTitle(cid)
    if self:getId() ~= cid then
        return ""
    end
 
    local value = self:getStorageValue(loyaltyStorage)
    if(value == -1 or not titles[value]) then
        return ""
    end
    return "\nThe " .. titles[value] .. " of Tibia.\n"
end
--[[
    used in scripts
    player:setLoyaltyPoints(value)
    where value is one of index's of titles
]]
function Player:setLoyaltyPoints(value)
    if title[value] and value ~= self:getStorageValue(loyaltyStorage)then
        self:setStorageValue(loyaltyStorage, value)
    end
end
--[[
    used in scripts
    player:getLoyaltyPoints()
    returns the current loyalty point value
    if none is set then it returns 0
]]
function Player:getLoyaltyPoints()
    local points = self:getStorageValue(loyaltyStorage)
    return points > 0 and points or 0
end

function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance) .. self:getTitle(thing.uid)

I just looked over the wiki and realized I really didn't understand how the loyalty system worked initially. The code above might be useless :(

This code adds only the title, but does not give bonus skills. I modified this code to export point values to config.lua and add them automatically after logging in if the loyalty lines are greater than in config.lua
 
Could anybody script it so that when a player looks another player, it gets the townID and say something like:
You see Bubble. She is a citizen of getTownID
Im using TFS 1.2
Thanks!
 
Could anybody script it so that when a player looks another player, it gets the townID and say something like:
You see Bubble. She is a citizen of getTownID
Im using TFS 1.2
Thanks!
You should really start making your own threads instead of bumping old one's. lol

add into the regular onLook function
data/events/scripts/player.lua
Lua:
function Player:onLook(thing, position, distance)
Add after
Lua:
local description = "You see " .. thing:getDescription(distance)
the following code
Lua:
if thing:isPlayer() then
    description = description .. (thing:getSex() == PLAYERSEX_FEMALE and " She" or " He") .. " is a citizen of " .. thing:getTown():getName() .. "."
end
 
It works, but I might as weel need to fix this:

14:05 You see yourself. You are a knight. He is a citizen of Town1.

any ideas?

Also Im trying to get the players bank balance when Im in a god but It's not working, im using this:

if thing:isPlayer() then
description = string.format("%s\nBank Balance: %s.", description, (thing:getBankBalance()))
end
 
Last edited:
It works, but I might as weel need to fix this:

14:05 You see yourself. You are a knight. He is a citizen of Town1.
how is your town name on map editor? CTRL+T

Also Im trying to get the players bank balance when Im in a god but It's not working, im using this:

if thing:isPlayer() then
description = string.format("%s\nBank Balance: %s.", description, (thing:getBankBalance()))
end
any error on console? and post your full Player:eek:nLook function here using [.code] tags
 
I replaced the original name of my town with Town1.
The issue is that when the player looks on himself it should say: "You are a citizen of cityname" instead of He/She.


Lua:
function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance)
    if thing:isPlayer() then
    description = description .. (thing:getSex() == PLAYERSEX_FEMALE and " She" or " He") .. " is a citizen of " .. thing:getTown():getName() .. "."
end
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInBattleList(creature, distance)
    local description = "You see " .. creature:getDescription(distance)
    if self:getGroup():getAccess() then
        local str = "%s\nHealth: %d / %d"
        if creature:getMaxMana() > 0 then
            str = string.format("%s, Mana: %d / %d", str, creature:getMana(), creature:getMaxMana())
        end
        description = string.format(str, description, creature:getHealth(), creature:getMaxHealth()) .. "."

        local position = creature:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if creature:isPlayer() then
            description = string.format("%s\nIP: %s", description, Game.convertIpToString(creature:getIp()))
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
 
I replaced the original name of my town with Town1.
The issue is that when the player looks on himself it should say: "You are a citizen of cityname" instead of He/She.


Lua:
function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance)
    if thing:isPlayer() then
    description = description .. (thing:getSex() == PLAYERSEX_FEMALE and " She" or " He") .. " is a citizen of " .. thing:getTown():getName() .. "."
end
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInBattleList(creature, distance)
    local description = "You see " .. creature:getDescription(distance)
    if self:getGroup():getAccess() then
        local str = "%s\nHealth: %d / %d"
        if creature:getMaxMana() > 0 then
            str = string.format("%s, Mana: %d / %d", str, creature:getMana(), creature:getMaxMana())
        end
        description = string.format(str, description, creature:getHealth(), creature:getMaxHealth()) .. "."

        local position = creature:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if creature:isPlayer() then
            description = string.format("%s\nIP: %s", description, Game.convertIpToString(creature:getIp()))
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
Lua:
description = description .. (self == thing and "You are" or (thing:getSex() == PLAYERSEX_FEMALE and " She is" or " He is")) .. " a citizen of " .. thing:getTown():getName() .. "."
 
Back
Top