LUA [NL] Sigma (Mutli Colored) hitlogs

  • 287
  • 42
Если найдете, какой-либо баг, пишите в тему, он будет исправлен в ближайшее время

unknown.png

Hitlogs:
--[[
    @region: script information
    * @ Hitlogs.
    * @ Created by shelzy#6665.
    * @ Version: 1.0.0
    @endregion
]]

local hitlogs = {data = {}}
local add = {x = 0, y = 0}




--- @region: font
local font = {}

font.verdana11 = {}
font.verdana11.size = 11
font.verdana11.init = Render.InitFont("Verdana", font.verdana11.size, {"r"})
--- @endregion




--- @region: menu elements
local ui = {
    hit_color = Menu.ColorEdit("Settings", "Hit color", Color.new(0.6, 1, 0, 1)),
    miss_color = Menu.ColorEdit("Settings", "Miss color", Color.new(1, 0, 0, 1)),
    test_log = Menu.Button("Main", "Test log")
}
--- @endregion




--- @region: animation helpers
local anim = {}
local animation_handler = {data = {}}
animation_handler.lerp = function(start, end_pos, time)
    time = GlobalVars.frametime * (time * 175)
    if time < 0 then
      time = 0.01
    elseif time > 1 then
      time = 1
    end

    if type(start) == "userdata" then
        local color_data = {0, 0, 0, 0}

        for v, k in ipairs({"r", "g", "b", "a"}) do
            color_data[v] = animation_handler.lerp(start[k], end_pos[k], time)
        end

        return Color.new(unpack(color_data))
    end

    if (math.abs(start-end_pos) < (delta or 0.01)) then return end_pos end

    return ((end_pos - start)*time +start)
end

animation_handler.new = function(name, value, time)
    if animation_handler.data[name] == nil then
        animation_handler.data[name] = value
    end

    animation_handler.data[name] = animation_handler.lerp(animation_handler.data[name], value, time)

    return animation_handler.data[name]
end
--- @endregion




--- @region: render helpers
Render.MultiColorText = function(data, x, y)
    local total_width = 0
    local width = 0

    for _, v in pairs(data) do
        local text_width = Render.CalcTextSize(v[1], font.verdana11.size, font.verdana11.init).x
        total_width = total_width + text_width
    end

    for _, v in ipairs(data) do
        local text_width = Render.CalcTextSize(v[1], font.verdana11.size, font.verdana11.init).x
        local x2 = (x - total_width / 2 + width)


        Render.Text(v[1], Vector2.new(x2+1, y+1), Color.new(0, 0, 0, v[2].a), font.verdana11.size, font.verdana11.init)
        Render.Text(v[1], Vector2.new(x2, y), v[2], font.verdana11.size, font.verdana11.init)
        width = width + text_width
    end
end
--- @endregion




--- @region: reasons & hitboxes
hitlogs.reasons = {"hit", "resolver", "spread", "occlusion",  "prediction error"}
hitlogs.hitbox = {"head", "chest", "stomach", "left arm", "right arm", "left leg", "right leg", "neck", "?", "gear"}
--- @endregion




--- @region: test log
local test_reason = 0
hitlogs.test_log = function()
    local health = math.random(1, 200)
    test_reason = test_reason + 1
    if test_reason%2 == 1 then
        table.insert(hitlogs.data, {
            {
                "Hit ",
                Cheat.GetCheatUserName(),
                " in the ",
                hitlogs.hitbox[math.random(1, 10)],
                " for ",
                tostring(health),
                " damage (",
                tostring(math.max(0, 100-health)),
                " health remaining)",
            },
            alpha = 0,
            alpha1 = 0,
            time = GlobalVars.realtime,
            color = ui.hit_color:Get(),
        })
    else
        table.insert(hitlogs.data, {
            {
                "Missed ",
                Cheat.GetCheatUserName(),
                " in the ",
                hitlogs.hitbox[math.random(1, 10)],
                " due to ",
                hitlogs.reasons[math.random(2, 4)],
                " (",
                tostring(math.random(0, 100)),
                "% hitchance)",
            },
            alpha = 0,
            alpha1 = 0,
            time = GlobalVars.realtime,
            color = ui.miss_color:Get(),
        })
    end
