LUA скрипт [GS] Velocity indicator

Посрал
Участник
Статус
Оффлайн
Регистрация
28 Ноя 2020
Сообщения
518
Реакции[?]
152
Поинты[?]
0
Индикатор чисто для прикола.
Кринжкод присутствует, т.к луашки не пишу.
Пожалуйста, авторизуйтесь для просмотра ссылки.



code_language.lua:
local masterswitch = ui.new_checkbox("LUA", "B", "Enable velocity indicator")
local styleswitch = ui.new_combobox("LUA", "B", "Setting when standing", {"0", "STAND"})
local on_vel = ui.new_checkbox("LUA", "B", "Display while velocity > 0")

local function enable()
  ui.set_visible(styleswitch, ui.get(masterswitch) and not ui.get(on_vel))
  ui.set_visible(on_vel, ui.get(masterswitch))
end

local function round(value)
    return math.floor(value + 0.5)
end

local function interpolation(speed, minSpeed, maxSpeed, minColor, maxColor)
    local factor = (speed - minSpeed) / (maxSpeed - minSpeed)
    factor = math.max(0, math.min(1, factor))

    local r = minColor[1] + (maxColor[1] - minColor[1]) * factor
    local g = minColor[2] + (maxColor[2] - minColor[2]) * factor
    local b = minColor[3] + (maxColor[3] - minColor[3]) * factor

    return r, g, b
end

local function paintInd()
    if not ui.get(masterswitch) then
      return
    end

    local get_local_player = entity.get_local_player()

    if not get_local_player then
      return
    end

    local velocity_x = entity.get_prop(get_local_player, "m_vecVelocity[0]")
    local velocity_y = entity.get_prop(get_local_player, "m_vecVelocity[1]")
    local speed = math.sqrt(velocity_x^2 + velocity_y^2)

    local minSpeed = 0
    local maxSpeed = 225
    local colors = {
        {208, 208, 208},
        {255, 0, 50}, --red
        {225, 165, 0}, --green
        {150, 195, 25} --blue
    }

    local r, g, b
    if speed <= 100 then
        r, g, b = interpolation(speed, minSpeed, 100, colors[1], colors[2])
    elseif speed <= 200 then
        r, g, b = interpolation(speed, 100, 200, colors[2], colors[3])
    else
        r, g, b = interpolation(speed, 200, maxSpeed, colors[3], colors[4])
    end



    if ui.get(on_vel) and round(speed) <= 1 then
      return
    end

    if round(speed) <= 1 then
      renderer.indicator(r, g, b, 255, "VELOCITY: " .. ui.get(styleswitch))
    else
      renderer.indicator(r, g, b, 255, "VELOCITY: " .. round(speed))
    end
end

client.set_event_callback("paint", enable)
client.set_event_callback("paint", paintInd)
 
Сверху Снизу