Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local hmr_reference = gui.Reference("VISUALS", "MISC", "Assistance")
- local hmr_checkbox_enable = gui.Checkbox(hmr_reference, "hmr_checkbox_enable", "[HMR] Hit/Miss ratio", false)
- local hmr_checkbox_reset = gui.Checkbox(hmr_reference, "hmr_checkbox_reset", "[HMR] Reset on round start", 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_chance = 0,
- miss_chance = 0
- }
- local function reset_shots()
- for index, shot in pairs(tbl_shots) do
- tbl_shots[index] = 0
- end
- end
- local function is_gun(weapon_name)
- for index, weapon in ipairs(tbl_other_weapons) do
- if(weapon_name == "weapon_"..weapon) then
- return false
- end
- end
- return true
- end
- local function update_shots(event)
- if( entities.GetLocalPlayer() == nil or not hmr_checkbox_enable:GetValue() ) then
- reset_shots()
- 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
- elseif(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
- elseif( event_name == "round_prestart" and hmr_checkbox_reset:GetValue() ) then
- reset_shots()
- end
- end
- local function main()
- if( entities.GetLocalPlayer() == nil or not hmr_checkbox_enable:GetValue() ) then
- return -1
- end
- tbl_shots.missed = tbl_shots.fired - tbl_shots.hit
- tbl_shots.hit_chance = ( (tbl_shots.hit / tbl_shots.fired) * 100 )
- tbl_shots.miss_chance = ( (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_chance).."%" )
- draw.Color(25,175,115)
- draw.Text(x, y + font_scale*4, tbl_shots.missed.." / "..tbl_shots.fired .." = "..string.format("%.2f", tbl_shots.miss_chance).."%" )
- end
- end
- client.AllowListener("weapon_fire")
- client.AllowListener("player_hurt")
- client.AllowListener("round_prestart")
- callbacks.Register("FireGameEvent", update_shots)
- callbacks.Register("Draw", main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement