Jump to content

English Only ... #1


justn

Recommended Posts

Posted

Hey guys :P

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..

Posted
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 
) 

Posted
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 ) 

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

Posted
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.

Posted
Actually that code is what you want

Ah... because when I tested his.. i said something arabic in chat . and it still worked :P

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

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

Posted

I'm currently using xXMADEXx's code.. :P But the 'cancelEvent( )' in his code doesn't get cancelled, that's what I need help fixing :P

Posted

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) 

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...