Jump to content

Colors and name


DjMixCuma

Recommended Posts

I guess by colors on chat you mean HEX colors, e.g: #00FF00Hello #FF0000World, if so, then you can use this:

-- server side:

addEventHandler ( "onPlayerChat", root, 
    function ( msg, msgType ) 
        if ( msgType == 0 ) then 
            local r, g, b = getPlayerNametagColor ( source ) 
            outputChatBox ( getPlayerName ( source ) ..": #FFFFFF".. msg, root, r, g, b ) 
            cancelEvent ( ) 
        end 
    end 
) 

About blocking the nick changer, you can cancel the onPlayerChangeNick with cancelEvent.

Link to comment
I guess by colors on chat you mean HEX colors, e.g: #00FF00Hello #FF0000World, if so, then you can use this:

-- server side:

addEventHandler ( "onPlayerChat", root, 
    function ( msg, msgType ) 
        if ( msgType == 0 ) then 
            local r, g, b = getPlayerNametagColor ( source ) 
            outputChatBox ( getPlayerName ( source ) ..": #FFFFFF".. msg, root, r, g, b ) 
            cancelEvent ( ) 
        end 
    end 
) 

About blocking the nick changer, you can cancel the onPlayerChangeNick with cancelEvent.

I have this onPlayerChat, and i can use #00FF00 for example.

I'm blocking onPlayerChangeNick with cancelEvent and i cant see message but nick changing.

Link to comment

try this: Nick Cancel

addEventHandler("onPlayerChangeNick",root,function(oldN,newN) 
   cancelEvent(true,"Sorry, you can not change your nick.") --Cancel event 
   if (not wasEventCancelled()) then outputDebugString("Sorry, the event was not cancelled, please go back to the forums for more help") end --if even wasn't cancelled, output that it wasn't 
end) 

Edited by Guest
Link to comment
try this: Nick Cancel
addEventHandler("onPlayerChangeNick",root,function(oldN,newN) 
   cancelEvent("Sorry, you can not change your nick.") --Cancel event 
   if (not wasEventCancelled()) then outputDebugString("Sorry, the event was not cancelled, please go back to the forums for more help") end --if even wasn't cancelled, output that it wasn't 
end) 

NOt working. :/

Link to comment
Guest Guest4401

In jaysds1's code, he had bad argument in cancelEvent. 1st argument should had been bool, but it was string

bool cancelEvent ( [ bool cancel = true, string reason = "" ] ) 

Getting on topic, here's the working code :

addEventHandler("onPlayerChangeNick",getRootElement(), 
    function() 
        cancelEvent() 
    end 
) 

Link to comment
Guest Guest4401
addEventHandler( 'onPlayerChangeNick', root, cancelEvent ) 

Done ..

It doesn't work either, because then cancelEvent would have 1st argument of the player's old nick which is string. So bad argument.

Link to comment

I not understand

addEventHandler( 'onClientPlayerDamage', localPlayer, cancelEvent ) 

work perfectly but first argument is element ( attacker ).

addEventHandler( 'onPlayerChangeNick', root, cancelEvent ) 

not work, bad argument is string.

addEventHandler ( 'onVehicleStartEnter', root, cancelEvent ) 

not work, bad argument is player

Edited by Guest
Link to comment
Hi!

How to block using colors on chat and how to block changing name on game??

All the posts here doesn't block colors in chat...

For chat, use this: (server)

  
addEventHandler("onPlayerChat", getRootElement(), 
  
function (message, type) 
if type == 0 then --If it's main chat 
cancelEvent() --Message won't send 
local uncolored = string.gsub(message, "#%x%x%x%x%x%x", "") --Delete all HEX codes. 
local r, g, b = getPlayerNametagColor(source) 
outputChatBox(getPlayerName(source) .. ": #ffffff" .. uncolored, getRootElement(), r, g, b, true) --Send message manually 
outputServerLog("CHAT: "..getPlayerName(source)..": "..message) --Output to log manually 
end 
end) 
  

For changing the nick in-game, use: (server)

addEventHandler("onPlayerChangeNick", getRootElement(), 
  
function () 
cancelEvent() --Nick won't change. 
outputChatBox("Sorry, you can't change your nick!", source, 255,0,0) 
end) 

Link to comment
  • 1 month later...
Hi!

How to block using colors on chat and how to block changing name on game??

All the posts here doesn't block colors in chat...

For chat, use this: (server)

  
addEventHandler("onPlayerChat", getRootElement(), 
  
function (message, type) 
if type == 0 then --If it's main chat 
cancelEvent() --Message won't send 
local uncolored = string.gsub(message, "#%x%x%x%x%x%x", "") --Delete all HEX codes. 
local r, g, b = getPlayerNametagColor(source) 
outputChatBox(getPlayerName(source) .. ": #ffffff" .. uncolored, getRootElement(), r, g, b, true) --Send message manually 
outputServerLog("CHAT: "..getPlayerName(source)..": "..message) --Output to log manually 
end 
end) 
  

For changing the nick in-game, use: (server)

addEventHandler("onPlayerChangeNick", getRootElement(), 
  
function () 
cancelEvent() --Nick won't change. 
outputChatBox("Sorry, you can't change your nick!", source, 255,0,0) 
end) 

1. Chat not working, I can use colors.

2. TY!

Link to comment

(For the chat part)

try this:

addEventHandler("onPlayerChat",root,function(message, type) 
    if type == 0 then --If it's main chat 
        if(string.find(message,"#%x%x%x%x%x%x"))then 
            cancelEvent() --Message won't send 
            local uncolored = string.gsub(message, "#%x%x%x%x%x%x", "") --Delete all HEX codes. 
            local r, g, b = getPlayerNametagColor(source) 
            outputChatBox(getPlayerName(source) .. ": " .. uncolored,root, r, g, b,false) --Send message manually 
            outputServerLog("CHAT: "..getPlayerName(source)..": "..message) --Output to log manually 
        end 
    end 
end) 

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