• 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 Text parsing/detecting.

MappingFOR

Web Developer
Joined
Jul 12, 2010
Messages
35
Reaction score
0
Hello. Im making commands system, and i need help.
How to detect text in lua?

Somethink like preg_match() and explode() in PHP

local text = "add_experience(100,50)"
I have to detect that is add_experience function, and take all values as text[0] = 100, text[1] = 50.

Code:
if(?) then
split text for 100 and 50.
end
 
Do you mean string.explode?

example talkaction - storage.lua
Code:
function onSay(cid, words, param)
	local t = string.explode(param, ",")
	if(not t[2]) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.")
		return true
	end

	local tid = getPlayerByNameWildcard(t[1])
......
 
Yes! Great! [REP]
Now I must dectect that first letter combination is "add_experience".

is this a talkaction? such as..
Code:
!admin add_experience, Name, 50000
If so, using string explode can break the string up into a table. Then check for example 'if params[1] == "add_experience" then'. You can use other string functions for pattern matching or string searches if you want lua-users wiki: String Library Tutorial
 
Back
Top