local hook_t = require("hooks")
local ffi = require("ffi")
local gSize = 65
local cSize = (gSize / 10) - 2
local colors = {
health = 0xFFB22222,
armour = 0xFFAAAAAA
}
ffi.cdef [[
enum {
SAMP_VERSION_UNKNOWN = -1,
SAMP_VERSION_037R1,
SAMP_VERSION_037R3_1,
SAMP_VERSION_037R5_1,
};
typedef struct CVector { float x, y, z; } CVector;
]]
local SAMP_VERSIONS = {
[0x31DF13] = ffi.C.SAMP_VERSION_037R1,
[0xCC4D0] = ffi.C.SAMP_VERSION_037R3_1,
[0xCBC90] = ffi.C.SAMP_VERSION_037R5_1
}
local function draw_circle_bar(x, y, amount, color)
if amount > 100 then amount = 100 end
local circles = math.ceil(amount / 10)
if circles == 0 and amount ~= 0 then circles = 1 end
local size = gSize * (circles / 10)
x = x - (size / 2)
for i = 1, circles do
local size = cSize + 2
renderDrawPolygon(x, y, size, size, 50, 0, 0xFF000000)
renderDrawPolygon(x, y, cSize, cSize, 50, 0, color)
x = x + size
end
end
function main()
while not isSampAvailable() do wait(0) end
local hsamp = getModuleHandle("samp.dll")
local ntheader = hsamp + ffi.cast("long*", hsamp + 0x3C)[0]
local ep = ffi.cast("unsigned long*", ntheader + 0x28)[0]
local samp_version = SAMP_VERSIONS[ep] or ffi.C.SAMP_VERSION_UNKNOWN
-- public: void __thiscall CPlayerTags::DrawHealthBar(void*, class sampapi::CVector *, float, float, float)
local CPlayerTags__DrawHealthBar = {
signature = "void(__thiscall*)(void*, CVector*, float, float, float)",
offset = ({
[ffi.C.SAMP_VERSION_037R1] = 0x689C0,
[ffi.C.SAMP_VERSION_037R3_1] = 0x6C930
})[samp_version]
}
if not CPlayerTags__DrawHealthBar.offset then
error("This version of SAMP is not supported")
return
end
local function CPlayerTags__DrawHealthBar__Call(this, vector, health, armour, distanceToCamera)
if isPointOnScreen(vector.x, vector.y, vector.z) then
local x, y = convert3DCoordsToScreen(vector.x, vector.y, distanceToCamera * 0.047499999 + vector.z + 0.2)
y = y + 21
if armour > 0 then
draw_circle_bar(x, y, armour, colors.armour)
y = y + 10
end
draw_circle_bar(x, y, health, colors.health)
end
return
end
CPlayerTags__DrawHealthBar__Hook = hook_t.jmp.new(CPlayerTags__DrawHealthBar.signature, CPlayerTags__DrawHealthBar__Call, hsamp + CPlayerTags__DrawHealthBar.offset)
wait(-1)
end