Jump to content

Problemo - HUD


Eshtiz

Recommended Posts

Working on this, everything is fine, except for this:

the weapon box / icons doesn't show after /reconnect'ing

local screenX, screenY = guiGetScreenSize() 
local screenXStart = screenX - screenX
local screenYStart = screenY - screenY
 
function drawBox( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        dxDrawRectangle(screenX - 115, screenYStart + 70, 110, 12.5, tocolor(0, 0, 0, 200))
dxDrawRectangle(screenX - 115, screenYStart + 83, 110, 12.5, tocolor(0, 0, 0, 200))
       
 
    end 
end
 
   
-- CLOCK   
function getDayName( day )
    if day == 0 then
        return "Sun"
    elseif day == 1 then   
        return "Mon"
    elseif day == 2 then
        return "Tue"
    elseif day == 3 then
        return "Wed"
    elseif day == 4 then
        return "Thu"
    elseif day == 5 then
        return "Fri"
    elseif day == 6 then
        return "Sat"
    end
end
 
function getGameTime( )
    local hour, mins = getTime()
   
    if mins < 10 then
        mins = "0".. mins -- show '01' instead of '1' in minutes
    end
       
    return hour.. " : ".. mins
end
   
 
-- HEALTH
function getBarWidth( hp )
    if hp >= 100 then
        return 100 -- If hp is more than 100, it shouldn't go out of the bar
    else
        return hp
    end
end 
       
function drawHealthBar( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
        local health = getElementHealth( getLocalPlayer() )
       
        if health >= 80 then
            r = 153
            g = 0
            b = 0
            a = 255
        elseif health >= 60 and health < 80 then
            r = 153
            g = 0
            b = 0
            a = 255
        elseif health >= 40 and health < 60 then   
            r = 102
            g = 0
            b = 0
            a = 255
        elseif health < 40 then
            r = 51
            g = 0
            b = 0
           
           
            if blink == 1 or not blink then -- Make the bar blink
                blink = 0
                a = 0
            elseif blink == 0 then
                blink = 1
                a = 255
            end 
        end
 
        dxDrawRectangle(screenX - 110, screenYStart + 85, getBarWidth( health ), 8, tocolor(r, g, b, a))
    end 
end
   
-- ARMOR   
function getAmourBarWidth ( armour )
    if armour >= 100 then
        return 100 -- If armour is more than 100, it shouldn't go out of the bar
    else
        return armour
    end
end 
 
function drawArmourBar( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local armour = getPedArmor( getLocalPlayer() )
        if armour > 0 then -- Only if he has armor
 
        dxDrawRectangle(screenX - 110, screenYStart + 72, getAmourBarWidth( armour ), 8, tocolor(200, 200, 200, 255))
        end 
    end 
end
   
-- MONEY   
function drawMoney( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local money = getPlayerMoney( getLocalPlayer() )
       
        dxDrawText("$".. string.format("%08d", money), screenX - 121, screenYStart + 96, screenX, screenY, tocolor(0, 0, 0, 255), 1.03, "pricedown")
        dxDrawText("$".. string.format("%08d", money), screenX - 120, screenYStart + 97, screenX, screenY, tocolor(0, 102, 0, 255), 1, "pricedown")
 
    end 
end 
   
function onStartDisableHud( )
    showPlayerHudComponent("ammo", false)
    showPlayerHudComponent("armour", false)
    showPlayerHudComponent("breath", false)
    showPlayerHudComponent("clock", true)
    showPlayerHudComponent("health", false)
    showPlayerHudComponent("money", false)
    showPlayerHudComponent("weapon", true)
   
    bindKey("r", "down", onWeaponReload)
   
    drawWeaponImageOnChange( 0, getPedWeaponSlot(getLocalPlayer()))
   
    -- Render!
    addEventHandler("onClientRender", getRootElement(), drawBox) -- box
    addEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
    addEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
    addEventHandler("onClientRender", getRootElement(), drawMoney) -- money
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onStartDisableHud)
   
function onStopEnableHud( )
    showPlayerHudComponent("ammo", false)
    showPlayerHudComponent("armour", true)
    showPlayerHudComponent("breath", true)
    showPlayerHudComponent("clock", false)
    showPlayerHudComponent("health", true)
    showPlayerHudComponent("money", true)
    showPlayerHudComponent("weapon", false)
end 
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), onStopEnableHud)
 
function toggleHUD( state )
    if state == true then
       
        bindKey("r", "down", onWeaponReload)
   
        drawWeaponImageOnChange( 0, getPedWeaponSlot(getLocalPlayer()))
       
        -- Render!
            addEventHandler("onClientRender", getRootElement(), drawBox) -- box
        addEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
        addEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
        addEventHandler("onClientRender", getRootElement(), drawMoney) -- money
       
    elseif state == false then
       
        if isElement(weaponImg) then
            destroyElement(weaponImg)
        end
 
        if isElement(weaponAmmo) then
            destroyElement(weaponAmmo)
        end
       
 
        removeEventHandler("onClientRender", getRootElement(), drawClock) -- clock
        removeEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
        removeEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
        removeEventHandler("onClientRender", getRootElement(), drawMoney) -- money
    end
end
addEvent("toggleHUD", true)
addEventHandler("toggleHUD", getLocalPlayer(), toggleHUD)
 
local weaponMaxClip = -- Maximum ammo a weapon holds in its each clip
    {
        [16] = 1,
        [17] = 1,
        [18] = 1,
        [22] = 17,
        [23] = 17,
        [24] = 7,
        [25] = 1,
        [26] = 2,
        [27] = 7,
        [28] = 50,
        [29] = 30,
        [30] = 30,
        [31] = 50,
        [32] = 50,
        [33] = 1,
        [34] = 1,
        [35] = 1,
        [36] = 1,
        [39] = 1,
        [41] = 500,
        [42] = 500,
        [43] = 36,
        [37] = 50,
        [38] = 500
   
    }
 
function onWeaponReload( )
    if (getPedWeapon(getLocalPlayer()) ~= 0) then
       
        setTimer(function()
       
            local ammoInClip = getPedAmmoInClip(getLocalPlayer())
            local ammo = getPedTotalAmmo(getLocalPlayer()) - ammoInClip
           
            if isElement(weaponAmmo) then
                guiSetText(weaponAmmo, tostring(ammo) .." - ".. tostring(ammoInClip))
            end
       
        end, 1500, 1)
    end
end
   
-- WEAPON HUD IMAGES & AMMO
function drawWeaponImageOnChange( prevSlot, newSlot )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local weapon = getPedWeapon(getLocalPlayer(), newSlot)
           
       
        local ammoInClip = getPedAmmoInClip(getLocalPlayer())
        local ammo = getPedTotalAmmo(getLocalPlayer()) - ammoInClip
       
        if (newSlot ~= 0 and newSlot ~= 1 and newSlot ~= 10 and newSlot ~= 11 and newSlot ~= 12) then
           
            if not isElement(weaponAmmo) then
                weaponAmmo = guiCreateLabel(screenX - 180, screenYStart + 86, 100, 100, tostring(ammo) .." - ".. tostring(ammoInClip), false)
                guiSetFont(weaponAmmo, "default-bold-small")
            else
               
Link to comment

That's fixed, but still if I /reconnect the weapon box / icons disappear.

EDIT: doesn't seem to be fixed,

I deleted the row where the error was and the same error I think, on the exact same row o.O

EDIT: Fixed.

back to this:

That's fixed, but still if I /reconnect the weapon box / icons disappear.

Link to comment

Nop, no errors at all :S

EDIT:

Trying to set it as the default weapon box / icons, that's all, but doesn't show after reconnecting or logging in. I have to restart the resource to make "new-ly" logged in players see it.

NOTE: If I stop the hud-system resource, the weapon box doesn't show, even after it being stopped!

Link to comment

Fixed:

local screenX, screenY = guiGetScreenSize() 
local screenXStart = screenX - screenX
local screenYStart = screenY - screenY
 
function drawBox( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        dxDrawRectangle(screenX - 115, screenYStart + 70, 110, 12.5, tocolor(0, 0, 0, 200))
dxDrawRectangle(screenX - 115, screenYStart + 83, 110, 12.5, tocolor(0, 0, 0, 200))
       
 
    end
end
 
   
-- CLOCK  
function getDayName( day )
    if day == 0 then
        return "Sun"
    elseif day == 1 then  
        return "Mon"
    elseif day == 2 then
        return "Tue"
    elseif day == 3 then
        return "Wed"
    elseif day == 4 then
        return "Thu"
    elseif day == 5 then
        return "Fri"
    elseif day == 6 then
        return "Sat"
    end
end
 
function getGameTime( )
    local hour, mins = getTime()
   
    if mins < 10 then
        mins = "0".. mins -- show '01' instead of '1' in minutes
    end
       
    return hour.. " : ".. mins
end
   
 
-- HEALTH
function getBarWidth( hp )
    if hp >= 100 then
        return 100 -- If hp is more than 100, it shouldn't go out of the bar
    else
        return hp
    end
end
       
function drawHealthBar( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
        local health = getElementHealth( getLocalPlayer() )
       
        if health >= 80 then
            r = 153
            g = 0
            b = 0
            a = 255
        elseif health >= 60 and health < 80 then
            r = 153
            g = 0
            b = 0
            a = 255
        elseif health >= 40 and health < 60 then  
            r = 102
            g = 0
            b = 0
            a = 255
        elseif health < 40 then
            r = 51
            g = 0
            b = 0
           
           
            if blink == 1 or not blink then -- Make the bar blink
                blink = 0
                a = 0
            elseif blink == 0 then
                blink = 1
                a = 255
            end
        end
 
        dxDrawRectangle(screenX - 110, screenYStart + 85, getBarWidth( health ), 8, tocolor(r, g, b, a))
    end
end
   
-- ARMOR  
function getAmourBarWidth ( armour )
    if armour >= 100 then
        return 100 -- If armour is more than 100, it shouldn't go out of the bar
    else
        return armour
    end
end
 
function drawArmourBar( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local armour = getPedArmor( getLocalPlayer() )
        if armour > 0 then -- Only if he has armor
 
        dxDrawRectangle(screenX - 110, screenYStart + 72, getAmourBarWidth( armour ), 8, tocolor(200, 200, 200, 255))
        end
    end
end
   
-- MONEY  
function drawMoney( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local money = getPlayerMoney( getLocalPlayer() )
       
        dxDrawText("$".. string.format("%08d", money), screenX - 121, screenYStart + 96, screenX, screenY, tocolor(0, 0, 0, 255), 1.03, "pricedown")
        dxDrawText("$".. string.format("%08d", money), screenX - 120, screenYStart + 97, screenX, screenY, tocolor(0, 102, 0, 255), 1, "pricedown")
 
    end
end
   
function onStartDisableHud( )
    showPlayerHudComponent("ammo", false)
    showPlayerHudComponent("armour", false)
    showPlayerHudComponent("breath", false)
    showPlayerHudComponent("clock", true)
    showPlayerHudComponent("health", false)
    showPlayerHudComponent("money", false)
    showPlayerHudComponent("weapon", true)
   
    bindKey("r", "down", onWeaponReload)
   
    drawWeaponImageOnChange( 0, getPedWeaponSlot(getLocalPlayer()))
   
    -- Render!
    addEventHandler("onClientRender", getRootElement(), drawBox) -- box
    addEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
    addEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
    addEventHandler("onClientRender", getRootElement(), drawMoney) -- money
end
addEventHandler("onClientResourceStart", getRootElement(), onStartDisableHud)
   
function onStopEnableHud( )
    showPlayerHudComponent("ammo", false)
    showPlayerHudComponent("armour", true)
    showPlayerHudComponent("breath", true)
    showPlayerHudComponent("clock", false)
    showPlayerHudComponent("health", true)
    showPlayerHudComponent("money", true)
    showPlayerHudComponent("weapon", false)
end
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), onStopEnableHud)
 
function toggleHUD( state )
    if state == true then
       
        bindKey("r", "down", onWeaponReload)
   
        drawWeaponImageOnChange( 0, getPedWeaponSlot(getLocalPlayer()))
       
        -- Render!
            addEventHandler("onClientRender", getRootElement(), drawBox) -- box
        addEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
        addEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
        addEventHandler("onClientRender", getRootElement(), drawMoney) -- money
       
    elseif state == false then
       
        if isElement(weaponImg) then
            destroyElement(weaponImg)
        end
 
        if isElement(weaponAmmo) then
            destroyElement(weaponAmmo)
        end
       
 
        removeEventHandler("onClientRender", getRootElement(), drawClock) -- clock
        removeEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
        removeEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
        removeEventHandler("onClientRender", getRootElement(), drawMoney) -- money
    end
end
addEvent("toggleHUD", true)
addEventHandler("toggleHUD", getLocalPlayer(), toggleHUD)
 
local weaponMaxClip = -- Maximum ammo a weapon holds in its each clip
    {
        [16] = 1,
        [17] = 1,
        [18] = 1,
        [22] = 17,
        [23] = 17,
        [24] = 7,
        [25] = 1,
        [26] = 2,
        [27] = 7,
        [28] = 50,
        [29] = 30,
        [30] = 30,
        [31] = 50,
        [32] = 50,
        [33] = 1,
        [34] = 1,
        [35] = 1,
        [36] = 1,
        [39] = 1,
        [41] = 500,
        [42] = 500,
        [43] = 36,
        [37] = 50,
        [38] = 500
   
    }
 
function onWeaponReload( )
    if (getPedWeapon(getLocalPlayer()) ~= 0) then
       
        setTimer(function()
       
            local ammoInClip = getPedAmmoInClip(getLocalPlayer())
            local ammo = getPedTotalAmmo(getLocalPlayer()) - ammoInClip
           
            if isElement(weaponAmmo) then
                guiSetText(weaponAmmo, tostring(ammo) .." - ".. tostring(ammoInClip))
            end
       
        end, 1500, 1)
    end
end
   
-- WEAPON HUD IMAGES & AMMO
function drawWeaponImageOnChange( prevSlot, newSlot )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local weapon = getPedWeapon(getLocalPlayer(), newSlot)
           
       
        local ammoInClip = getPedAmmoInClip(getLocalPlayer())
        local ammo = getPedTotalAmmo(getLocalPlayer()) - ammoInClip
       
        if (newSlot ~= 0 and newSlot ~= 1 and newSlot ~= 10 and newSlot ~= 11 and newSlot ~= 12) then
           
            if not isElement(weaponAmmo) then
                weaponAmmo = guiCreateLabel(screenX - 180, screenYStart + 86, 100, 100, tostring(ammo) .." - ".. tostring(ammoInClip), false)
                guiSetFont(weaponAmmo, "default-bold-small")
            else
               
Link to comment

Still have the same problem :?

also noticed that the clock/watch doesn't show either after a relog/login/reconnect.

local screenX, screenY = guiGetScreenSize() 
local screenXStart = screenX - screenX
local screenYStart = screenY - screenY
 
function drawBox( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        dxDrawRectangle(screenX - 115, screenYStart + 70, 110, 12.5, tocolor(0, 0, 0, 230))
dxDrawRectangle(screenX - 115, screenYStart + 83, 110, 12.5, tocolor(0, 0, 0, 230))
       
 
    end 
end
 
   
-- CLOCK   
function getDayName( day )
    if day == 0 then
        return "Sun"
    elseif day == 1 then   
        return "Mon"
    elseif day == 2 then
        return "Tue"
    elseif day == 3 then
        return "Wed"
    elseif day == 4 then
        return "Thu"
    elseif day == 5 then
        return "Fri"
    elseif day == 6 then
        return "Sat"
    end
end
 
function getGameTime( )
    local hour, mins = getTime()
   
    if mins < 10 then
        mins = "0".. mins -- show '01' instead of '1' in minutes
    end
       
    return hour.. " : ".. mins
end
   
 
-- HEALTH
function getBarWidth( hp )
    if hp >= 100 then
        return 100 -- If hp is more than 100, it shouldn't go out of the bar
    else
        return hp
    end
end 
       
function drawHealthBar( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
        local health = getElementHealth( getLocalPlayer() )
       
        if health >= 80 then
            r = 153
            g = 0
            b = 0
            a = 255
        elseif health >= 60 and health < 80 then
            r = 153
            g = 0
            b = 0
            a = 255
        elseif health >= 40 and health < 60 then   
            r = 153
            g = 0
            b = 0
            a = 255
        elseif health < 40 then
            r = 153
            g = 0
            b = 0
           
 
        end
 
        dxDrawRectangle(screenX - 110, screenYStart + 85, getBarWidth( health ), 8, tocolor(r, g, b, a))
    end 
end
   
-- ARMOR   
function getAmourBarWidth ( armour )
    if armour >= 100 then
        return 100 -- If armour is more than 100, it shouldn't go out of the bar
    else
        return armour
    end
end 
 
function drawArmourBar( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local armour = getPedArmor( getLocalPlayer() )
        if armour > 0 then -- Only if he has armor
 
        dxDrawRectangle(screenX - 110, screenYStart + 72, getAmourBarWidth( armour ), 8, tocolor(200, 200, 200, 255))
        end 
    end 
end
 
-- MONEY   
function drawPocketMoney( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local money = getPlayerMoney( getLocalPlayer() )
       
        dxDrawText("$".. string.format("%08d", money), screenX - 105, screenYStart + 42, screenX, screenY, tocolor(0, 0, 0, 200), 0.8, "pricedown")
        dxDrawText("$".. string.format("%08d", money), screenX - 105, screenYStart + 43, screenX, screenY, tocolor(204, 204, 0, 200), 0.8, "pricedown")
 
    end 
end 
   
-- MONEY   
function drawMoney( )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local money = getPlayerMoney( getLocalPlayer() )
                local money = getElementData(localPlayer, "bankmoney")
       
        dxDrawText("Bank:".. string.format("%08d", money), screenX - 133, screenYStart + 96, screenX, screenY, tocolor(0, 0, 0, 200), 0.8, "pricedown")
        dxDrawText("Bank:".. string.format("%08d", money), screenX - 133, screenYStart + 94, screenX, screenY, tocolor(204, 204, 204, 200), 0.8, "pricedown")
 
    end 
end 
   
function onStartDisableHud( )
    showPlayerHudComponent("ammo", false)
    showPlayerHudComponent("armour", false)
    showPlayerHudComponent("breath", false)
    showPlayerHudComponent("clock", false)
    showPlayerHudComponent("health", false)
    showPlayerHudComponent("money", false)
    showPlayerHudComponent("weapon", true)
   
    bindKey("r", "down", onWeaponReload)
   
    drawWeaponImageOnChange( 0, getPedWeaponSlot(getLocalPlayer()))
   
    -- Render!
    addEventHandler("onClientRender", getRootElement(), drawBox) -- box
    addEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
    addEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
    addEventHandler("onClientRender", getRootElement(), drawMoney) -- bankmoney
    addEventHandler("onClientRender", getRootElement(), drawPocketMoney) -- pocketmoney
end 
addEventHandler("onClientResourceStart", getRootElement(), onStartDisableHud)
   
function onStopEnableHud( )
    showPlayerHudComponent("ammo", false)
    showPlayerHudComponent("armour", true)
    showPlayerHudComponent("breath", true)
    showPlayerHudComponent("clock", false)
    showPlayerHudComponent("health", true)
    showPlayerHudComponent("money", true)
end 
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), onStopEnableHud)
 
function toggleHUD( state )
    if state == true then
       
        bindKey("r", "down", onWeaponReload)
   
        drawWeaponImageOnChange( 0, getPedWeaponSlot(getLocalPlayer()))
       
       
    elseif state == false then
       
        if isElement(weaponImg) then
            destroyElement(weaponImg)
        end
 
        if isElement(weaponAmmo) then
            destroyElement(weaponAmmo)
        end
       
 
        removeEventHandler("onClientRender", getRootElement(), drawClock) -- clock
        removeEventHandler("onClientRender", getRootElement(), drawHealthBar) -- health
        removeEventHandler("onClientRender", getRootElement(), drawArmourBar) -- armour
        removeEventHandler("onClientRender", getRootElement(), drawMoney) -- money
    end
end
addEvent("toggleHUD", true)
addEventHandler("toggleHUD", getLocalPlayer(), toggleHUD)
 
local weaponMaxClip = -- Maximum ammo a weapon holds in its each clip
    {
        [16] = 1,
        [17] = 1,
        [18] = 1,
        [22] = 17,
        [23] = 17,
        [24] = 7,
        [25] = 1,
        [26] = 2,
        [27] = 7,
        [28] = 50,
        [29] = 30,
        [30] = 30,
        [31] = 50,
        [32] = 50,
        [33] = 1,
        [34] = 1,
        [35] = 1,
        [36] = 1,
        [39] = 1,
        [41] = 500,
        [42] = 500,
        [43] = 36,
        [37] = 50,
        [38] = 500
   
    }
 
function onWeaponReload( )
    if (getPedWeapon(getLocalPlayer()) ~= 0) then
       
        setTimer(function()
       
            local ammoInClip = getPedAmmoInClip(getLocalPlayer())
            local ammo = getPedTotalAmmo(getLocalPlayer()) - ammoInClip
           
            if isElement(weaponAmmo) then
                guiSetText(weaponAmmo, tostring(ammo) .." - ".. tostring(ammoInClip))
            end
       
        end, 1500, 1)
    end
end
   
-- WEAPON HUD IMAGES & AMMO
function drawWeaponImageOnChange( prevSlot, newSlot )
    if getElementData(getLocalPlayer(), "loggedin") == 1 then
       
        local weapon = getPedWeapon(getLocalPlayer(), newSlot)
           
       
        local ammoInClip = getPedAmmoInClip(getLocalPlayer())
        local ammo = getPedTotalAmmo(getLocalPlayer()) - ammoInClip
       
        if (newSlot ~= 0 and newSlot ~= 1 and newSlot ~= 10 and newSlot ~= 11 and newSlot ~= 12) then
           
            if not isElement(weaponAmmo) then
                weaponAmmo = guiCreateLabel(screenX - 180, screenYStart + 86, 100, 100, tostring(ammo) .." - ".. tostring(ammoInClip), false)
                guiSetFont(weaponAmmo, "default-bold-small")
            else
               
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...