Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions [gameplay]/killmessages/scripts/client/c.ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ function outputMessage(new)

new.initTick = getTickCount()

if new.icon.path and fileExists(new.icon.path) then
new.icon.texture = dxCreateTexture(new.icon.path)
if new.icon and new.icon.path and fileExists(new.icon.path) then
new.icon.texture = getTexture(new.icon.path)
end

table.insert(messages, new)

local displayLines = tonumber(getSetting('displayLines')) or 5

local quantity = #messages

if (quantity == 1) then
addEventHandler('onClientRender', root, renderMessages)

elseif (quantity > displayLines) then
table.remove(messages, 1)

end

return true
Expand All @@ -51,7 +48,6 @@ function renderMessages()
duration = duration * 1000

local y = sH - (sH * marginBottom)

local padding = 5 -- distance between texts and icon

for k = #messages, 1, -1 do
Expand All @@ -63,10 +59,8 @@ function renderMessages()

if (passed <= fadeTime) then
alpha = 255 * passed / math.max(1, fadeTime)

elseif (passed >= (duration - fadeTime)) then
alpha = 255 - 255 * ((now - duration + fadeTime) - v.initTick) / math.max(1, fadeTime)

end

local victim = v.victim
Expand All @@ -75,48 +69,39 @@ function renderMessages()
victimColor = tocolor(victimColor[1], victimColor[2], victimColor[3], alpha)

local victimWidth = dxGetTextSize(victimText, 0, 1, 1, font, false, true)

local x = sW - (sW * marginRight) - victimWidth

dxDrawText(victimText, x + 2, y + 2, x + victimWidth, y + lineHeight, tocolor(0, 0, 0, alpha), 1, font, 'center', 'center')
dxDrawText(victimText, x, y, x + victimWidth, y + lineHeight, victimColor, 1, font, 'center', 'center')
dxDrawText(victimText, x + 1, y + 1, x + victimWidth + 1, y + lineHeight + 1, tocolor(0, 0, 0, alpha), 1, font, 'left', 'center')
dxDrawText(victimText, x, y, x + victimWidth, y + lineHeight, victimColor, 1, font, 'left', 'center')

local icon = v.icon

if icon then
if icon and icon.texture then
local texture = icon.texture
local iconWidth = icon.width
local iconWidth = icon.width or 20
x = x - padding - iconWidth
dxDrawImage(x, y, iconWidth, lineHeight, texture, 0, 0, 0, tocolor(255, 255, 255, alpha))
end

local killer = v.killer

if killer then
local killerText = killer.text
local killerColor = killer.color
killerColor = tocolor(killerColor[1], killerColor[2], killerColor[3], alpha)

local killerWidth = dxGetTextSize(killerText, 0, 1, 1, font, false, true)

x = x - padding - killerWidth

dxDrawText(killerText, x + 2, y + 2, x + killerWidth, y + lineHeight, tocolor(0, 0, 0, alpha), 1, font, 'center', 'center')
dxDrawText(killerText, x, y, x + killerWidth, y + lineHeight, killerColor, 1, font, 'center', 'center')
dxDrawText(killerText, x + 1, y + 1, x + killerWidth + 1, y + lineHeight + 1, tocolor(0, 0, 0, alpha), 1, font, 'left', 'center')
dxDrawText(killerText, x, y, x + killerWidth, y + lineHeight, killerColor, 1, font, 'left', 'center')
end

y = y - lineHeight - padding
else
if v.icon.path and v.icon.texture and isElement(v.icon.texture) then
destroyElement(v.icon.texture)
end

table.remove(messages, k)

if (#messages == 0) then
removeEventHandler('onClientRender', root, renderMessages)
end

end
end
end
Expand Down
50 changes: 28 additions & 22 deletions [gameplay]/killmessages/scripts/client/c.utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,28 @@ local customIcons = {
[999] = "icons/generic.png",
}

function getMessageIcon(weapon, attacker)
local path
local textures = {}

if weapon then
path = customIcons[weapon] or 'icons/generic.png'
function getTexture(path)
if (type(path) ~= 'string') then
return false
end

if isElement(textures[path]) then
return textures[path]
end

if fileExists(path) then
textures[path] = dxCreateTexture(path)
return textures[path]
end

return false
end

function getMessageIcon(weapon, attacker)
local path

local elemType = isElement(attacker) and getElementType(attacker)

if (elemType == 'vehicle') then
Expand All @@ -161,38 +176,29 @@ function getMessageIcon(weapon, attacker)
elseif (elemType == 'player') then
local vehicle = getPedOccupiedVehicle(attacker)
if vehicle then
return getMessageIcon(_, vehicle)
return getMessageIcon(nil, vehicle)
end
end

if not path and weapon then
path = customIcons[weapon] or 'icons/generic.png'
end

path = path or 'icons/generic.png'

local texture = getTexture(path)

if texture then
local w, h = dxGetMaterialSize(texture)
return {
texture = texture,
width = dxGetMaterialSize(texture)
width = w or 32
}
end

return false
end

local textures = {}

function getTexture(path)
if (type(path) ~= 'string') then
return false
end

if (textures[path] ~= nil) then
return textures[path]
end

textures[path] = dxCreateTexture(path)

return textures[path]
end

function removeHex(s)
if (type(s) == "string") then
while (s ~= s:gsub("#%x%x%x%x%x%x", "")) do
Expand Down