Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. local hmr_reference = gui.Reference("VISUALS", "MISC", "Assistance")
  2. local hmr_checkbox_enable = gui.Checkbox(hmr_reference, "hmr_checkbox_enable", "[HMR] Hit/Miss ratio", false)
  3. local hmr_checkbox_reset = gui.Checkbox(hmr_reference, "hmr_checkbox_reset", "[HMR] Reset on round start", false)
  4.  
  5.  
  6. local x,y = 80, 420
  7. local font_scale = 20
  8. local font = draw.CreateFont("Verdana", font_scale, 800)
  9.  
  10. local gun_fired = false
  11.  
  12. local tbl_other_weapons =
  13. {
  14. "knife",
  15. "knife_t",
  16. "hegrenade",
  17. "smokegrenade",
  18. "molotov",
  19. "incgrenade",
  20. "flashbang",
  21. "decoy",
  22. "taser"
  23. }
  24.  
  25. local tbl_shots =
  26. {
  27. fired = 0,
  28. hit = 0,
  29. missed = 0,
  30. hit_chance = 0,
  31. miss_chance = 0
  32. }
  33.  
  34. local function reset_shots()
  35.  
  36. for index, shot in pairs(tbl_shots) do
  37.  
  38. tbl_shots[index] = 0
  39.  
  40. end
  41.  
  42. end
  43.  
  44. local function is_gun(weapon_name)
  45.  
  46. for index, weapon in ipairs(tbl_other_weapons) do
  47.  
  48. if(weapon_name == "weapon_"..weapon) then
  49.  
  50. return false
  51.  
  52. end
  53.  
  54. end
  55.  
  56. return true
  57.  
  58. end
  59.  
  60. local function update_shots(event)
  61.  
  62. if( entities.GetLocalPlayer() == nil or not hmr_checkbox_enable:GetValue() ) then
  63.  
  64. reset_shots()
  65.  
  66. return -1
  67.  
  68. end
  69.  
  70. local event_name = event:GetName()
  71.  
  72. local local_player_index = client.GetLocalPlayerIndex()
  73. local local_player_info = client.GetPlayerInfo(local_player_index)
  74.  
  75.  
  76. if(event_name == "weapon_fire") then
  77.  
  78. local player_id = event:GetInt("userid")
  79. local player_weapon = event:GetString("weapon")
  80.  
  81. if(local_player_info["UserID"] == player_id and is_gun(player_weapon)) then
  82.  
  83. tbl_shots.fired = tbl_shots.fired + 1
  84. gun_fired = true
  85.  
  86. end
  87.  
  88. elseif(event_name == "player_hurt") then
  89.  
  90. local attacker_id = event:GetInt("attacker")
  91. local attacker_weapon = event:GetString("weapon")
  92.  
  93. if( local_player_info["UserID"] == attacker_id and is_gun(attacker_weapon) and gun_fired) then
  94.  
  95. tbl_shots.hit = tbl_shots.hit + 1
  96. gun_fired = false
  97.  
  98. end
  99.  
  100. elseif( event_name == "round_prestart" and hmr_checkbox_reset:GetValue() ) then
  101.  
  102. reset_shots()
  103.  
  104. end
  105. end
  106.  
  107. local function main()
  108.  
  109. if( entities.GetLocalPlayer() == nil or not hmr_checkbox_enable:GetValue() ) then
  110.  
  111. return -1
  112.  
  113. end
  114.  
  115. tbl_shots.missed = tbl_shots.fired - tbl_shots.hit
  116. tbl_shots.hit_chance = ( (tbl_shots.hit / tbl_shots.fired) * 100 )
  117. tbl_shots.miss_chance = ( (tbl_shots.missed / tbl_shots.fired) * 100 )
  118.  
  119. draw.SetFont(font)
  120.  
  121. draw.Color(255, 255, 255)
  122. draw.Text(x, y, "total: "..tbl_shots.fired)
  123.  
  124. draw.Color(30, 190, 40)
  125. draw.Text(x, y + font_scale, "hit: "..tbl_shots.hit)
  126.  
  127. draw.Color(200, 60, 40)
  128. draw.Text(x, y + font_scale*2, "miss: "..tbl_shots.missed)
  129.  
  130. if(tbl_shots.fired > 0) then
  131.  
  132. draw.Color(30, 95, 190)
  133. draw.Text(x, y + font_scale*3, tbl_shots.hit.." / "..tbl_shots.fired .." = "..string.format("%.2f", tbl_shots.hit_chance).."%" )
  134.  
  135. draw.Color(25,175,115)
  136. draw.Text(x, y + font_scale*4, tbl_shots.missed.." / "..tbl_shots.fired .." = "..string.format("%.2f", tbl_shots.miss_chance).."%" )
  137.  
  138. end
  139.  
  140. end
  141.  
  142.  
  143. client.AllowListener("weapon_fire")
  144. client.AllowListener("player_hurt")
  145. client.AllowListener("round_prestart")
  146.  
  147. callbacks.Register("FireGameEvent", update_shots)
  148. callbacks.Register("Draw", main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement