- 124
- 6
how can I add this function to my lua script?
script_name("HPbar")
script_description("example of using drawBar function")
script_version_number(1)
script_version("v.001")
script_authors("hnnssy")
function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
while not isSampAvailable() do wait(100) end
local font = renderCreateFont("Arial", 8, 5)
while true do
wait(0)
if not isPauseMenuActive() and isPlayerPlaying(playerHandle) then
local HP = getCharHealth(playerPed)
local playerposX, playerposY, playerposZ = getCharCoordinates(playerPed)
local screenX, screenY = convert3DCoordsToScreen(playerposX, playerposY, playerposZ)
drawBar(screenX - 50, screenY, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, HP)
end
end
end
function drawBar(posX, posY, sizeX, sizeY, color1, color2, borderThickness, font, value)
renderDrawBoxWithBorder(posX, posY, sizeX, sizeY, color2, borderThickness, 0xFF000000)
renderDrawBox(posX + borderThickness, posY + borderThickness, sizeX / 100 * value - (borderThickness * 2), sizeY - (2 * borderThickness), color1)
local textLength = renderGetFontDrawTextLength(font, tostring(value))
local textHeight = renderGetFontDrawHeight(font)
renderFontDrawText(font, tostring(value), posX + (sizeX / 2) - (textLenght / 2), posY + (sizeY / 2) - (textHeight / 2), 0xFFFFFFFF)
end
script_name("HPbar")
script_description("example of using drawBar function")
script_version_number(1)
script_version("v.001")
script_authors("hnnssy")
function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
while not isSampAvailable() do wait(100) end
local font = renderCreateFont("Arial", 8, 5)
while true do
wait(0)
if not isPauseMenuActive() and isPlayerPlaying(playerHandle) then
local HP = getCharHealth(playerPed)
local playerposX, playerposY, playerposZ = getCharCoordinates(playerPed)
local screenX, screenY = convert3DCoordsToScreen(playerposX, playerposY, playerposZ)
drawBar(screenX - 50, screenY, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, HP)
end
end
end
function drawBar(posX, posY, sizeX, sizeY, color1, color2, borderThickness, font, value)
renderDrawBoxWithBorder(posX, posY, sizeX, sizeY, color2, borderThickness, 0xFF000000)
renderDrawBox(posX + borderThickness, posY + borderThickness, sizeX / 100 * value - (borderThickness * 2), sizeY - (2 * borderThickness), color1)
local textLength = renderGetFontDrawTextLength(font, tostring(value))
local textHeight = renderGetFontDrawHeight(font)
renderFontDrawText(font, tostring(value), posX + (sizeX / 2) - (textLenght / 2), posY + (sizeY / 2) - (textHeight / 2), 0xFFFFFFFF)
end