UI.AddCheckbox('Damage marker')
UI.AddColorPicker('Hit color')
    UI.SetColor('Script items', 'Hit color', [255,255,255,255])
UI.AddColorPicker('Lethal hit color')
    UI.SetColor('Script items', 'Lethal hit color', [255,0,0,255])
UI.AddSliderInt('Numbers size', 8, 20)
    UI.SetValue('Script items', 'Numbers size', 12)
UI.AddSliderInt('Ticks damage lasts', 50, 600)
    UI.SetValue('Script items', 'Ticks damage lasts', 300)
UI.AddSliderInt('Damage indicator weight and speed', 1, 15)
    UI.SetValue('Script items', 'Damage indicator weight and speed', 3)

function m() {
    UI.SetEnabled('Script items', 'Ticks damage lasts', UI.GetValue('Damage marker'))
    UI.SetEnabled('Script items', 'Damage indicator weight and speed', UI.GetValue('Script items', 'Damage marker'))
    UI.SetEnabled('Script items', 'Hit color', UI.GetValue('Script items', 'Damage marker'))
    UI.SetEnabled('Script items', 'Lethal hit color', UI.GetValue('Script items', 'Damage marker'))
    UI.SetEnabled('Script items', 'Numbers size', UI.GetValue('Script items', 'Damage marker'))
}

Cheat.RegisterCallback('Draw', 'm')

var particles = []

function hurt() {
        attacker = Event.GetInt("attacker");
        index = Entity.GetEntityFromUserID(attacker);
        user_id = Event.GetInt("userid");
        user = Entity.GetEntityFromUserID(user_id);
        if (index == Entity.GetLocalPlayer() && index != user) {
            var pos = Entity.GetHitboxPosition(user, Event.GetInt("hitgroup"))
            if (pos == undefined) {
                pos = Entity.GetRenderOrigin(user)
                pos[2] = pos[2] + 30
            }
            pos[0] = (pos[0] - 10) + (Math.random() * 50)
            pos[1] = (pos[1] - 10) + (Math.random() * 50)
            pos[2] = (pos[2] - 15) + (Math.random() * 40)
    
                particles.push([pos, Globals.Tickcount() + UI.GetValue('Script items', 'Ticks damage lasts'), Event.GetInt("health"), Event.GetInt("dmg_health")])
        }
    }

Cheat.RegisterCallback('player_hurt', 'hurt')

function tick() {
        for (i = 0; i < particles.length; i++) {
            object = particles[i]
            var delta = object[1] - Globals.Tickcount()
            if (delta > 0) {
                object[0][2] += (UI.GetValue('Script items', 'Damage indicator weight and speed') / 10)
            }
        }
    }

Cheat.RegisterCallback('CreateMove', 'tick')

function draw() {
        for (var i = 0; i < particles.length; i++) {
            position = Render.WorldToScreen(particles[i][0])
            var timer = particles[i][1]  - Globals.Tickcount()
            health_remaining = particles[i][2]

            globalColor = [255,255,255,255]


            if (timer > 255) {
                timer = 255
            }
            if (!(timer < 0)) {
                if (position != undefined) {
                    if (UI.GetValue('Script items', 'Damage marker')) {
                        if (health_remaining > 0) { globalColor = UI.GetColor('Script items', 'Hit color') }
                        if (health_remaining <= 0) { globalColor = UI.GetColor('Script items', 'Lethal hit color') }
                            Render.StringCustom(position[0], position[1] + 1, 1, '-' + particles[i][3].toString(), [0,0,0, timer], Render.AddFont('MuseoSansCyrl-700.ttf', UI.GetValue('Script items', 'Numbers size'), 700))
                            Render.StringCustom(position[0], position[1] - 1, 1, '-' + particles[i][3].toString(), [0,0,0, timer], Render.AddFont('MuseoSansCyrl-700.ttf', UI.GetValue('Script items', 'Numbers size'), 700))
                            Render.StringCustom(position[0] + 1, position[1], 1, '-' + particles[i][3].toString(), [0,0,0, timer], Render.AddFont('MuseoSansCyrl-700.ttf', UI.GetValue('Script items', 'Numbers size'), 700))
                            Render.StringCustom(position[0] - 1, position[1], 1, '-' + particles[i][3].toString(), [0,0,0, timer], Render.AddFont('MuseoSansCyrl-700.ttf', UI.GetValue('Script items', 'Numbers size'), 700))
                            Render.StringCustom(position[0], position[1], 1, '-' + particles[i][3].toString(), [globalColor[0], globalColor[1], globalColor[2], timer], Render.AddFont('MuseoSansCyrl-700.ttf', UI.GetValue('Script items', 'Numbers size'), 700))
                    }
                }
            }
            if (!Entity.IsAlive(Entity.GetLocalPlayer())) particles = []
        }
    }

Cheat.RegisterCallback('Draw', 'draw')
