local memory = require 'memory'
local ffi = require 'ffi'
ffi.cdef[[
typedef struct RwRGBA { uint8_t red; uint8_t green; uint8_t blue; uint8_t alpha; } RwRGBA;
typedef struct CRGBA { RwRGBA rgba; } CRGBA;
]]
function main()
repeat wait(100) until isSampAvailable()
CSprite2D_DrawBarChart = ffi.cast("char(__cdecl*)(float, float, uint16_t, uint32_t, float, int, bool, bool, RwRGBA, RwRGBA)", 0x728640)
CRGBA_constructor = ffi.cast("CRGBA*(__thiscall*)(void*, uint8_t, uint8_t, uint8_t, uint8_t)", 0x7170C0)
addEventHandler("onD3DPresent", CHUD_RenderStaminaBar)
wait(-1)
end
function getSprintLocalPlayer()
return memory.getfloat(0xB7CDB4, 1) / 31.47000244
end
function CHUD_RenderStaminaBar()
-- sampfuncs console causes visual bugs
if not isPlayerPlaying(PLAYER_HANDLE) or isCharDead(PLAYER_PED) or sampIsScoreboardOpen() or isSampfuncsConsoleActive() then return 1 end
local sw, sh = getScreenResolution()
local width, height =
sw * 0.0015625 * 62.0,
sh * 0.002232143 * 8.5
local function getYBasedOnHealth(pos, offset)
return pos - sh * 0.002232143 * offset
end
local isPlayerInWater = isCharInWater(PLAYER_PED)
local color = CRGBA_constructor(ffi.new("CRGBA"), 0xBF, 0x94, 0x30, 0xFF)
local progressAddedColor = CRGBA_constructor(ffi.new("CRGBA"), 0, 0, 0, 0)
return CSprite2D_DrawBarChart(
sw - sw * 0.0015625 * 94.0,
getYBasedOnHealth(getYBasedOnHealth(sh * 0.002232143 * 68.0, isPlayerInWater and 17 or 6), isPlayerInWater and 17 or 6),
width, height,
getSprintLocalPlayer(),
0, 0, 1,
color.rgba, progressAddedColor.rgba
)
end