Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

Lua hit%miss% ratio

  • Автор темы Автор темы xlisov
  • Дата начала Дата начала
Удалите мой акк с форума.
Участник
Участник
Статус
Оффлайн
Регистрация
21 Сен 2019
Сообщения
1,085
Реакции
193
Может кому то надо но мне нет.
Код:
Expand Collapse Copy
local hmr_reference = gui.Reference("VISUALS", "MISC", "Assistance")
local hmr_checkbox = gui.Checkbox(hmr_reference, "hmr_checkbox", "Hit/Miss Ratio", false)

local x,y = 80, 420
local font_scale = 20
local font = draw.CreateFont("Verdana", font_scale, 800)

local gun_fired = false

local tbl_other_weapons =
{
    "knife",
    "knife_t",
    "hegrenade",
    "smokegrenade",
    "molotov",
    "incgrenade",
    "flashbang",
    "decoy",
    "taser"
}

local tbl_shots =
{
    fired = 0,
    hit = 0,
    missed = 0,
    hit_ratio = 0,
    miss_ratio = 0
}

local function is_gun(weapon_name)

    for index, weapon in pairs(tbl_other_weapons) do
     
        if(weapon_name == "weapon_"..weapon) then

            return false

        end

    end

    return true

end

local function on_shot(event)

    if( not hmr_checkbox:GetValue() ) then
        return -1
    end

    local event_name = event:GetName()
 
    local local_player_index = client.GetLocalPlayerIndex()
    local local_player_info = client.GetPlayerInfo(local_player_index)


    if(event_name == "weapon_fire") then

        local player_id = event:GetInt("userid")
        local player_weapon = event:GetString("weapon")

        if(local_player_info["UserID"] == player_id and is_gun(player_weapon)) then

            tbl_shots.fired = tbl_shots.fired + 1
            gun_fired = true

        end

    end
 
    if(event_name == "player_hurt") then

        local attacker_id = event:GetInt("attacker")
        local attacker_weapon = event:GetString("weapon")

        if( local_player_info["UserID"] == attacker_id and is_gun(attacker_weapon) and gun_fired) then

            tbl_shots.hit = tbl_shots.hit + 1
            gun_fired = false

        end

    end

end

local function main()

    if( entities.GetLocalPlayer() == nil or not hmr_checkbox:GetValue() ) then
        return -1
    end

    tbl_shots.missed = tbl_shots.fired - tbl_shots.hit
    tbl_shots.hit_ratio = ( (tbl_shots.hit / tbl_shots.fired) * 100 )
    tbl_shots.miss_ratio = ( (tbl_shots.missed / tbl_shots.fired) * 100 )

    draw.SetFont(font)

    draw.Color(255, 255, 255)
    draw.Text(x, y, "total: "..tbl_shots.fired)

    draw.Color(30, 190, 40)
    draw.Text(x, y + font_scale, "hit: "..tbl_shots.hit)

    draw.Color(200, 60, 40)
    draw.Text(x, y + font_scale*2, "miss: "..tbl_shots.missed)

    if(tbl_shots.fired > 0) then

        draw.Color(30, 95, 190)
        draw.Text(x, y + font_scale*3, tbl_shots.hit.." / "..tbl_shots.fired .." = "..string.format("%.2f", tbl_shots.hit_ratio).."%" )

        draw.Color(25,175,115)
        draw.Text(x, y + font_scale*4, tbl_shots.missed.." / "..tbl_shots.fired .." = "..string.format("%.2f",  tbl_shots.miss_ratio).."%" )

    end

end
 
Последнее редактирование:
хуита, если самому стрелять, то тоже будет засчитывать
 
Назад
Сверху Снизу