
var alpha = 0;
var size = 0;


const time = UI.AddSliderFloat("Effect duration", 0, 2);
UI.AddColorPicker('kill color');// 加个操蛋的颜色选取器
var color= UI.GetColor( "Misc", "JAVASCRIPT", "Script items", "kill color" );

function clamp(v, min, max)
{
    return Math.max(Math.min(v, max), min);
}

function get(element)
{
    return UI.GetValue("Misc", "JAVASCRIPT", "Script items", element);
}

function render_effect()
{
    if (alpha === 0)
        return;

    const inc_alpha = ((1 / get("Effect duration")) * Global.Frametime()) * 255
    const inc_size = ((1 / get("Effect duration")) * Global.Frametime()) * 360

    alpha = clamp(alpha - inc_alpha, 0, 255);
    size = clamp(size - inc_size, 0, 360);

    const x = Global.GetScreenSize()[0], y = Global.GetScreenSize()[1];
    //画到屏幕上之前 先获取一下颜色
//下面的颜色被改写了 getcolor返回的是一个数组  有三个元素 分表代表red green blue
    Render.GradientRect(0, 0, x, size, 0, [color[0],color[1], color[2], alpha], [color[0], color[1], color[2], 0]);
    Render.GradientRect(0, y - size, x, size, 0, [color[0], color[1], color[2], 0], [color[0], color[1], color[2], alpha]);
    Render.GradientRect(x - size, 0, size, y, 1, [color[0], color[1], color[2], 0], [color[0], color[1], color[2], alpha]);
    Render.GradientRect(0, 0, size, y, 1, [color[0], color[1], color[2], alpha], [color[0], color[1], color[2], 0]);
}

function on_death()
{
    const attacker = Entity.GetEntityFromUserID(Event.GetInt("attacker"));
    const userid = Entity.GetEntityFromUserID(Event.GetInt("userid"));
    const player = Entity.GetLocalPlayer();
    color= UI.GetColor( "Misc", "JAVASCRIPT", "Script items", "kill color" );
    if (attacker === player && userid != player)
    {
        alpha = 255;
        size = 360;
    }
}

Global.RegisterCallback("player_hurt", "on_death");
Global.RegisterCallback("Draw", "render_effect");
