File size: 5,111 Bytes
7e9dc27 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
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 |