JS [WEAVE] Hit log

  • 85
  • 12
Credits: Mased (Его тема)
JavaScript:
var Lerp = function(a, b, percentage) { return a + (b - a) * percentage }
var screen = render.get_screen_size()
var data = new Object
var logs = new Array
var logs_time = new Array
var logs_anim_move = new Array
var logs_anim_alpha = new Array


ui.add_slider("Y Offset","y_off" ,screen[1] / 2, screen[1])
ui.add_slider("Text Size", "text_size",0,5)


function get_player() {
    var hitgroup = current_event.get_int("hitgroup");
    var damage = current_event.get_int("dmg_health");
    var health = current_event.get_int("health");
    var local = entity.get_local_player()
    var enemy = current_event.get_int("userid");
    var attacker = entity.get_player_for_user_id(current_event.get_int('attacker'));
    var victim = entity.get_player_for_user_id(current_event.get_int('userid'));
    var enemy_index = entity.get_player_for_user_id(enemy);
    var name = entity.get_player_info(enemy_index)['name'];
    var hitboxes = {
        0: "generic",
        1: "head",
        2: "chest",
        3: "stomach",
        4: "left arm",
        5: "right arm",
        6: "right leg",
        7: "left leg"
    }

    for(var i in hitboxes) {
        if(hitgroup == i) { hitgroup = hitboxes[i] }
    }
    if(attacker == local && victim !== local) {
        logs_time.push(global_vars.curtime())
        logs.push("[weave] hit " + name + "'s " + hitgroup + " for " + damage + " (" + health + " remaining)")
        logs_anim_move.push(0)
        logs_anim_alpha.push(0)
    }
}

function on_render() {
    var textSize = vars.get_int("js.text_size")
    var offset = vars.get_int("js.y_off")
       if(logs.length > 10) {
        logs.shift()
        logs_time.shift()
        logs_anim_move.shift()
        logs_anim_alpha.shift()
    }

    if(logs_time[0] + 3.5 < global_vars.curtime()) {
        logs.shift();
        logs_time.shift();
        logs_anim_move.shift()
        logs_anim_alpha.shift()
    }
    for(var i in logs) {
        logs_anim_alpha[i] = Lerp(logs_anim_alpha[i], (logs_time[0] + 3.45 > global_vars.curtime()) ? 255 : 0, 0.2)
        logs_anim_move[i] = Lerp(logs_anim_alpha[i], (logs_time[0] + 3.45 > global_vars.curtime()) ? 255 : 125, 0.2)


        render.text([screen[0] / 2 - 399  + 100 * (logs_anim_move[i] / 254) + 120, offset + 1 + (14 * i)], [0, 0, 0, 255 * (logs_anim_alpha[i] / 255)], 0,textSize,logs[i])
        render.text([screen[0] / 2 - 400 + 100 * (logs_anim_move[i] / 254) + 120, offset + (14 * i)], [255, 255, 255, 255 * (logs_anim_alpha[i] / 255)], 0,textSize,logs[i])
    
    }

}
register_callback("render", on_render)
register_callback("player_hurt", get_player)
 

Вложения

  • [WEAVE] Hitlog.zip
    1 KB · Просмотры: 31
Сверху Снизу