Jump to content

[Aporte] Cambio de Color de TAG


Recommended Posts

Simplemente, Cambia de color tu tag.

Beneficioso para los nombres que se ponen sin color HEX, like: XtremeSeul54

--[[ 
//////////////////////////////////////// 
    SERVER SIDE 
    VENAD MINISCRIPT 
    ccolor.lua 
--//////////////////////////////////////// 
]] 
function ccolor (source, command, color, color2, color3) 
    if type(color) == 'number' then 
        if color <= 255 and color >= 0 then 
            if color2 ~= nil and type(color2) == 'number' then 
                if color3 ~= nil and type(color3) == 'number' then 
                    if color2 <= 255 and color2 >= 0 then 
                        if color3 <= 255 and color3 >= 0 then 
                        setPlayerNametagColor(source, tonumber(color), tonumber(color2), tonumber(color3)) 
                        outputChatBox("Ahora tu nombre es de este color",source, tonumber(color), tonumber(color2), tonumber(color3), true) 
                        else 
                        outputChatBox("Tu tercer color no es valido: "..tostring(color3), source, 255,0,0,true) 
                        end 
                    else 
                    outputChatBox("Tu segundo color no es valido: "..tostring(color2), source, 255,0,0,true) 
                    end 
                else 
                outputChatBox("Tu tercer color no es un numero: "..tostring(color3), source, 255,0,0,true) 
                end 
            else 
            outputChatBox("Tu segundo color no es un numero: "..tostring(color2), source, 255,0,0,true) 
            end 
        else 
        outputChatBox("Tu primer color no es valido: "..tostring(color), source, 255,0,0,true) 
        end 
    end 
    color = tostring(color) 
    if color == 'nil' then 
    outputChatBox("========COLORES DISPONIBLES====",source, 255,150,0,true) 
    outputChatBox("Recuerda poner \"/ccolor\" [Color] para cambiarlo", source, 255,150,0,true) 
    outputChatBox("{ rojo, naranja, verde, negro, blanco, lila, azul, gris, gris2, azul2", source, 255,150,0,true) 
    outputChatBox("amarillo} o usa \"/ccolor r g b\" para un color personalizado", source, 255,150,0,true) 
    elseif color == "rojo" then 
    local _ = setPlayerNametagColor(source, 255,0,0) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "naranja" then 
    local _ = setPlayerNametagColor(source, 255,150,0) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "verde" then 
    local _ = setPlayerNametagColor(source, 0,255,0) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "negro" then 
    local _ = setPlayerNametagColor(source, 0,0,0) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "blanco" then 
    local _ = setPlayerNametagColor(source, 255,255,255) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "lila" then 
    elseif color == "azul" then 
    local _ = setPlayerNametagColor(source, 0,0,255) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "gris" then 
    local _ = setPlayerNametagColor(source, 60,60,60) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "gris2" then 
    local _ = setPlayerNametagColor(source, 150,150,150) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "azul2" then 
    local _ = setPlayerNametagColor(source, 120,120,255) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == "amarillo" then 
    local _ = setPlayerNametagColor(source, 255,255,0) 
            if _ then 
            outputChatBox("has cambiado tu nombre al color: "..tostring(color), source, 10,255,10,true) 
            end 
    elseif color == color then 
    outputChatBox("Ese color no existe", source, 255,0,0,true) 
    end 
end 
addCommandHandler("ccolor", ccolor) 

Este es un script que usaba en mi servidor de forma privada, ovbiamente se puede mejorar y acepto las optimizaciones

Edited by Guest
Link to comment

Me hice mi propia versión 8)

 tColors = {  
    ["rojo"] =      {255,   0,      0}, 
    ["azul"] =      {0,     0,      255}, 
    ["naranja"] =   {255,   150,    0}, 
    ["verde"] =     {0,     255,    0}, 
    ["negro"] =     {0,     0,      0}, 
    ["blanco"] =    {255,   255,    255}, 
    ["gris"] =      {150,   150,    150}, 
    ["amarillo"] =  {255,   255,    0}, 
} 
  
function changeColor(player, command , R, G, B) 
        if isRGB( R, G, B) then 
            local R = tonumber(R) G = tonumber(G) B = tonumber(B) 
            setPlayerNametagColor(player, R, G, B) 
            outputChatBox("El color de tu nombre fue cambiado al de este mensaje.", player, R, G, B) 
        elseif decodeString(R) then 
            setPlayerNametagColor(player, decodeString(R)) 
            outputChatBox("El color de tu nombre fue cambiado al de este mensaje.", player, decodeString(R)) 
        else 
            outputChatBox("#00ff00Usa /"..command.." R G B #ffffffo el#ff0000 nombre del color, disponibles: ", player, 255, 255, 255, true) 
            printAvailableColours(player) 
        end 
end 
  
addCommandHandler("cColor",changeColor) 
  
function isRGB( R, G, B ) 
    if tonumber(R) and tonumber(G) and tonumber(B) then 
        R = tonumber(R) G = tonumber(G) B = tonumber(B) 
        return R >= 0 and R <= 255 and G >= 0 and G <= 255 and B >= 0 and B <= 255 
    else 
        return false 
    end 
end 
  
function decodeString(cName) 
    for index, value in pairs (tColors) do 
        while index == cName do 
            return value[1],value[2],value[3] 
        end 
    end      
end 
  
function printAvailableColours(player) 
        for index, value in pairs (tColors) do 
            outputChatBox(firstToUpper(index), player, decodeString(index)) 
        end 
end 
  
function firstToUpper(str) 
    return (str:gsub("^%l", string.upper)) 
end 
  

