lua hud

shtcinc

Известный
Автор темы
128
22
Версия MoonLoader
.026-beta
Восап, не понимаю как добавить или поменять переменную в худе так что бы я его мог сдвинуть вверх. И через что можно пофиксить выход за границы бара худа, а то на дрифт сервах это выглядит ужасно.

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(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 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

up
 

Вложения

  • 13.png
    13.png
    2.4 MB · Просмотры: 139
Последнее редактирование:

:re

Участник
32
10
1. Чтобы сдвинуть ХП - бар вверх тебе нужно убавлять какое - то число от переменной screenY
Lua:
drawBar(screenX - 50, screenY - 300, 100, 20, 0xBFDF0101, 0xBF610B0B, 2, font, HP)
-- Будет выше персонажа

2. Тебе нужно просто сравнивать своё ХП и если что - то не так, то задавать переменной новое значение
И да, соблюдай табуляцию, с ней код выглядит сексуальней =)
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(playerHandle) then
            local playerposX, playerposY, playerposZ = getCharCoordinates(playerPed)
            local screenX, screenY = convert3DCoordsToScreen(playerposX, playerposY, playerposZ)
            local HP = getCharHealth(playerPed)
            if HP > 101 then
                HP = 100
            else
                HP = HP
            end
            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 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

изображение_2022-07-17_223931166.png
 
Последнее редактирование:
  • Вау
Реакции: shtcinc