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

TFS 1.X+ How to read a specific part of item description?

mano368

Senior Support Team Member
Staff member
Support Team
Joined
Sep 2, 2011
Messages
624
Solutions
42
Reaction score
271
Location
Brazil
TFS 1.5 by Nekiro <

How do I get my script to read a specific part of an item's description?

For example, I have a script that gives bonus equipment that has the description [MoveSpeed], but in that same description there are other words, and for this reason the script cannot recognize only [MovSpeed], since the sentence would be "This item has increased its [MovSpeed]". so how do i isolate the movespeed from the description and thus activate the bonus script?

Thanks for the help.
 
Solution
It will work but only for the first bonus matched in the string sequence
Lua:
local equips = {
    ["MovSpeed"] = {value = x},
    ["Hp"] = {value = x},
    ["Magic"] = {value = x}
}

local bonus = equips[item:getDescription():match("%[(%w+)%]")]
if bonus then
    -- code
end

To loop through all bonuses, string.gmatch is the one
Lua:
for bonus in item:getDescription():gmatch("%[(%w+)%]+") do
    if equips[bonus] then
        print(equips[bonus].value)
    end
end

Just an example, dont make code like that xD
you can use string match to find the ocurrence but I dont think I understand why would you want just the [MoveSpeed]
you can check if there is any text in brackets or just check if there is any "MoveSpeed" between brackets in text like

Lua:
local str = "you see a something. it has [MoveSpeed] and a bunch of stuff"

local moveSpeedByBracket = str:match('%[(%a+)%]')
print(moveSpeedByBracket) --- Output: MoveSpeed

local moveSpeedPlain = str:match('%[MoveSpeed%]')
print(moveSpeedPlain) --- Output: [MoveSpeed]
 
you can use string match to find the ocurrence but I dont think I understand why would you want just the [MoveSpeed]
you can check if there is any text in brackets or just check if there is any "MoveSpeed" between brackets in text like

Lua:
local str = "you see a something. it has [MoveSpeed] and a bunch of stuff"

local moveSpeedByBracket = str:match('%[(%a+)%]')
print(moveSpeedByBracket) --- Output: MoveSpeed

local moveSpeedPlain = str:match('%[MoveSpeed%]')
print(moveSpeedPlain) --- Output: [MoveSpeed]
Its to check buff names, with backets or without and then give the buff to a player, for exemple:
Lua:
local equips = {
["MovSpeed"] = {value = x},
["Hp"] = {value = x},
["Magic"] = {value = x}
}

local str = equips[item:getDescription()]
if str:match('%[(%a+)%]') then
-- script
end

it will work?
 
Its to check buff names, with backets or without and then give the buff to a player, for exemple:
Lua:
local equips = {
["MovSpeed"] = {value = x},
["Hp"] = {value = x},
["Magic"] = {value = x}
}

local str = equips[item:getDescription()]
if str:match('%[(%a+)%]') then
-- script
end

it will work?
I dont really know never tried something like that, let me check
Can you paste the full description of your item, so I dont have to test ingame
 
It will work but only for the first bonus matched in the string sequence
Lua:
local equips = {
    ["MovSpeed"] = {value = x},
    ["Hp"] = {value = x},
    ["Magic"] = {value = x}
}

local bonus = equips[item:getDescription():match("%[(%w+)%]")]
if bonus then
    -- code
end

To loop through all bonuses, string.gmatch is the one
Lua:
for bonus in item:getDescription():gmatch("%[(%w+)%]+") do
    if equips[bonus] then
        print(equips[bonus].value)
    end
end

Just an example, dont make code like that xD
 
Solution
It will work but only for the first bonus matched in the string sequence
Lua:
local equips = {
    ["MovSpeed"] = {value = x},
    ["Hp"] = {value = x},
    ["Magic"] = {value = x}
}

local bonus = equips[item:getDescription():match("%[(%w+)%]")]
if bonus then
    -- code
end

To loop through all bonuses, string.gmatch is the one
Lua:
for bonus in item:getDescription():gmatch("%[(%w+)%]+") do
    if equips[bonus] then
        print(equips[bonus].value)
    end
end

Just an example, dont make code like that xD
you can also use the string just one time and loop over with the lua regex pattern thats why I asked for the description but now I think I dont need it lol
 
solved by @Roddet in pm msg using
Lua:
 for bonus in item:getDescription():gmatch("%[(.-)%]+") do
because my bonuses have spaces like "Intricate Mana"

thank you @StreamSide for your help too
 
Back
Top