Link to comment
Hidden
Me hice mi propia versión 8)
 tColors = {  
    ["rojo"] =      {255,   0,      0}, 
    ["azul"] =      {0,     0,      255}, 
    ["naranja"] =   {255,   150,    0}, 
    ["verde"] =     {0,     255,    0}, 
    ["negro"] =     {0,     0,      0}, 
    ["blanco"] =    {255,   255,    255}, 
    ["gris"] =      {150,   150,    150}, 
    ["amarillo"] =  {255,   255,    0}, 
} 
  
function changeColor(player, command , R, G, B) 
        if isRGB( R, G, B) then 
            local R = tonumber(R) G = tonumber(G) B = tonumber(B) 
            setPlayerNametagColor(player, R, G, B) 
            outputChatBox("El color de tu nombre fue cambiado al de este mensaje.", player, R, G, B) 
        elseif decodeString(R) then 
            setPlayerNametagColor(player, decodeString(R)) 
            outputChatBox("El color de tu nombre fue cambiado al de este mensaje.", player, decodeString(R)) 
        else 
            outputChatBox("#00ff00Usa /"..command.." R G B #ffffffo el#ff0000 nombre del color, disponibles: ", player, 255, 255, 255, true) 
            printAvailableColours(player) 
        end 
end 
  
addCommandHandler("cColor",changeColor) 
  
function isRGB( R, G, B ) 
    if tonumber(R) and tonumber(G) and tonumber(B) then 
        R = tonumber(R) G = tonumber(G) B = tonumber(B) 
        return R >= 0 and R <= 255 and G >= 0 and G <= 255 and B >= 0 and B <= 255 
    else 
        return false 
    end 
end 
  
function decodeString(cName) 
    for index, value in pairs (tColors) do 
        while index == cName do 
            return value[1],value[2],value[3] 
        end 
    end      
end 
  
function printAvailableColours(player) 
        for index, value in pairs (tColors) do 
            outputChatBox(firstToUpper(index), player, decodeString(index)) 
        end 
end 
  
function firstToUpper(str) 
    return (str:gsub("^%l", string.upper)) 
end 
  

Presumido :lol:

Link to comment
Me hice mi propia versión 8)
 tColors = {  
    ["rojo"] =      {255,   0,      0}, 
    ["azul"] =      {0,     0,      255}, 
    ["naranja"] =   {255,   150,    0}, 
    ["verde"] =     {0,     255,    0}, 
    ["negro"] =     {0,     0,      0}, 
    ["blanco"] =    {255,   255,    255}, 
    ["gris"] =      {150,   150,    150}, 
    ["amarillo"] =  {255,   255,    0}, 
} 
  
function changeColor(player, command , R, G, B) 
        if isRGB( R, G, B) then 
            local R = tonumber(R) G = tonumber(G) B = tonumber(B) 
            setPlayerNametagColor(player, R, G, B) 
            outputChatBox("El color de tu nombre fue cambiado al de este mensaje.", player, R, G, B) 
        elseif decodeString(R) then 
            setPlayerNametagColor(player, decodeString(R)) 
            outputChatBox("El color de tu nombre fue cambiado al de este mensaje.", player, decodeString(R)) 
        else 
            outputChatBox("#00ff00Usa /"..command.." R G B #ffffffo el#ff0000 nombre del color, disponibles: ", player, 255, 255, 255, true) 
            printAvailableColours(player) 
        end 
end 
  
addCommandHandler("cColor",changeColor) 
  
function isRGB( R, G, B ) 
    if tonumber(R) and tonumber(G) and tonumber(B) then 
        R = tonumber(R) G = tonumber(G) B = tonumber(B) 
        return R >= 0 and R <= 255 and G >= 0 and G <= 255 and B >= 0 and B <= 255 
    else 
        return false 
    end 
end 
  
function decodeString(cName) 
    for index, value in pairs (tColors) do 
        while index == cName do 
            return value[1],value[2],value[3] 
        end 
    end      
end 
  
function printAvailableColours(player) 
        for index, value in pairs (tColors) do 
            outputChatBox(firstToUpper(index), player, decodeString(index)) 
        end 
end 
  
function firstToUpper(str) 
    return (str:gsub("^%l", string.upper)) 
end 
  

Presumido :lol:

Nah, sólo apliqué la idea de Castillo e intenté hacerlo un poco más eficiente :P

Link to comment
Hidden
function decodeString(cName) 
    for index, value in pairs (tColors) do 
        while index == cName do 
            return value[1],value[2],value[3] 
        end 
    end     
end 

Eso no es muy eficiente que digamos, ya que no hay necesidad de usar un loop.

Simplemente haces asi:

function decodeString ( cName ) 
    if ( tColors [ cName ] ) then 
        return unpack ( tColors [ cName ] ) 
    end 
  
    return false 
end 

Link to comment
function decodeString(cName) 
    for index, value in pairs (tColors) do 
        while index == cName do 
            return value[1],value[2],value[3] 
        end 
    end     
end 

Eso no es muy eficiente que digamos, ya que no hay necesidad de usar un loop.

Simplemente haces asi:

function decodeString ( cName ) 
    if ( tColors [ cName ] ) then 
        return unpack ( tColors [ cName ] ) 
    end 
  
    return false 
end 

Oh. No se me había ocurrido :P, gracias.

Link to comment
  • 2 weeks later...
Hidden

repeat until se usa para repetir un codigo hasta que la condicion sea 'true', por ejemplo, incrementar el valor de una variable, hasta que esta llegue a cierto numero. Por ejemplo:

local myVariable = 0 
  
repeat 
    outputChatBox ( "HELLO WORLD!" ) 
    myVariable = 1 
until ( myVariable == 1 ) 

El while se usa tambien para ejecutar un codigo, hasta que la condicion devuelva 'false'. Por ejemplo:

while true do 
    outputChatBox ( "HELLO WORLD!" ) 
end 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...