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

special description

Itutorial

Board Moderator
Staff member
Board Moderator
Joined
Dec 23, 2014
Messages
2,461
Solutions
68
Reaction score
1,123
What is the method for TFS 1.2 to set special description on a player? I have:

Code:
plyr = Player(player)
plyr:setSpecialDescription(desc)

Not working how does it need to be worded?
 
i dont have any function setSpecialDescription in my tfs 1.2 o_O

i think u need to do it like this
Code:
if thing:isCreature() then
    if thing:isMonster() then
        description = string.format("%s\nHP: %d / %d", description, thing:getHealth(), thing:getMaxHealth())
        description = string.format("%s\nEXP: %d", description, thing:getType():getExperience())
    end
end

one example from my player.lua inside the Player: onLook function
 
Can you explain the %s and %d....Also that isn't setting the description just creating a value for me to use.
 
What is the method for TFS 1.2 to set special description on a player? I have:

Code:
plyr = Player(player)
plyr:setSpecialDescription(desc)

Not working how does it need to be worded?
There is no function for a player, their is one but it is only for items, however you can create one.
You would need to convert std::string Player::getDescription(int32_t lookDistance) const to lua in Player.lua.
https://github.com/otland/forgotten...e2984d4b997f82d10769f205c/src/player.cpp#L205

And then create a new metamethod setSpecialDescription(desc) to work with the getDescription.
 
Can you explain the %s and %d....Also that isn't setting the description just creating a value for me to use.

%s gets all the from description, for example in this case that would be
16:56 You see a tortoise.
if I didn't include the %s this text would get removed but it would also allow me to for example change you see into another language

and the %d is the the value you pull from the function that is located after, for example thing:getHealth().

when i loot on monsters ingame it shows me this:

16:56 You see a tortoise.
HP: 185 / 185
EXP: 90

but if u explain us what u want to do, im sure i could help more since i suck at explaining


u could set different descriptions depending on storagevalue easily in the onlook function, i guess thats kinda what u want to do
for example, instead of using
player:setSpecialDesc

you instead give the player a storagevalue

if the player has the storagevalue

you just add smt like this
Code:
if thing:isCreature() then
    if thing:isPlayer() then
       if (thing:getStorageValue(storagenumber) >= 1) then
        description = string.format("%s\n some description", description)
    end
  end
end

^ I even tried that, and it should work like you want.
 
Last edited:
@Itutorial

description = string.format("%s\nHP: %d / %d", description, thing:getHealth(), thing:getMaxHealth())
description = string.format("%s\nEXP: %d", description, thing:getType():getExperience())

Result:

You see Xagul. He is a sorcerer. Level (100)
HP: 75/100
Experience: 123456789

