need help

Runbu73

Участник
Автор темы
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
 
  • Грустно
Реакции: recxvery

Vintik

Через тернии к звёздам
Проверенный
1,556
1,027
not sure that i understood you correctly.
first of all, you need to add drawBar function to your script
Lua:
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
and after that you should use drawBar function (call it) in a loop when you want to show this bar.
this function draws bar for 1 frame, so you should call it every frame in a loop until you want to hide bar.
is it clear?