[Script] Schimbă culoarea mapei

Code:
tfm.exec.disableAfkDeath(true)

system.modes = {
    [1] = {math.random(0, 255), math.random(0, 255), math.random(0, 255)}
}
system.type = 1
system.grounds = {
    [0] = "C7A889";
    [1] = "C5D9E3";
    [2] = "654385";
    [3] = "B62B01";
    [4] = "662F11";
    [5] = "3E2312";
    [6] = "B0C51D";
    [7] = "F5E68B";
    [10] = "605A4C";
    [11] = "D5D6D6";
};

function eventNewGame()
mapAuthor = tfm.get.room.xmlMapInfo.author
    if mapAuthor ~= '#Module' then
        tfm.exec.disableAutoShaman(false)
        system.loadMap(tfm.get.room.xmlMapInfo.xml)
    else
        tfm.exec.disableAutoShaman(true)
        system.mapToLoad = true
        system.loadTime = os.time()*8000
    end
end

function string.split(stringt, sep)
    st = {}
    for str in stringt:gmatch("[^"..sep.."]+") do
        table.insert(st, str)
    end
    return st
end

function system.loadMap(xml)
    allgrounds = ""
    alljoints = ""
    alldecorations = ""
    grounds = xml:match("<S>(.+)</S>")
    xml = xml:gsub("<S>(.+)</S>", "<S>{allgrounds}</S>")
    joints = xml:match("<L>(.+)</L>")


    for object in grounds:gmatch("<S([^/>]+)/>") do
        objectType = object:match("T=\"([0-9]+)\"")+0
        color = object:match("o=\"([0-9A-Za-z]+)\"")
        if (color == nil) then
            color = system.grounds[objectType]
        end
        
        if (color and not object:find("m=") and string.len(color) <= 6 and color:upper() ~= "6A7495") then
            colort = system.applyColor(color, system.modes[system.type])
            if (objectType == 13) then
                allgrounds = allgrounds..string.format("<S %s o=\"%s\" />", object, colort)
            else
                if not (objectType == 9) then
                    allgrounds = allgrounds..string.format("<S %s o=\"%s\" T=\"12\" />", object, colort)
                else
                    allgrounds = allgrounds..string.format("<S %s />", object)
                end
            end
        else
            allgrounds = allgrounds..string.format("<S %s />", object)
        end
    end
    
    joints = xml:match("<L>(.+)</L>")
    if (joints ~= nil) then
        xml = xml:gsub("<L>(.+)</L>", "<L>{alljoints}</L>")
        for index, joint in ipairs(string.split(joints, "/>")) do
            if (joint:match("c=\"([0-9A-Za-z,]+)\"") ~= nil) then
                c = joint:match("c=\"([0-9A-Za-z,]+)\"")
                pr = ""
                prop = string.split(c, ",")
                newC = system.applyColor(prop[1], system.modes[system.type])
                prop[1] = newC
                for ind in pairs(prop) do
                    pr = pr..","..prop[ind]
                end
                pr = pr:sub(2, string.len(pr))
                jointA = joint
                joint = joint:gsub("c=\"([0-9A-Za-z,]+)\"","c=\""..pr.."\"")
            end
            alljoints = alljoints..joint.."/>"
        end
    end
    
    decorations = xml:match("<D>(.+)</D>")
    if (decorations ~= nil) then
        xml = xml:gsub("<D>(.+)</D>", "<D>{alldecorations}</D>")
        for index, decoration in ipairs(string.split(decorations, "/>")) do
            if (decoration:match("C=\"([0-9A-Za-z,]+)\"") ~= nil) then
                c = decoration:match("C=\"([0-9A-Za-z,]+)\"")
                pr = ""
                prop = string.split(c, ",")
                for ind, prt in pairs(prop) do
                    prop[ind] = system.applyColor(prt, system.modes[system.type])
                end
                
                for ind, prt in pairs(prop) do
                    pr = pr..","..prt
                end
                pr = pr:sub(2)
                decoration = decoration:gsub("C=\"([0-9A-Za-z,]+)\"","C=\""..pr.."\"")
            end
            alldecorations = alldecorations..decoration.."/>"
        end
    end   
    
    xml = xml:gsub("{allgrounds}", allgrounds)
    xml = xml:gsub("{alljoints}", alljoints)
    xml = xml:gsub("{alldecorations}", alldecorations)
    system.mapLoaded = true
    system.loadTime = os.time()
    system.mapToLoad = xml
end

function eventLoop(ct, tr)
    if (system.mapToLoad) then
        if (system.loadTime < os.time()-500) then
            tfm.exec.newGame(system.mapToLoad)
            system.mapToLoad = false
        end
    end
    dark = system.applyColor(system.gethex(system.modes[system.type]), {150, 150, 150})
    bright = system.applyColor(system.gethex(system.modes[system.type]), {200, 200, 200})
    ui.addTextArea(0, "", nil, 770, 370, 25, 25, "0x"..bright, "0x"..dark, 1, true)
end

function system.getrgb(hex,d)
    hex = hex:gsub("#","")
    while (string.len(hex) < 6) do
        hex = '0'..hex
    end
    if (d) then
        return {tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))}
    else
        return {r = tonumber("0x"..hex:sub(1,2)), g = tonumber("0x"..hex:sub(3,4)), b = tonumber("0x"..hex:sub(5,6))}
    end
end

function system.gethex(rgb)
    hex = ""
    for ind,st in ipairs(rgb) do
        st = string.format("%x", st)
        if (string.len(st) == 1) then
            st = "0"..st
        end
        hex = hex..st
    end
    return hex
end

function eventChatCommand(player, command)
    if (command:sub(0,3) == "rgb") then
        command = command:sub(5)
        if (command:find("%(") ~= nil and command:find("%)") ~= nil) then
            rgb = command:sub(command:find("%(")+1, command:find("%)")-1)
            rgb = string.split(rgb, ",")
            if (#rgb > 3) then
                print("Invalid RGB")
            else
                newHex = system.gethex(rgb)
                system.modes[system.type] = rgb
                print("HEX set: "..newHex)
            end
        else
            print("Invalid RGB")
        end
    elseif (command:sub(0,3) == "hex") then
        command = command:sub(5):gsub("#","")
        if (#command > 6) then
            print("Invalid HEX")
        else
            rgb = system.getrgb(command, true)
            system.modes[system.type] = rgb
            print("HEX set: "..command)
        end
    end
end

function system.applyColor(rawColor, mode)
    color = system.getrgb(rawColor)
    color.r = math.floor((color.r*mode[1])/255)
    color.g = math.floor((color.g*mode[2])/255)
    color.b = math.floor((color.b*mode[3])/255)
    hex = system.gethex({color.r, color.g, color.b})
    return hex
end

Comenzi :
!hex #culoare

Exemplu : !hex #FFB300

!rgb R (în lucru)
 
Top
"Dev-TR" theme by Soulzone