• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

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

mano368

Well-Known Member
Joined
Sep 2, 2011
Messages
235
Solutions
30
Reaction score
99
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

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,574
Solutions
50
Reaction score
1,183
Location
Arica - Chile
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]
 
OP
OP
M

mano368

Well-Known Member
Joined
Sep 2, 2011
Messages
235
Solutions
30
Reaction score
99
Location
Brazil
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?
 

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,574
Solutions
50
Reaction score
1,183
Location
Arica - Chile
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
 

Roddet

Boo!
Premium User
Joined
May 1, 2013
Messages
684
Solutions
70
Reaction score
432
Location
Mexico
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

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,574
Solutions
50
Reaction score
1,183
Location
Arica - Chile
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
 
Top