Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local events = require 'lib.samp.events'
- local settings = {
- max_lines = 30,
- fake_afk = false,
- remove_on_quit = false
- }
- function create_empty_item()
- return {
- shots = 0,
- hits = 0,
- accuracy = 0,
- last = 0,
- nick = '',
- lines = {}, sum=0
- }
- end
- function get_speed_safely(id)
- if id == select(2, sampGetPlayerIdByCharHandle(1)) then return math.floor(getCharSpeed(1) * 3) end
- local res, ped = sampGetCharHandleBySampPlayerId(id)
- if not res then return 'UNK' else
- return math.floor(getCharSpeed(ped) * 3) end
- end
- function get_vspeed_safely(id)
- local res, car = sampGetCarHandleBySampVehicleId(id)
- if not res then return 'UNK' else
- return math.floor(getCarSpeed(car) * 3) end
- end
- function get_vehicle_model(id)
- local res, car = sampGetCarHandleBySampVehicleId(id)
- if res then return getNameOfVehicleModel(getCarModel(car)) else return 'UNK ' .. tostring(id) end
- end
- function get_weapon_name(id)
- local weapons = {
- [22] = 'glock',
- [23] = 's glock',
- [24] = 'deagle',
- [25] = 'shotgun',
- [26] = 'sawn',
- [27] = 'spac12',
- [28] = 'uzi',
- [29] = 'mp5',
- [30] = 'ak47',
- [31] = 'm4',
- [32] = 'tec9',
- [33] = 'rifle',
- [34] = 'sniper',
- [38] = 'minigun'
- }
- return weapons[id] or 'UNK ' .. tostring(id)
- end
- local pool = {}
- local shotspec = false
- local shotspec_id = -1
- function process_warning(id, data)
- local O, T = data.origin, data.target
- if data.targetType == 1 and not isLineOfSightClear(O.x, O.y, O.z, T.x, T.y, T.z, true, false, false, true, true) then
- return ' {CCAA00}(стрельба сквозь текстуры){ABCDEF}'
- end
- return ''
- end
- function events.onSendBulletSync(data)
- process_bullet_sync(select(2, sampGetPlayerIdByCharHandle(1)), data)
- end
- function events.onBulletSync(id, data)
- process_bullet_sync(id, data)
- end
- function events.onPlayerQuit(id)
- if settings.remove_on_quit and pool[id] then
- pool[id] = create_empty_item()
- end
- end
- function process_bullet_sync(id, data)
- if not pool[id] or pool[id].nick ~= sampGetPlayerNickname(id) then pool[id] = create_empty_item() end
- local O, T = data.origin, data.target
- local distance = math.sqrt((O.x - T.x) ^ 2 + (O.y - T.y) ^ 2 + (O.z - T.z) ^ 2)
- local dist_text = ''
- if data.targetType == 1 or data.targetType == 2 then dist_text = ', ' .. math.floor(distance) .. 'm' end
- local hit_name = 'ПРОМАХ'
- if data.targetType == 1 then hit_name = sampGetPlayerNickname(data.targetId) end
- if data.targetType == 2 then hit_name = get_vehicle_model(data.targetId) end
- local speed_vs = ''
- if data.targetType == 1 then speed_vs = ', ' .. get_speed_safely(id) .. ' vs ' .. get_speed_safely(data.targetId) end
- if data.targetType == 2 then speed_vs = ', ' .. get_speed_safely(id) .. ' vs ' .. get_vspeed_safely(data.targetId) end
- local time_since = os.clock() - pool[id].last
- if time_since > 5 and pool[id].shots > 0 then pool[id].lines[#pool[id].lines + 1] = '' end
- if time_since > 1 then time_since = 'ok' else time_since = math.floor(1000 * time_since) .. 'ms' end
- pool[id].nick = sampGetPlayerNickname(id)
- pool[id].last = os.clock()
- pool[id].shots = pool[id].shots + 1
- if data.targetType == 1 or data.targetType == 2 then pool[id].hits = pool[id].hits + 1 end
- pool[id].accuracy = math.floor(100 * pool[id].hits / pool[id].shots)
- local line = string.format(
- '%s > %s%s, %s%s > %s%s',
- pool[id].nick, get_weapon_name(data.weaponId), dist_text, time_since, speed_vs, hit_name, process_warning(id, data)
- )
- pool[id].lines[#pool[id].lines + 1] = '[' .. os.date('%H:%M:%S') .. '] ' .. line
- if shotspec and shotspec_id == id then sampAddChatMessage('[SHOT] ' .. line, -1) end
- end
- function onSendPacket(id)
- if settings.fake_afk and (id == 200 or id == 207 or id == 211) then -- sampAddChatMessage(1,-1);
- if sampIsDialogActive() then
- local did = sampGetCurrentDialogId()
- if did == 5555 or did == 5556 then return false end
- end
- end
- end
- local pids = {}
- function show_list()
- --[[local output = ''
- for i = 0, 999 do
- if pool[i] then
- output = output .. pool[i].nick .. ' [ID ' .. i .. ']\t' ..
- pool[i].hits .. '/' .. pool[i].shots .. ' (' .. pool[i].accuracy .. '%)\n'
- end
- end
- sampShowDialog(5556, 'Статистика стрельбы', output, 'Select', 'X', 4)]]
- -- ### I know this is fucked up
- pids = {}
- local output = ''
- local sorted = {}
- local sorted_len = 0
- local pool_len = 0
- for i = 0, 999 do if pool[i] then pool_len = pool_len + 1 end end
- if pool_len == 0 then return sampAddChatMessage('В статистике стрельбы нет ни одной записи.', 0xAFAFAF) end
- while sorted_len ~= pool_len do
- local highest = -1
- local max = 0
- for i = 0, 999 do
- if pool[i] and not sorted[i] then
- if pool[i].accuracy >= max then
- max = pool[i].accuracy
- highest = i
- end
- end
- end
- sorted[highest] = true
- sorted_len = sorted_len + 1
- local off = off_mark(highest)
- output = output .. pool[highest].nick .. ' [ID ' .. highest .. ']' .. off .. '\t' ..
- pool[highest].hits .. '/' .. pool[highest].shots .. ' (' .. pool[highest].accuracy .. '%)\n'
- pids[#pids+1] = highest
- end
- sampShowDialog(5556, 'Статистика стрельбы', output, '>>', 'X', 4)
- end
- local arrow_shown = false
- function show_stats(id, arrow)
- arrow_shown = arrow or false
- local off = off_mark(id)
- local output = '{ABCDEF}Статистика попаданий: ' .. pool[id].hits .. '/' .. pool[id].shots .. ' (' .. pool[id].accuracy .. '%)\n'
- local start = #pool[id].lines > settings.max_lines and #pool[id].lines - settings.max_lines or 1
- for i = start, #pool[id].lines do
- output = output .. '\n' .. pool[id].lines[i]
- end
- if arrow then
- sampShowDialog(5555, 'Лог выстрелов ' .. pool[id].nick .. ' [ID ' .. id .. ']' .. off, output, '<<', 'X')
- else
- sampShowDialog(5555, 'Лог выстрелов ' .. pool[id].nick .. ' [ID ' .. id .. ']' .. off, output, 'X')
- end
- end
- function off_mark(id)
- if id == select(2, sampGetPlayerIdByCharHandle(1)) then return '' end
- if not sampIsPlayerConnected(id) or pool[id].nick ~= sampGetPlayerNickname(id) then return ' {AA0000}OFF{FFFFFF}'
- else return '' end
- end
- function main()
- while not isSampAvailable() do wait(100) end
- sampRegisterChatCommand('shotlog', function (id)
- if id == '' then return show_list() end
- id = tonumber(id)
- if not id then return sampAddChatMessage('Подсказка: /shotlog [ID]', 0xAFAFAF) end
- if not pool[id] then return sampAddChatMessage('Лог выстрелов указанного игрока пуст.', 0xAFAFAF) end
- show_stats(id)
- end)
- sampRegisterChatCommand('shotspec', function (id)
- if shotspec then
- shotspec = false
- return sampAddChatMessage('Режим shotspec выключен.', 0xAFAFAF)
- end
- id = tonumber(id)
- if not id then return sampAddChatMessage('Подсказка: /shotspec [ID]', 0xAFAFAF) end
- shotspec = true
- shotspec_id = id
- sampAddChatMessage('Режим shotspec включен.', 0xAFAFAF)
- end)
- while true do
- wait(1)
- local res, btn, item = sampHasDialogRespond(5556)
- if res and btn == 1 then show_stats(pids[item + 1], true) end
- local res2, btn2 = sampHasDialogRespond(5555)
- if res2 and arrow_shown and btn2 == 1 then show_list() end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement