ID:166726
 
I am playing around with the idea of a text based game. Now the combat is turn based, but will go auto like a mud unless you call up another command.

I have a question about this though, say I want like a Fireball spell or something, I want it so players can type fireb or Fireball, or FiReB or something along those lines and they will still reconize it.

How would I go about doing that?
there are a few alternatives to that;

1) make the keyword for the command. ie the fireball's keyword would be fireb, if someone types that, ignore the rest of the message and do the command.

2)make use of client/Command and check for every possible combination of this command. a very painful activity. :(

i think a keyword would be the best solution.
I have a proc for that!
// Matches the input with the closest value in a list of words.
proc/MatchText(text, list/options)
text = lowertext(text)
for(var/cut = 2, cut <= lentext(text)+1, cut++)
for(var/word in options)
var/short_word = copytext(lowertext(word), 1, cut)
//world.log << "'[short_word]' of '[word]' in '[text]'"
if(findtext(short_word, text))
return word
return null


Here's how to try it out:
mob/verb/TestMatch(text as txt)
var/list/L = list("fireball", "vortex", "icebolt")
var/result = MatchText(text, L)
if(result)
src << "You selected [result]."
else
src << "Couldn't find a match."


You might also take a look at A Bunch of MUD Procs that I made a while ago. These were really designed for a telnet environment, though.