hpbar help

Статус
В этой теме нельзя размещать новые ответы.

TadasD

Новичок
Автор темы
15
0
hi guys, i know u all chat in russian, but i always use translator to search information in this forum because i don't understand russian. all i wanted to ask is how to make this hpbar to have armor and hp numbers in one drawbar? https://blast.hk/threads/15519/ thank you :)
while true do
wait(0)
if not isPauseMenuActive() and isPlayerPlaying(playerHandle) then
if active == 1 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
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 textLenght = renderGetFontDrawTextLength(font, tostring(value))
local textHeight = renderGetFontDrawHeight(font)
renderFontDrawText(font, tostring(value), posX + (sizeX / 2) - (textLenght / 2), posY + (sizeY / 2) - (textHeight / 2), 0xFFFFFFFF)
end
 
Последнее редактирование:

Frapsy

Известный
Проверенный
393
226
Чтобы сделать показатель брони, который отличается от здоровья цветом - продублируй drawBar, но немного опусти дубль по координатам, чтобы под здоровьем была полоска иного цвета, как индикатор брони. А чтобы сам текст сделать один, то в одном из drawBar оставь параметр "value" пустым, чтобы текста не было, а в другом к здоровью добавь бронь.. К примеру:
Lua:
if not isPauseMenuActive() and isPlayerPlaying(PLAYER_HANDLE) then
    local textBar = "HP: "..getCharHealth(PLAYER_PED)..", armour: "..getCharArmour(PLAYER_PED)
    local playerposX, playerposY, playerposZ = getCharCoordinates(PLAYER_PED)
    local screenX, screenY = convert3DCoordsToScreen(playerposX, playerposY, playerposZ)
    drawBar(screenX - 50, screenY, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, textBar) -- varible textBar show health and armour.
    --drawBar(screenX - 50, screenY-50, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, "") -- you need to change colors, if you want get armour indicator under health indicator, but this isn't necessary, if you don't need it
end

Выходит как то так.
 
  • Нравится
Реакции: TadasD

TadasD

Новичок
Автор темы
15
0
Чтобы сделать показатель брони, который отличается от здоровья цветом - продублируй drawBar, но немного опусти дубль по координатам, чтобы под здоровьем была полоска иного цвета, как индикатор брони. А чтобы сам текст сделать один, то в одном из drawBar оставь параметр "value" пустым, чтобы текста не было, а в другом к здоровью добавь бронь.. К примеру:
Lua:
if not isPauseMenuActive() and isPlayerPlaying(PLAYER_HANDLE) then
    local textBar = "HP: "..getCharHealth(PLAYER_PED)..", armour: "..getCharArmour(PLAYER_PED)
    local playerposX, playerposY, playerposZ = getCharCoordinates(PLAYER_PED)
    local screenX, screenY = convert3DCoordsToScreen(playerposX, playerposY, playerposZ)
    drawBar(screenX - 50, screenY, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, textBar) -- varible textBar show health and armour.
    --drawBar(screenX - 50, screenY-50, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, "") -- you need to change colors, if you want get armour indicator under health indicator, but this isn't necessary, if you don't need it
end

Выходит как то так.
thank you, hp and armour didn't work in one textbar, but got this to work
and just one thing, how to change colors with that 0x prefix?
 

Frapsy

Известный
Проверенный
393
226
Показатель брони вместе со здоровьем не работал из-за того что value должна быть числом, чтобы дальше использоваться в вычислениях. 5 минут работы и ты получаешь то, что хотел, держи:
Lua:
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(PLAYER_HANDLE) then
            local HP = getCharHealth(PLAYER_PED)
            local armour = getCharArmour(PLAYER_PED)
            --local textBar = "HP: "..getCharHealth(PLAYER_PED)..", armour: "..getCharArmour(PLAYER_PED)
            local playerposX, playerposY, playerposZ = getCharCoordinates(playerPed)
            local screenX, screenY = convert3DCoordsToScreen(playerposX, playerposY, playerposZ)
            drawBar(screenX - 50, screenY, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, HP, HP.." | "..armour)
            drawBar(screenX - 50, screenY, 100, 8, 0xFFCFCFCF, 0xFF4D4D4D, 2, font, armour, "")
        end
    end
end

function drawBar(posX, posY, sizeX, sizeY, color1, color2, borderThickness, font, value, text)
    renderDrawBoxWithBorder(posX, posY, sizeX, sizeY, color2, borderThickness, 0xFF000000)
    renderDrawBox(posX + borderThickness, posY + borderThickness, sizeX / 100 * value - (borderThickness * 2), sizeY - (2 * borderThickness), color1)
    local textLenght = renderGetFontDrawTextLength(font, tostring(text))
    local textHeight = renderGetFontDrawHeight(font)
    renderFontDrawText(font, tostring(text), posX + (sizeX / 2) - (textLenght / 2), posY + (sizeY / 2) - (textHeight / 3), 0xFFFFFFFF)
end
У функции появился параметр text, который отвечает за то, что нужно выводить на drawBar, если параметр не заполнять, то выведет nil, так что, лучше держать пустоту в виде "".
 
  • Нравится
Реакции: TadasD и Heinz Winkel
Статус
В этой теме нельзя размещать новые ответы.