Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Headshot Announcer v2
- -- by H® Shaft
- -- changelog 1/16/2017
- -- corrected a couple typos where [id] should have been PlayerIndex instead
- -- corrected show stats to correctly attribute headshot counts
- -- edited to only read memory if a game is running to prevent crashes
- -- corrected OnDamageLookup to only work if damage was caused by another player
- -- The PRIMARY purpose of this script:
- -- is to announce when a player is killed by a "head-shot", and -
- -- to show everyone their "kills by head-shots count" in (parenthesis).
- -- **Example** this kill message shows H® Shaft has '14' head-shot-kills:
- -- " BOOM! H® Shaft ASSASSINATED New001 with a HEAD-SHOT! (14) "
- -- The SECONDARY purpose of this script to allow admins identify all players kill counts -vs- kills-by-headshot counts
- -- Note: many players are very good at killing by headshots; it doesn't mean they are cheating or aim-botting!
- -- ADMIN USAGE:
- -- admins can type "/ss" for the ShowStats command to see all players kill counts -vs- kills-by-headshot counts
- -- admins can specify the admin level of those who can execute the command (see ADMIN_LEVEL below)
- -- SAMPLE OUTPUT of ShowStats command (Player # is ID#):
- -- ID#: 1 -- H® Shaft -- KILLS: 4 -- HEADSHOTS: 3
- -- ID#: 2 -- Killer -- KILLS: 0 -- HEADSHOTS: 0
- -- This admin level and higher can use the /ss (ShowStats) command, and see all players head shot scores
- ADMIN_LEVEL = 2
- -- if set to true, when the /ss command is used, log all players kill counts and kills-by-headshot counts into sapps log
- LOG_RESULTS = true
- -- The command to use to "reset the map" AND reset players kill count and kills-by-headshot counts zero
- RESET_COMMAND = "reset"
- --- END CONFIGURATION ----
- --- don't edit below ---
- api_version = "1.9.0.0"
- function OnScriptLoad()
- register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
- register_callback(cb['EVENT_GAME_START'], "OnNewGame")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- register_callback(cb['EVENT_DIE'], "OnPlayerDie")
- register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
- register_callback(cb['EVENT_DAMAGE_APPLICATION'], "OnDamageApplication")
- register_callback(cb['EVENT_COMMAND'], "OnCommand")
- head_shot = {}
- headshot_count = {}
- if get_var(0, "$gt") ~= "n/a" then
- OnNewGame()
- end
- end
- function OnScriptUnload() end
- function OnNewGame()
- game_started = true
- for i = 1, 16 do
- if player_present(i) then
- head_shot[i] = false
- headshot_count[i] = 0
- end
- end
- end
- function OnGameEnd()
- game_started = false
- for i = 1,16 do
- if player_present(i) then
- local id = get_var(i, "$n")
- if headshot_count[i] == nil then headshot_count[i] = 0 end
- local headshots = tonumber(headshot_count[i])
- local name = get_var(i, "$name")
- local kills = tonumber(get_var(i, "$kills"))
- if kills == nil then kills = 0 end
- local player_stats = string.format("ID#: %s -- %s -- KILLS: %s -- HEADSHOTS: %s", id, name, kills, headshots)
- if (LOG_RESULTS == true) then
- execute_command("log_note \""..player_stats.."\"")
- end
- head_shot[i] = false
- headshot_count[i] = 0
- end
- end
- end
- function OnPlayerJoin(PlayerIndex)
- if player_present(PlayerIndex) then
- head_shot[PlayerIndex] = false
- headshot_count[PlayerIndex] = 0
- end
- end
- function OnPlayerLeave(PlayerIndex)
- head_shot[PlayerIndex] = nil
- headshot_count[PlayerIndex] = nil
- end
- function OnDamageApplication(PlayerIndex, CauserIndex, MetaID, Damage, HitString, Backtap)
- if player_present(PlayerIndex) then
- if (CauserIndex ~= nil) then
- local CausesHeadShot = OnDamageLookup(PlayerIndex, CauserIndex)
- if (CausesHeadShot ~= nil) then
- if (HitString == "head") then
- head_shot[PlayerIndex] = true
- else
- head_shot[PlayerIndex] = false
- end
- else
- head_shot[PlayerIndex] = false
- end
- end
- end
- end
- function OnDamageLookup(ReceiverIndex, CauserIndex)
- local response = nil
- if get_var(0, "$gt") ~= "n/a" then
- if (CauserIndex and ReceiverIndex ~= CauserIndex) then
- if (CauserIndex ~= 0) then
- local r_team = read_word(get_player(ReceiverIndex) + 0x20)
- local c_team = read_word(get_player(CauserIndex) + 0x20)
- if (r_team ~= c_team) then
- local tag_address = read_dword(0x40440000)
- local tag_count = read_word(0x4044000C)
- for A=0,tag_count-1 do
- local tag_id = tag_address + A * 0x20
- if (read_dword(tag_id) == 1785754657) then
- local tag_data = read_dword(tag_id + 0x14)
- if (tag_data ~= nil) then
- if (read_word(tag_data + 0x1C6) == 5) or (read_word(tag_data + 0x1C6) == 6) then -- damage category: bullets
- if (read_bit(tag_data + 0x1C8, 1) == 1) then -- damage effect: can cause head shots
- response = true
- else
- response = false
- end
- end
- end
- end
- end
- end
- else
- response = false
- end
- end
- end
- return response
- end
- function OnPlayerDie(PlayerIndex, KillerIndex)
- if (game_started == true) then
- local killer = tonumber(KillerIndex)
- if (killer > 0) then -- killer is another player
- local vname = get_var(PlayerIndex, "$name")
- local kname = get_var(KillerIndex,"$name")
- local ktype = string.upper(generatekill(killtype))
- if headshot_count[KillerIndex] == nil then headshot_count[KillerIndex] = 0 end
- if (PlayerIndex ~= killer) then
- if (get_var(KillerIndex, "$team") ~= get_var(PlayerIndex, "$team")) then
- if (head_shot[PlayerIndex] == true) then
- headshot_count[killer] = headshot_count[killer] + 1
- local count = headshot_count[killer]
- if (kname ~= nil) then
- if (ktype~= nil) then
- say_all("BOOM! " ..kname .. " " .. ktype .. " " .. vname .. " with a HEAD-SHOT! (" .. count .. ")")
- else
- say_all("BOOM! " ..kname .. " NAILED " .. vname .. " with a HEAD-SHOT! (" .. count .. ")")
- end
- else
- say_all("BOOM! " ..vname .. " was GUTTED by a 'random' HEAD-SHOT!") -- killer unknown, such as killer left server, or error
- end
- end
- end
- end
- head_shot[PlayerIndex] = false
- end
- end
- end
- function OnPlayerChat(PlayerIndex, Message)
- local response = nil
- if Message == nil then
- return true
- end
- local name = get_var(PlayerIndex,"$name")
- local Message = string.lower(Message)
- local isadmin = nil
- if (tonumber(get_var(PlayerIndex,"$lvl"))) >= ADMIN_LEVEL then isadmin = true else isadmin = false end
- if Message ~= nil then
- if (Message == "/ss") then
- if (isadmin == true) then
- local data1 = string.format("%s used the showstats (/ss) command. ", tostring(name))
- if (LOG_RESULTS == true) then
- execute_command("log_note \""..data1.."\"")
- end
- ShowStats(PlayerIndex)
- response = false
- else
- local data2 = string.format("%s attempted to use the showstats (/ss) command. ", tostring(name))
- if (LOG_RESULTS == true) then
- execute_command("log_note \""..data2.."\"")
- end
- say(PlayerIndex, "You are not allowed to use this command, or you must log in first.")
- response = true
- end
- end
- end
- return response
- end
- function ShowStats(PlayerIndex)
- for j=1,30 do
- rprint(PlayerIndex," ")
- end
- for i = 1,16 do
- if player_present(i) then
- local id = get_var(i, "$n")
- if headshot_count[i] == nil then headshot_count[i] = 0 end
- local headshots = headshot_count[i]
- local name = get_var(i, "$name")
- local kills = tonumber(get_var(i, "$kills"))
- if kills == nil then kills = 0 end
- local player_stats = string.format("ID#: %s -- %s -- KILLS: %s -- HEADSHOTS: %s", id, name, kills, headshots)
- rprint(PlayerIndex, player_stats)
- if (LOG_RESULTS == true) then
- execute_command("log_note \""..player_stats.."\"")
- end
- end
- end
- end
- function OnCommand(PlayerIndex,Command,Environment,Password)
- Command = string.lower(Command)
- -- if chat command, i.e. chat: /reset
- if (Environment == 2) then
- if (Command == RESET_COMMAND) or (Command == "/reset") or (Command == "reset") then
- if (tonumber(get_var(PlayerIndex, "$lvl")) >= ADMIN_LEVEL) then
- for i = 1, 16 do
- if player_present(i) then
- head_shot[i] = false
- headshot_count[i] = 0
- end
- end
- execute_command("sv_map_reset")
- return false
- end
- end
- -- if console or rcon
- elseif (Environment == 0) or (Environment == 1) then
- if (Command == "sv_map_reset") or (Command == RESET_COMMAND) then
- for i = 1, 16 do
- if player_present(i) then
- head_shot[i] = false
- headshot_count[i] = 0
- end
- end
- execute_command("sv_map_reset")
- return true
- end
- end
- return true
- end
- function generatekill(killtype)
- local killtype = {"destroyed", "fubbared", "disemboweled", "violated", "eviscerated", "assassinated", "slaughtered", "exterminated", "murdered", "eradicated", "executed", "snuffed", "eliminated", "liquidated"}
- local killcount = #killtype
- local rand_type = rand(1, killcount+1)
- local kill_type = string.format("%s", killtype[rand_type])
- if (kill_type ~= nil) then
- return kill_type
- else
- return "killed"
- end
- end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft
- -- Visit http://halorace.org/forum/index.php
- -- The player -db-GoNe/Juhleek - a well spoken liar, cheat.
- -- -db- is: "diverging from the believable" - How ironic. A race clan where admins use rcon to favor themselves to win.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement