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

Solved Store and use last player message.

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
TFS 0.3.7

Trying to store last message of player and use it to determine next message by npc.
terrible example incoming..

Code:
elseif msgcontains(msg, "number") and talkState[talkUser] == 1 then
   selfSay("What number under 1000?", cid)
   talkState[talkUser] = 2
   local playerMessage = ""
elseif msgcontains(msg, "ANYTHING OTHER THEN A NUMBER") and talkState[talkUser] == 2 then
   selfSay("That is not an accepted number. Please choose a numeric number.", cid)

elseif msgcontains(msg, "Any numeric number over 1000") and talkState[talkUser] == 2 then
   selfSay("The number you have chosen is too high. Choose another.", cid)

elseif msgcontains(msg, "Any numeric number") and talkState[talkUser] == 2 then
   selfSay("The number you have chosen is ".. number ..".", cid)
   talkState[talkUser] = 3

I've been googling and searching around for a few hours and not having much luck figuring out what to search for to get this to work.

If anyone knows what I should be searching for, or would like to provide an example, I would definitely appreciate it. :oops:

Thanks!

Xikini
 
Last edited by a moderator:
msg is the message of the player.
To store it you can add it to a table.
For example:
Code:
local xmsg = {} -- add this above the function, like talkState
Then to store the msg.
Code:
xmsg[cid] = msg
Then you can use xmsg[cid] after that incase a player should say something else but still the old message should be used.

If you want to check if a message is a number or a specific one, you can use tonumber.
Code:
if tonumber(msg) then -- checks if the message is a number
Code:
if tonumber(msg) >= 1000 then -- checks if the number is 1000 or higher
 
Or you can use a regular expression
Code:
local msg = "You are 1001 times smarter than me"
local cid = 1
local xmsg = {}
xmsg[cid] = msg
-- this will check if the string contains a number and if it does retrieve the portion that is a number string
-- and convert it to a real number to compare it to 1000
if tonumber( string.match(xmsg[cid], '[0-9]+') ) >= 1000 then
   print(msg)
end
-- output : You are 1001 times smarter than me

To learn about patterns in lua
http://lua-users.org/wiki/PatternsTutorial

Cool I just found this site, I'm gonna read it myself :)
This will teach you about regular expressions.
http://regexone.com/
 
Last edited:
Back
Top