• 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 - Action] finding an unspecific value in description/name of item?

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I'm wondering if it's possible to find a value in the name/description of an item.

I.e.
"You see a sword [+X hp on click]"

And X are various values so I have to find the X value through a function, can this be done with string.find, and if so, how?

Thank you,
unknown666
 
If you want to find a number, use:
LUA:
local description = getItemAttribute(uid, 'description')
local result = description:find('%d+')
 
Thank you, exactly what I was looking for :)

edit:

How to make this work, so it remembers the value.
LUA:
function find()
local description = "an item [+420 hp]"
local result = description:find("%d+")
print(result)
end

##Fixed it :)

LUA:
local description = "an item [+115 hp]"
local p = 0
for s in description:gmatch("[%d+]") do 
if tonumber(s) ~= nil then
p = p .. '' .. tonumber(s)
end
end
if tonumber(p) > 0 then
print(tonumber(p))
else
print('0')
end
 
Last edited:
Back
Top