Jump to content

SOLVED(string.gsub)


Karoffe

Recommended Posts

Posted

you can use gsub to replace something in a centain word or sentence, let say the players name for roleplay servers;

local name = "angelica_mitten":gsub ( "_", " " ) 

This will replace _ with a space, transforming Angelica_Mitten into Angelica Mitten. You can use this as a bad word filter too. :) read all about it on the lua wiki; http://lua-users.org/wiki/StringLibraryTutorial

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

Posted

Firstly if i am going to change everyone's name entering the server if he has a "_" to "" then how can i even check if he has "_", secondly how to apply this example on many typing characters, for example if i want to avoid everyone from typing numbers in mainchat ?

Posted

Well, the function itself already checks if there is a _ in the given string. So don't worry about that, you should rename players without the underscore. Just remove it while typing etc. To remove numbers you can use the parameter %W like this;

local name = name:gsub ( "%W", "" ); 

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

Posted

Well, actually i wanted if someone changing his nick to something that contains numbers then a gui shows telling him that he couldn't change his nick to that name. i wanted gsub to automatically change it without numbers

So, how to check the entered nick if it contains numbers or not(without changing it)

Posted
function containsNumber ( str ) 
    if str:find ( "%d" ) then 
        return true 
    end 
    return false 
end 

Owner of [HUN]Magyar Play Szerver 1.4, IP: 31.220.43.153:22003

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...