Edit:
@Ahilphino
PFF >: ( my colors are still pretty >.>
 
@Itutorial

description = string.format("%s\nHP: %d / %d", description, thing:getHealth(), thing:getMaxHealth())
description = string.format("%s\nEXP: %d", description, thing:getType():getExperience())

Result:

You see Xagul. He is a sorcerer. Level (100)
HP: 75/100
Experience: 123456789

Edit:
@Ahilphino
PFF >: ( my colors are still pretty >.>

my explain sucks and this better xD
 
Alright guys help me figure out whats wrong with this script please

Code:
local boosts = {
[1] = {name = "boostEXP"},
[2] = {name = "stunReduction"},
[3] = {name = "dodge"},
[4] = {name = "magicFind"}
}

local skill_points = {
[1] = {name = "healing"},
[2] = {name = "spellDamage"},
[3] = {name = "defence"}
}

local acts = {
[1] = {name = "Act I"},
[2] = {name = "Act II"},
[3] = {name = "Act III"},
[4] = {name = "Act IV"},
[5] = {name = "Act V"}
}

local heritage = {
[0] = {name = "Lack of"},
[1] = {name = "Elvish"},
[2] = {name = "Orcish"},
[3] = {name = "Someother"}
}

function onLogin(player)
        plyr = Player(player)
      
        if not plyr then return false end
      
        local text = ""
  
        local HERIT = heritage[getPlayerHeritage(plyr)]
        local guild = "needs fixed"
        local rank = "This part too"
        local equipment_boost = "N/A"
      
        if plyr:getSex() == 1 then
        text = text.." He has a "..HERIT.name.." heritage.\n"
        text = text.."He belongs to the guild ["..guild.."] with the ranking ["..rank.."]\n"
        else
        text = text.." She has a "..heritage.." heritage.\n"
        text = text.."She belongs to the guild ["..guild.."] with the ranking ["..rank.."]\n"
        end
      
        text = text.."Equipment Boost:"..equipment_boost..""
      
        local count = 0
        for i = 1, #skill_points do
            if getPlayerSkillPoints(plyr, skill_points[i].name) > 0 then
                if count == 0 then
                    text = text.."\nSkill points: ["..getPlayerSkillPoints(plyr, skill_points[i].name).." "..skill_points[i].name.."] "
                    count = count + 1
                else
                    text = text.."["..getPlayerSkillPoints(plyr, skill_points[i].name).." "..skill_points[i].name.."] "
                end
            end
        end
      
        local count2 = 0
        for i = 1, #boosts do
            if getPlayerBoosts(plyr, boosts[i].name) > 0 then
                if count2 == 0 then
                    text = text.."\nBoosts: ["..getPlayerBoosts(plyr, boosts[i].name).." "..boosts[i].name.."] "
                    count2 = count2 + 1
                else
                    text = text.."["..getPlayerBoosts(plyr, boosts[i].name).." "..boost[i].name.."]"
                end
            end
        end
      
        local count3 = 0
        for i = 1, #acts do
            if getPlayerActCompletion(plyr, acts[i].name) > 0 then
                if count3 == 0 then
                    text = text.."\nAct completions: ["..getPlayerActCompletion(plyr, acts[i].name).." "..acts[i].name.."] "
                    count3 = count3 + 1
                else
                    text = text.."["..getPlayerActCompletion(plyr, acts[i].name).." "..acts[i].name.."]"
                end
            end
        end
      
  
        description = string.format("%s", description, text)
    return true
end

function getPlayerSkillPoints(player, skillType)
       local resultr, ret = db.storeQuery("SELECT `"..skillType.."` FROM `players` WHERE `id` = "..player:getAccountId()..";")
        ret = result.getDataInt(resultr,skillType)
        result.free(resultr)
        return ret
end

function getPlayerBoosts(player, boostType)
       local resultr, ret = db.storeQuery("SELECT `"..boostType.."` FROM `players` WHERE `id` = "..player:getAccountId()..";")
        ret = result.getDataInt(resultr,bostType)
        result.free(resultr)
        return ret
end

function getPlayerHeritage(player)
       local resultr, ret = db.storeQuery("SELECT `heritage` FROM `players` WHERE `id` = "..player:getAccountId()..";")
        ret = result.getDataInt(resultr,"heritage")
        result.free(resultr)
        return ret
end

function getPlayerActCompletion(player, act)
       local resultr, ret = db.storeQuery("SELECT `"..act.."` FROM `players` WHERE `id` = "..player:getAccountId()..";")
        ret = result.getDataInt(resultr,act)
        result.free(resultr)
        return ret
end

The error:
check.png
 
Ill try changing that but I dont believe that should be a problem

Yeah, that wasn't a problem in the script.

The code works. I tried just putting a broadcast in the game rather then the description and it runs all the way to the broadcast. So I just need the correct way to implement the information into the description.

The error is this code:

Code:
description = string.format("%s %d", description, text)
The error is that its trying to call a number but I am giving it a string. So how do I make it call a string rather then a number?
 
Last edited by a moderator:
Tried a combination on all of them... I'm not getting an error with the description anymore. But nothing is being changed.
 
The error is that its trying to call a number

This is your problem
description = string.format("%s %d", description, text)

It should be %s because both description and text are strings.

Edit:
I just read your code actually and even though I just answered your question, it still isn't going to fix your script...

You are trying to set the string "description" to include "text" but the problem is that the string "description" is not defined and/or used anywhere in the script you posted. I honestly have no clue wtf you are trying to do here.
 
Last edited:
How do you not know what I am trying to do if you read my code??? I am trying to add MORE INFO to the players description when he is looked at.... So instead of:
You see playername. he is a level * sorcerer.

Instead you will see:
You see playername. he is a level * sorcerer. He has a * heritage
Armor bonuses: blah blah blah
Skill_points: vblah blahb lah
boosts: blah blah blah
Act Completion: blah blah blah


Understand that? I thought description was calling the players description in that method.
 
onLogin is not the correct place to do this.

data>events>scripts>player.lua>
Code:
function Player:onLook(thing, position, distance)
Is where you want to implement that change.
 
How do you not know what I am trying to do if you read my code??? I am trying to add MORE INFO to the players description when he is looked at.... So instead of:
You see playername. he is a level * sorcerer.

Instead you will see:
You see playername. he is a level * sorcerer. He has a * heritage
Armor bonuses: blah blah blah
Skill_points: vblah blahb lah
boosts: blah blah blah
Act Completion: blah blah blah


Understand that? I thought description was calling the players description in that method.
Why the attitude?
Especially since @Xagul and the rest of us are trying to help you...

In 1.x the metamethod in player called onLook and onLookInBattleList, inside of these metamethod is another metamethod called getDescription with 1 parameter called distance which is a number.

If you want to effectively alter the description of the player, you would rewrite getDescription as a metamethod of player, since it is not defined outside the sources.

I will say this again to you, if you knew the lua language you would know how to read the code, but you don't.. I'd rather be negative and know the language then be positive and waste hours to days on 1 simple problem that would be resolved if I knew what the hell i was reading.
 
you would rewrite getDescription
The problem is that doing it in that way is much more complicated than it needs to be. This person is clearly new/inexperienced and so he should operate within the limits of LUA. With that said he should simply add to the end of getDescription when looking at a player and write it himself completely in LUA which he has already begun doing but just in the wrong place. It has to be done in onLook not onLogin, he was simply attempting the correct thing in the wrong place.

Example:
Code:
    local description = player:getDescription()
    if(customDescription) then
        description = description .."\nCustom Description: ".. customDescription
    end

P.S.
I read his post with an attitude in my head as well but I figured maybe english isn't his main language so he didn't mean it to sound that way. xD
 
CodeEx, If this were a 0.3.6 script i would be able to handle it no problem. I am not used to the 1.2x script system. So, forgive me for not spending all of my life on tibia scripting. I know what I am reading obviously. The script works, I am just stuck one one simple line of code. Don't act like I am completely lost.
 
CodeEx, If this were a 0.3.6 script i would be able to handle it no problem. I am not used to the 1.2x script system. So, forgive me for not spending all of my life on tibia scripting. I know what I am reading obviously. The script works, I am just stuck one one simple line of code. Don't act like I am completely lost.
I would think someone with "10 years scripting experience" would know even the basics of lua, 1.x and any distro made before uses the same language (lua), the only thing that has changed is the names of some of functions from distro to distro.
 
Back
Top