Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Stats
- -- SAPP Compatability: 9.7+
- -- Script by: Skylace aka Devieth
- -- Discord: https://discord.gg/Mxmuxgm
- player_data = {}
- api_version = "1.10.0.0"
- function OnScriptLoad()
- register_callback(cb['EVENT_GAME_START'], "OnGameStart")
- register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
- register_callback(cb['EVENT_LEAVE'], "OnPlayerJoin")
- register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
- register_callback(cb['EVENT_TICK'], "OnEventTick")
- local file = io.open("player.data", "r")
- if file then
- player_data = tableload("player_data.data")
- end
- end
- function OnScriptUnload()
- for i = 1,16 do
- if player_present(i) then
- save_stats(PlayerIndex, true)
- end
- end
- tablesave(player_data, "player_data.data")
- end
- function OnGameStart()
- local file = io.open("player.data", "r")
- if file then
- player_data = tableload("player_data.data")
- end
- end
- function OnGameEnd(PlayerIndex)
- for i = 1,16 do
- if player_present(i) then
- save_stats(PlayerIndex, true)
- end
- end
- tablesave(player_data, "player_data.data")
- end
- function OnPlayerJoin(PlayerIndex)
- local name = get_var(PlayerIndex, "$name")
- if not player_data[name] or player_data[name] == nil then
- player_data[name] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- end
- end
- function OnPlayerLeave(PlayerIndex)
- save_stats(PlayerIndex)
- end
- function OnEventTick()
- for i = 1,16 do
- if player_present(i) then
- local m_object = getdynamicplayer(i)
- if m_object then
- local e = read_bit(m_object + 0x209, 6)
- local crouch = read_bit(m_object + 0x208, 0)
- if e == 1 and crouch == 1 then
- printstats(i)
- end
- end
- end
- end
- end
- function save_stats(PlayerIndex)
- local name = get_var(PlayerIndex, "$name")
- local m_player = getplayer(PlayerIndex)
- if m_player then
- local score = tonumber(get_var(PlayerIndex, "$score"))
- local kills = tonumber(get_var(PlayerIndex, "$kills"))
- local assists = tonumber(get_var(PlayerIndex, "$assists"))
- local deaths = tonumber(get_var(PlayerIndex, "$deaths"))
- local suicides = tonumber(get_var(PlayerIndex, "$suicides"))
- local betrays = tonumber(get_var(PlayerIndex, "$tk"))
- local gt = get_var(PlayerIndex, "$gt")
- local flag_scores, flag_steals, flag_returns = 0, 0 , 0
- local hill_time = 0
- local race_time, race_laps, race_best_time = 0, 0, 0
- local oddball_target_kills, oddball_kills = 0, 0
- if gt == "ctf" then
- flag_scores = tonumber(read_word(m_player + 0xC8))
- flag_steals = tonumber(read_word(m_player + 0xC4))
- flag_returns = tonumber(read_word(m_player + 0xC6))
- elseif gt == "koth" then
- hill_time = tonumber(read_word(m_player + 0xC4)) / 30
- elseif gt == "race" then
- race_time = tonumber(read_word(m_player + 0xC4)) / 30
- race_laps = tonumber(read_word(m_player + 0xC6))
- race_best_time = tonumber(read_word(m_player + 0xC8)) / 30
- elseif gt == "oddball" then
- oddball_target_kills = tonumber(read_word(m_player + 0xC6))
- oddball_kills = tonumber(read_word(m_player + 0xC8))
- end
- local s, k, a, d, su, b, fscores, fsteals, freturns, htime, rtime, rlaps, rbtime, otk, ok = getstats(PlayerIndex)
- player_data[name] = {
- s + score, k + kills, a + assists, d + deaths, su + suicides, b + betrays,
- fscores + flag_scores, fsteals + flag_steals, freturns + flag_returns,
- htime + hill_time, rtime + race_time, rlaps + race_laps, race_best_time,
- otk + oddball_target_kills, ok + oddball_kills
- }
- end
- end
- function getstats(PlayerIndex)
- local name = get_var(PlayerIndex, "$name")
- if player_data[name] then
- score = player_data[name][1]
- kills = player_data[name][2]
- assists = player_data[name][3]
- deaths = player_data[name][4]
- suicides = player_data[name][5]
- betrays = player_data[name][6]
- flag_scores = player_data[name][7]
- flag_steals = player_data[name][8]
- flag_returns = player_data[name][9]
- hill_time = player_data[name][10]
- race_time = player_data[name][11]
- race_laps = player_data[name][12]
- race_best_time = player_data[name][13]
- oddball_target_kills = player_data[name][15]
- oddball_kills = player_data[name][16]
- return score, kills, assists, deaths, suicides, betrays, flag_scores, flag_steals, flag_returns, hill_time, race_time, race_laps, race_best_time, oddball_target_kills, oddball_kills
- else
- return 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- end
- end
- function getplayer(PlayerIndex)
- if tonumber(PlayerIndex) then
- if tonumber(PlayerIndex) ~= 0 then
- local m_player = get_player(PlayerIndex)
- if m_player ~= 0 then return m_player end
- end
- end
- return nil
- end
- function getdynamicplayer(PlayerIndex)
- if tonumber(PlayerIndex) then
- if tonumber(PlayerIndex) ~= 0 then
- local m_object = get_dynamic_player(PlayerIndex)
- if m_object ~= 0 then return m_object end
- end
- end
- return nil
- end
- function printstats(PlayerIndex)
- for i = 1,23 do
- rprint(PlayerIndex," ")
- end
- local s, k, a, d, su, b, fscores, fsteals, freturns, htime, rtime, rlaps, rbtime, otk, ok = getstats(PlayerIndex)
- local kd = math.floor((k / d) * (10 ^ 2) + 0.5) / (10 ^ 2)
- local s, m, h = gettimestamp(rtime)
- local s1, m1, h1 = gettimestamp(rbtime)
- local s2, m2, h2 = gettimestamp(htime)
- local racetime = h..":"..m..":"..s
- local racebesttime = h1..":"..m1..":"..s1
- local hilltime = h2..":"..m2..":"..s2
- local line0 = string.format("Total Score: %s", s)
- local line1 = string.format("Kills: %s|tKDR: %s",k, kd)
- local line2 = string.format("Deaths: %s|tSuicides: %s",d, su)
- local line3 = string.format("Assists: %s|tBetrays: %s",a, b)
- local line4 = string.format("Flags Captured: %s|tRace Time: %s|tOddball Kills: %s|tKOTH Time: %s", fscores, racetime, ok, hilltime)
- local line5 = string.format("Flags Retruned: %s|tRace Laps: %s|tCarrier Kills: %s", freturns, rlaps, otk)
- local line6 = string.format("Flags Stolen: %s|tBest Lap: %s", fsteals, racebesttime)
- rprint(PlayerIndex, "-- Primary Stats --")
- rprint(PlayerIndex, line0)
- rprint(PlayerIndex, line1)
- rprint(PlayerIndex, line2)
- rprint(PlayerIndex, line3)
- rprint(PlayerIndex, " ")
- rprint(PlayerIndex, "-- CTF --|t-- RACE --|t-- ODDBALL --|t-- KOTH --")
- rprint(PlayerIndex, line4)
- rprint(PlayerIndex, line5)
- rprint(PlayerIndex, line6)
- rprint(PlayerIndex, " ")
- rprint(PlayerIndex, " ")
- rprint(PlayerIndex, "|cNOTE: This will only update at the end of each game or when you quit.")
- end
- function gettimestamp(seconds)
- if seconds > 60 then
- minutes = math.floor(seconds / 60)
- seconds = seconds - (minutes * 60)
- if seconds < 10 then
- seconds = "0"..tostring(seconds)
- else
- seconds = seconds
- end
- if minutes > 60 then
- hours = math.floor(minutes / 60)
- minutes = minutes - (hours * 60)
- else
- hours = 0
- end
- else
- if seconds < 10 then
- seconds = "0"..tostring(seconds)
- else
- seconds = seconds
- end
- minutes = 0
- hours = 0
- end
- return math.floor(seconds), math.floor(minutes), hours
- end
- function tablesave(t, filename) -- Nuggets's Code to the end
- local file = io.open(filename, "w")
- local spaces = 0
- local function tab()
- local str = ""
- for i = 1,spaces do
- str = str .. " "
- end
- return str
- end
- local function format(t)
- spaces = spaces + 4
- local str = "{ "
- for k,v in opairs(t) do
- -- Key datatypes
- if type(k) == "string" then
- k = string.format("%q", k)
- elseif k == math.inf then
- k = "1 / 0"
- end
- k = tostring(k)
- -- Value datatypes
- if type(v) == "string" then
- v = string.format("%q", v)
- elseif v == math.inf then
- v = "1 / 0"
- end
- if type(v) == "table" then
- if tablelen(v) > 0 then
- str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. format(v) .. ","
- else
- str = str .. "\n" .. tab() .. "[" .. k .. "] = {},"
- end
- else
- str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. tostring(v) .. ","
- end
- end
- spaces = spaces - 4
- return string.sub(str, 1, string.len(str) - 1) .. "\n" .. tab() .. "}"
- end
- file:write("return " .. format(t))
- file:close()
- end
- function tableload(filename)
- local file = loadfile(filename)
- if file then
- return file() or {}
- end
- return {}
- end
- function tablelen(t)
- local count = 0
- for k,v in pairs(t) do
- count = count + 1
- end
- return count
- end
- function opairs(t)
- local keys = {}
- for k,v in pairs(t) do
- table.insert(keys, k)
- end
- table.sort(keys,
- function(a,b)
- if type(a) == "number" and type(b) == "number" then
- return a < b
- end
- an = string.lower(tostring(a))
- bn = string.lower(tostring(b))
- if an ~= bn then
- return an < bn
- else
- return tostring(a) < tostring(b)
- end
- end)
- local count = 1
- return function()
- if unpack(keys) then
- local key = keys[count]
- local value = t[key]
- count = count + 1
- return key,value
- end
- end
- end
- function spaces(n, delimiter)
- delimiter = delimiter or ""
- local str = ""
- for i = 1, n do
- if i == math.floor(n / 2) then
- str = str .. delimiter
- end
- str = str .. " "
- end
- return str
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement