Jump to content

[REQ] : /setwritecollor - command


Recommended Posts

Hey everyone,

is it possible to create a command for admins to set the write - collor for the players and that this collor will be saved?

like this:

Noob : example1

DSC-L|Gr00vE[Ger] : /setcolor Noob red

Noob : example2

and it would be nice too, when the collors will be saved in a .xml file to reload it everytime when the player with the nick

joins :P ^^

thx if you can do that

Link to comment

Maybe it would be possible to bind players into a custom group (clans, crews, admins, moderators, banned and so on) which has an own color. For example all normal clients have a white/default name color and the groups have own. But the command looks so long, should be shorter.

In this example an admin is logged in and he is in the admin group (admin group color color: green). The color for the clan [ABC] is blue.

Player0815: Hey Admin123, I joined the [ABC] clan. Could you set me to the group now?

Admin123: /setgroup Player0815 [ABC]

Console: Player0815 has been setted to the [ABC] group by Admin123.

Player0815: Nice, thank you!

The command would be /setgroup

If the thing with the groups isn't possible it would be better if all clients can change their namecolor.

Example:

Player0815: /namecolor 3

Player0815: My name is red now :D !

The command would be /namecolor

Link to comment
function setPlayerTextColor(source, commandName, playerName, colR, colG, colB) 
    player = getPlayerFromNick(playerName) 
    setElementData(player, "colR", colR) 
    setElementData(player, "colG", colG) 
    setElementData(player, "colB", colB) 
end 
  
function onPlayerChat(message, messageType) 
    if messageType == 0 then 
        local playerName = getClientName(source) 
        local colR = getElementData(source, "colR") 
        local colG = getElementData(source, "colG") 
        local colB = getElementData(source, "colB") 
        outputChatBox(playerName .. ": " .. message, getRootElement(), colR, colG, colB) 
        cancelEvent() 
    end 
end 
  
function setData() 
    players = getElementsByType("player") 
    setElementData(players, "colR", 0) 
    setElementData(players, "colG", 0) 
    setElementData(players, "colB", 0) 
end 
  
addEventHandler("onPlayerChat", getRootElement(), onPlayerChat) 
addEventHandler("onPlayerJoin", getRootElement(), setData) 
addEventHandler("onResourceStart", getRootElement(), setData) 
  
addCommandHandler("setwritecollor", setPlayerTextColor) 

Something like that should work. Didn't test though. The command is /setwritecollor playerName r b g

Link to comment
Why not try debugging (debugscript 3) and post warnings, errors

Look at your cancelEvent... You messed up a bit. You made it so it cancels the Chat, even if you put stuff in -.-

Here is how to set the player's name.

root = getRootElement () 
  
function setPlayerWriteColor ( player, commandName, r, g, b ) 
setElementData (player, "colorr", r ) 
setElementData (player, "colorg", g ) 
setElementData (player, "colorb", b ) 
end 
addCommandHandler ("typecol", setPlayerWriteColor ) 
  
function chatOutput ( message, text ) 
    if text == 0 then 
        cancelEvent() 
        message = string.gsub(message, "#%x%x%x%x%x%x", "") 
        local r = getElementData ( player, "colorr" ) 
        local g = getElementData ( player, "colorg" ) 
        local b = getElementData ( player, "colorb" ) 
        local playername = getClientName ( player ) 
        outputChatBox ( playername..":#FFFFFF "..message, getRootElement(), r, g, b, true ) 
    end 
end 
addEventHandler ( "onPlayerChat", root, chatOutput ) 

Link to comment
You messed up a bit. You made it so it cancels the Chat, even if you put stuff in -.-

It's not that - your code is the same in that respect. I don't think it matters where the cancelEvent() occurs in the "if" block.

The problem probably lies in :

  
function setData() 
    players = getElementsByType("player") 
    setElementData(players, "colR", 0) 
    setElementData(players, "colG", 0) 
    setElementData(players, "colB", 0) 
end 
  

I think this needs to be a loop - I don't think you can set data for all players at once.

Link to comment

The issue I see for the actual text coloring it it would need to be hexadecimal... Unless you do like "..r..""..g..""..b.." and had the user input 00-FF values, although I am not sure if shorthand hex will work, such as #F00 for red.

I for one am NOT wanting to write a LUA script to convert 0-255 to 00-FF... Toooooo much code. DX

Link to comment
  
outputDebugString(string.format("%02x",69)) 
  

Doesn't take much to convert numbers to hex if that's what you're wanting to script.

Could you point me in the right direction ? =)

I thought I was ? AFAIK, part of what you wanted was to convert numerics to strings (for the coloured text). If so, string.format() is an easy way of doing this.

Link to comment
  
outputDebugString(string.format("%02x",69)) 
  

Doesn't take much to convert numbers to hex if that's what you're wanting to script.

Could you point me in the right direction ? =)

I thought I was ? AFAIK, part of what you wanted was to convert numerics to strings (for the coloured text). If so, string.format() is an easy way of doing this.

Oh haha. I thought more or less you meant that is how to do it and you had ahold of a script to already do it.

Link to comment

I'm having trouble comprehending what you're not getting here. There's no "script" because it's a two liner. You're right, it's a PITA to type hex in a chat string so find another solution. How about a simple string substitution like :

  
... 
message = string.gsub(message,"@1","#FF0000") 
... 
  

So "@1" becomes "#FF0000" (red) or similar.

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