| script_name("damage-indicator-samp-local") | |
| script_version("1.1.4") | |
| script_authors("Victor Trok", "plasma") | |
| local sampev = require "lib.samp.events" | |
| local configs = require "damage-indicator-samp.configs" | |
| local core = require "damage-indicator-samp.core" | |
| local dmg_font_size = configs.dmg_font_size | |
| local dmg_font = renderCreateFont("Arial Black", dmg_font_size, 12) | |
| local nick_font_size = configs.nick_font_size | |
| local nickname_font = renderCreateFont("Arial Black", nick_font_size, 13) | |
| local info_velocity = { | |
| x = 0.0, | |
| y = 0.07 | |
| } | |
| local given_nick_pos = { | |
| x = 0.60, | |
| y = 0.42 | |
| } | |
| local taken_nick_pos = { | |
| x = 0.30, | |
| y = 0.42 | |
| } | |
| local given_dmg_pos = { | |
| x = 0.60, | |
| y = 0.40 | |
| } | |
| local taken_dmg_pos = { | |
| x = 0.30, | |
| y = 0.40 | |
| } | |
| local screen_size = { | |
| x = 1920, | |
| y = 1080, | |
| find_abs_positions = function(self, px, py) | |
| local x = px * self.x | |
| local y = py * self.y | |
| return x, y | |
| end | |
| } | |
| local given_dmg_pool = core.ObjectPool(1, core.GivenDamageInfo) | |
| local taken_dmg_pool = core.ObjectPool(1, core.TakenDamageInfo) | |
| local has_given_update_finished = true | |
| local has_taken_update_finished = true | |
| local function update_infos() | |
| while true do | |
| wait(0) | |
| has_given_update_finished = false | |
| for _, info in pairs(given_dmg_pool.infos) do | |
| info:update() | |
| info:render() | |
| end | |
| core.player_combos:update() | |
| has_given_update_finished = true | |
| has_taken_update_finished = false | |
| for _, info in pairs(taken_dmg_pool.infos) do | |
| info:update() | |
| info:render() | |
| end | |
| has_taken_update_finished = true | |
| end | |
| end | |
| function main() | |
| while not isSampAvailable() do wait(200) end | |
| repeat wait(200) until sampIsLocalPlayerSpawned() | |
| local sx, sy = getScreenResolution() | |
| screen_size.x = sx | |
| screen_size.y = sy | |
| print("Lua Version " .. tostring(_VERSION)) | |
| print(string.format("Script Version %s | Core Version: %s | Configs Version: %s", tostring(thisScript().version), | |
| tostring(core._VERSION), tostring(configs._VERSION))) | |
| print(string.format("screen resolution: %d x %d", sx, sy)) | |
| core.init(screen_size, dmg_font, nickname_font, configs, info_velocity) | |
| given_dmg_pool:init() | |
| taken_dmg_pool:init() | |
| print("Pools initialized successfully.") | |
| lua_thread.create(update_infos) | |
| print("Thread initialized successfully.") | |
| end | |
| local function recycle_taken_dmg_info(info, player_id, nick, nick_color, damage, dmg_color, initial_dmg_pos, | |
| initial_nick_pos, timestamp) | |
| info.player_id = player_id | |
| info.nick = nick | |
| info.nick_color = nick_color | |
| info.damage = damage | |
| info.dmg_color = dmg_color | |
| info.initial_dmg_pos = initial_dmg_pos | |
| info.initial_nick_pos = initial_nick_pos | |
| info.timestamp = timestamp | |
| end | |
| local function recycle_given_dmg_info(info, player_id, nick, nick_color, is_paused, damage, dmg_color, initial_dmg_pos, | |
| initial_nick_pos, combo_count, timestamp) | |
| recycle_taken_dmg_info(info, player_id, nick, nick_color, damage, dmg_color, initial_dmg_pos, initial_nick_pos, | |
| timestamp) | |
| info.is_paused = is_paused | |
| info.combo_count = combo_count | |
| end | |
| local function is_player_id_valid(player_id) | |
| return player_id ~= nil and player_id < 65535 | |
| end | |
| local function get_player_properties(player_id) | |
| return sampGetPlayerNickname(player_id), sampGetPlayerColor(player_id), sampIsPlayerPaused(player_id) | |
| end | |
| function sampev.onSendGiveDamage(player_id, damage, weapon, bodypart) | |
| if not is_player_id_valid(player_id) then | |
| print("Invalid player_id received from onSendGiveDamage: " .. tostring(player_id)) | |
| return | |
| end | |
| if not sampIsPlayerConnected(player_id) then return end | |
| local timestamp = os.clock() | |
| print(string.format("timestamp: %s onSendGiveDamage-> pid: %s %s %s", tostring(timestamp), tostring(player_id), | |
| tostring(damage), tostring(weapon))) | |
| local nick, nick_color, is_paused = get_player_properties(player_id) | |
| local info = given_dmg_pool:get() | |
| while not has_given_update_finished do wait(0) end | |
| core.player_combos:insert(player_id) | |
| local combo_count = core.player_combos:find_by_id(player_id).count | |
| local dmg_color = bodypart == core.body_parts.HEAD and configs.headshot_color or configs.given_dmg_color | |
| recycle_given_dmg_info(info, player_id, nick, nick_color, is_paused, damage, dmg_color, given_dmg_pos, | |
| given_nick_pos, combo_count, timestamp) | |
| end | |
| function sampev.onSendTakeDamage(player_id, damage, weapon, bodypart) | |
| if not is_player_id_valid(player_id) then | |
| print("Invalid player_id received from onSendTakeDamage: " .. tostring(player_id)) | |
| return | |
| end | |
| if not sampIsPlayerConnected(player_id) then return end | |
| local timestamp = os.clock() | |
| local nick, nick_color = get_player_properties(player_id) | |
| print(string.format("timestamp: %s onSendTakeDamage-> pid: %s %s %s %s", tostring(timestamp), tostring(player_id), | |
| tostring(damage), tostring(weapon), tostring(nick))) | |
| local info = taken_dmg_pool:get() | |
| while not has_taken_update_finished do wait(0) end | |
| recycle_taken_dmg_info(info, player_id, nick, nick_color, damage, configs.taken_dmg_color, taken_dmg_pos, | |
| taken_nick_pos, timestamp) | |
| end |