end
ui.test_log:RegisterCallback(hitlogs.test_log)
--- @endregion




--- @region: registered_shot
hitlogs.on_registered_shot = function(shot)
    local name = EntityList.GetPlayer(shot.target_index):GetName() or "?"
    local reason = hitlogs.reasons[shot.reason]
    local hitbox = hitlogs.hitbox[shot.hitgroup] or "?"
    local hitchance = math.floor(shot.hitchance + 0.5)
    local wanted_hitbox = hitlogs.hitbox[shot.wanted_hitgroup] or "?"
    local health_remaining = math.max(0, (EntityList.GetPlayer(shot.target_index):GetProp("m_iHealth")-shot.damage))

    if shot.reason == 0 then
        table.insert(hitlogs.data, {
            {
                "Hit ",
                tostring(name),
                " in the ",
                tostring(hitbox),
                " for ",
                tostring(shot.damage),
                " damage (",
                tostring(health_remaining),
                " health remaining)",
            },
            alpha = 0,
            alpha1 = 0,
            time = GlobalVars.realtime,
            color = ui.hit_color:Get(),
        })
    else
        table.insert(hitlogs.data, {
            {
                "Missed ",
                tostring(name),
                " in the ",
                tostring(wanted_hitbox),
                " due to ",
                tostring(reason),
                " (",
                tostring(hitchance),
                "% hitchance)",
            },
            alpha = 0,
            alpha1 = 0,
            time = GlobalVars.realtime,
            color = ui.miss_color:Get(),
        })
    end
end
--- @endregion




--- @region: draw
hitlogs.on_draw = function()
    local sc = EngineClient.GetScreenSize()
    local x, y = sc.x/2, sc.y/1.1
    add.y = 0
    for k, v in ipairs(hitlogs.data) do
        local text = v[1]
        local r, g, b = v.color.r, v.color.g, v.color.b
        
        if v.time + 1 > GlobalVars.realtime then
            v.alpha = animation_handler.lerp(v.alpha, 1, 0.095)
            v.alpha1 = animation_handler.lerp(v.alpha, 1, 0.05)
        end

        add.y = add.y + 15*v.alpha

        Render.MultiColorText({
            {
                text[1],
                Color.new(1, 1, 1, v.alpha)
            },
            {
                text[2],
                Color.new(r, g, b, v.alpha)
            },
            {
                text[3],
                Color.new(1, 1, 1, v.alpha)
            },
            {
                text[4],
                Color.new(r, g, b, v.alpha)
            },
            {
                text[5],
                Color.new(1, 1, 1, v.alpha)
            },
            {
                text[6],
                Color.new(r, g, b, v.alpha)
            },
            {
                text[7],
                Color.new(1, 1, 1, v.alpha)
            },
            {
                text[8],
                Color.new(r, g, b, v.alpha)
            },
            {
                text[9],
                Color.new(1, 1, 1, v.alpha)
            }
        }, x + v.alpha1*100 - 100, y - add.y)
        
        if v.time + 5 < GlobalVars.realtime then
            v.alpha = animation_handler.lerp(v.alpha, 0, 0.05)
            v.alpha1 = animation_handler.lerp(v.alpha1, 2, 0.04)
        end

        if v.alpha < 0.01 and (v.time + 6 < GlobalVars.realtime) or #hitlogs.data > 5 then
            table.remove(hitlogs.data, k)
        end
    end
end
--- @endregion




--- @region: callbacks
Cheat.RegisterCallback("registered_shot", hitlogs.on_registered_shot)
Cheat.RegisterCallback("draw", hitlogs.on_draw)
--- @endregion
 
Активность
Пока что здесь никого нет
Сверху Снизу