• 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 string manipulating

darkmu

Active Member
Joined
Aug 26, 2007
Messages
253
Solutions
1
Reaction score
45
Location
Paraná,Brazil
Would you like to know how I make a function get my mount's name from an item description?

TFS 1.X

1625180001136.png

Mount: Cavalinho by [ADM] Veteranos


but this name "Cavalinho" is dynamic or it can change always, is there a possibility?

I would only need to return the name "Cavalinho"
 
Last edited:
Solution
1. Cut 'Mount: '
2. Split string using pattern ' by '. Players must not be able to use lowercase ' by ' as part of their name (default in acc. makers).
Code:
-- 'string:split' from http://lua-users.org/wiki/SplitJoin
function string:split( inSplitPattern, outResults )
   if not outResults then
      outResults = { }
   end
   local theStart = 1
   local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
   while theSplitStart do
      table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
      theStart = theSplitEnd + 1
      theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
   end
   table.insert( outResults, string.sub( self, theStart ) )
   return outResults
end


--...

Laloomega

Looking for Client 10 DLL experienced member
Joined
Feb 28, 2011
Messages
82
Solutions
3
Reaction score
51
look for an item that has a description, copy and paste the code and add your own desc..
 
OP
OP
darkmu

darkmu

Active Member
Joined
Aug 26, 2007
Messages
253
Solutions
1
Reaction score
45
Location
Paraná,Brazil
look for an item that has a description, copy and paste the code and add your own desc..
I think I expressed myself wrong.

What I would like is to get the description of the item, but only the part written "Cavalinho", and the name "Cavalinho" is dynamic, that is, depending on the mount, the name in the description would change and I would have to get only the name .
 

Gesior.pl

Mega Noob&LOL 2012
Senator
Premium User
Joined
Sep 18, 2007
Messages
2,451
Solutions
51
Reaction score
1,999
Location
Poland
GitHub
gesior
1. Cut 'Mount: '
2. Split string using pattern ' by '. Players must not be able to use lowercase ' by ' as part of their name (default in acc. makers).
Code:
-- 'string:split' from http://lua-users.org/wiki/SplitJoin
function string:split( inSplitPattern, outResults )
   if not outResults then
      outResults = { }
   end
   local theStart = 1
   local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
   while theSplitStart do
      table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
      theStart = theSplitEnd + 1
      theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
   end
   table.insert( outResults, string.sub( self, theStart ) )
   return outResults
end


-- local description = item:getDescription()
local description = 'Mount: Cavalinho by [ADM] Veteranos'
print(description)
local noMountPart = string.sub(description, 8)
print(noMountPart)
local descriptionParts = noMountPart:split(' by ')
local playerName1 = descriptionParts[1]
local playerName2 = descriptionParts[2]
print('player one:', playerName1)
print('player two:', playerName2)
Tested on Lua: demo (https://www.lua.org/cgi-bin/demo)
 
Solution
Top