Jump to content

Problem using a string function


TheMtaUser555

Recommended Posts

Nothing happens when I try this ( it's supposed to remove all the HEX code ):

addEventHandler('onPlayerChangeNick', root, 
    function(oldNick, newNick) 
        if string.find( newNick, '#%x%x%x%x%x%x') then 
            setPlayerName ( source, oldNick ) 
        end 
    end 
) 

I also tried to use gsub and then setPlayerName, put it spams the chatbox..

Any help would be appreciated

Link to comment
addEventHandler ( 'onPlayerChangeNick', root, 
    function ( oldNick, newNick ) 
        if string.find ( newNick, '#%x%x%x%x%x%x' ) then 
            outputChatBox ( "You can't use HEX codes.", source, 255, 0, 0 ) 
            cancelEvent ( ) 
        end 
    end 
) 

That'll not change the nick if new one has HEX codes, and it'll send a message to the player.

Link to comment
addEventHandler ( 'onPlayerChangeNick', root, 
    function ( oldNick, newNick ) 
        if string.find ( newNick, '#%x%x%x%x%x%x' ) then 
            outputChatBox ( "You can't use HEX codes.", source, 255, 0, 0 ) 
            cancelEvent ( ) 
        end 
    end 
) 

That'll not change the nick if new one has HEX codes, and it'll send a message to the player.

thanks, that worked. I tried using string.find before but it didn't work, I guess it was because I didn't cancel the event

Link to comment
addEventHandler ( 'onPlayerChangeNick', root, 
    function ( oldNick, newNick ) 
        if string.find ( newNick, '#%x%x%x%x%x%x' ) then 
            outputChatBox ( "You can't use HEX codes.", source, 255, 0, 0 ) 
            cancelEvent ( ) 
        end 
    end 
) 

That'll not change the nick if new one has HEX codes, and it'll send a message to the player.

thanks, that worked. I tried using string.find before but it didn't work, I guess it was because I didn't cancel the event

You might want to try mine, it removes HEX codes automatically.

Link to comment

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