• Need case sensitive text help
    7 replies, posted
Hello there, I am using a RTD mod but I noticed its text finding capabilities is not case sensitive. Users either typing just: ! r t d [or NOTHING] Automatically roll the dice. How could I make it case sensitive? Here is the code: [lua] local function diceplayerSay(ply , text , teamonly , dead) if ply:Alive() then if text == "rtd" then dice:Roll(ply) end else ply:PrintMessage(HUD_PRINTTALK, "[RTD]You must be alive to use this command.") end end hook.Add("PlayerSay", "rtdcmd", diceplayerSay) concommand.Add("rtd", diceplayerSay) [/lua]
if text == "rtd" or text == "RTD" then?
use [b][url=http://wiki.garrysmod.com/?title=String.lower]String.lower [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] like this: [lua] if string.lower(text) == "rtd" then [/lua] that will lowercase whatever they typed in, so RtD becomes rtd, and RTD would be rtd, rTd would be rtd, and so on
Ah, now I see what he means. Sorry D:
No, what I meant was that even if they type: a simple exclamation mark, it still rolls the dice, or even types r or t or d, just one letter.
That doesn't make sense, that hook should be called after all text is entered, [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerSay]Gamemode.PlayerSay [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]. Add a print statement like [lua]print(tostring(ply) .. " said " .. text) [/lua] to the beginning of the hook to verify what is being passed to the hook.
I fixed it with: [lua]if string.sub(txt,1,4) == "!rtd" then[/lua]
-snip- [highlight](User was permabanned for this post ("Spammer" - Asaratha))[/highlight]
Sorry, you need to Log In to post a reply to this thread.