justn Posted August 22, 2014 Share Posted August 22, 2014 Hey guys I'm working on a script.. so when the player talks in the main chat.. if there's letters / words which is not english.. then it will output a error in the chatbox.. Link to comment
./BlackBird# Posted August 22, 2014 Share Posted August 22, 2014 addEventHandler("onPlayerChat",root, function (msg) for i 1,string.len(msg) if string.byte(string.sub(msg,i,i)) < 32 or string.byte(string.sub(msg,i,i)) > 127 then return cancelEvent() end end end ) Link to comment
justn Posted August 22, 2014 Author Share Posted August 22, 2014 This didn't help at all... did you read what i wanted? Link to comment
xXMADEXx Posted August 22, 2014 Share Posted August 22, 2014 This didn't help at all... did you read what i wanted? Actually that code is what you want, although it's a bit sloppy. Try using this, it should work. addEventHandler ( "onPlayerChat", root, function ( message ) for i=1, string.len ( message ) do local n = message:sub ( i, i ) if ( n:byte ( ) < 32 or n:byte ( ) > 127 ) then cancelEvent ( ) outputChatBox ( "English characters only...", source, 255, 0, 0 ) return; end end end ) Link to comment
tosfera Posted August 22, 2014 Share Posted August 22, 2014 This didn't help at all... did you read what i wanted? Actually that code is what you want, although it's a bit sloppy. Try using this, it should work. addEventHandler ( "onPlayerChat", root, function ( message ) for i=1, string.len ( message ) do local n = message:sub ( i, i ) if ( n:byte ( ) < 32 or n:byte ( ) > 127 ) then cancelEvent ( ) outputChatBox ( "English characters only...", source, 255, 0, 0 ) return; end end end ) In The Netherlands ( so Dutch ) we also use English letters... it's quite hard to actually make a script like that haha! Link to comment
xXMADEXx Posted August 22, 2014 Share Posted August 22, 2014 This didn't help at all... did you read what i wanted? Actually that code is what you want, although it's a bit sloppy. Try using this, it should work. addEventHandler ( "onPlayerChat", root, function ( message ) for i=1, string.len ( message ) do local n = message:sub ( i, i ) if ( n:byte ( ) < 32 or n:byte ( ) > 127 ) then cancelEvent ( ) outputChatBox ( "English characters only...", source, 255, 0, 0 ) return; end end end ) In The Netherlands ( so Dutch ) we also use English letters... it's quite hard to actually make a script like that haha! Well yes, a lot of Spanish does too. I actually don't think you can fully block other languages unless well you want to write an English dictionary in a table lol. I could be wrong though. Link to comment
justn Posted August 22, 2014 Author Share Posted August 22, 2014 Actually that code is what you want Ah... because when I tested his.. i said something arabic in chat . and it still worked I actually don't think you can fully block other languages unless well you want to write an English dictionary in a table lol. Hahah. I had that suggestion, but I don't think I wanna take a long time creating a english dictionary... __ @xXMADEXx: In your code, the event doesn't get cancelled Link to comment
tosfera Posted August 22, 2014 Share Posted August 22, 2014 Any help? What you can do, is try to fetch the google translate page ( or write a php script with an API if there is one ) and let it detect if it's English or not. Keep in mind that typos will be blocked too. so people with bad English won't be able to talk either! Link to comment
justn Posted August 22, 2014 Author Share Posted August 22, 2014 I'm currently using xXMADEXx's code.. But the 'cancelEvent( )' in his code doesn't get cancelled, that's what I need help fixing Link to comment
justn Posted August 22, 2014 Author Share Posted August 22, 2014 Someone can help me please? Link to comment
./BlackBird# Posted August 22, 2014 Share Posted August 22, 2014 MADE code works perfect, try stop freeroam if it's running Link to comment
justn Posted August 22, 2014 Author Share Posted August 22, 2014 cancelEvent() doesn't work.. and Freeroam is not running.. I edited his code a bit: addEventHandler ( "onPlayerChat", root, function ( message,messageType ) if ( messageType == 0 ) then for i=1, string.len ( message ) do local n = message:sub ( i, i ) if ( n:byte ( ) < 32 or n:byte ( ) > 127 ) then cancelEvent ( ) outputChatBox ( "#0075ff(Language): #FFFFFFMain chat is for #0075ffEnglish #FFFFFFonly !", source, 255, 0, 0,true ) return; end end end end) Link to comment
./BlackBird# Posted August 22, 2014 Share Posted August 22, 2014 your code works fine, maybe there are resource using onPlayerChat > cancelEvent > outputChatBox Link to comment
ALw7sH Posted August 22, 2014 Share Posted August 22, 2014 ithink u use supernick script ? try to stop it Link to comment
justn Posted August 22, 2014 Author Share Posted August 22, 2014 Yeah, it was because of supernick, I just added the code in the supernick script and now it works fine Thanks guys Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now