Jump to content

Hud Does Not Reduce Hunger and Thirst


Perigo

Recommended Posts

Hello, I'm having a problem with a hud that the player's hunger/thirst doesn't reduce for him to feel hungry/thirsty, I tried to reduce manually by the script defining the limit and I also realized that the character is not degrading his life by hunger/thirst, could you help.

 

local sx, sy = guiGetScreenSize()
local link = "http://mta/"..getResourceName(getThisResource()).."/web-side/index.html"
local browser = createBrowser(sx, sy, true, true)
local components = { "area_name", "radio", "vehicle_name" }

setDevelopmentMode(true, true)

local player = {}

local vehicle = false
local voiceEnabled = true

function dxHud()
    dxDrawImage(0, 0, sx, sy, browser)
end

function updateDX( )
    local health = getElementHealth(localPlayer)
    local armour = getPedArmor(localPlayer)
    local hunger = getElementData(localPlayer, configs['Elements']['Fome']) or 100
    local thirst = getElementData(localPlayer, configs['Elements']['Sede']) or 100
    local stress = getElementData(localPlayer, configs['Elements']['Stress']) or 100
    local radio = getElementData(localPlayer, "ae.frequencia") or 0

    local x,y,z = getElementPosition(localPlayer)
    local street = getZoneName ( x, y, z, true )
    local direction = getZoneName ( x, y, z, false )

    local time = getRealTime()
    local hours = ""..time.hour..":"..time.minute
    local minutes = time.minute;

    if getPedOccupiedVehicle(localPlayer) then

        fuel = getElementData(getPedOccupiedVehicle(getLocalPlayer()), configs['Elements']['fuel']) or 100
        speed = ( function( x, y, z ) return math.floor( math.sqrt( x*x + y*y + z*z ) * 155 ) end )( getElementVelocity( getPedOccupiedVehicle(localPlayer) ) ) 

end
  
    SendNUIMessage(browser, { vehicle = vehicle, talking = talking, health = health, armour = armour, thirst = thirst, hunger = hunger, street = street, radio = radio, time = hours, minutes = minutes, direction = direction, voice = voice, speed = speed, fuel = fuel })
end

 function SendNUIMessage(browser, table)
    if isElement(browser) and type(table) == "table" then
        return executeBrowserJavascript(browser, 'window.postMessage('..toJSON(table)..'[0])')
    end
end

 addEventHandler("onClientBrowserCreated", browser, function()
    loadBrowserURL(source, link)
 end)
 
 addEventHandler( "onClientBrowserDocumentReady", browser, 
 function (url)
    SendNUIMessage(browser, {hud = true})

    addEventHandler( "onClientRender", getRootElement(), dxHud)
 end)

 function EntrarEsair()
    if getPedOccupiedVehicle(getLocalPlayer()) then 
       vehicle = true
    else
        vehicle = false
    end
 end



setTimer(function()
    EntrarEsair(1)
    updateDX(1)
end, 50, 10)

function setHud()
    setPlayerHudComponentVisible("armour", false)
    setPlayerHudComponentVisible("wanted", false)
    setPlayerHudComponentVisible("weapon", false)
    setPlayerHudComponentVisible("money", false)
    setPlayerHudComponentVisible("health", false)
    setPlayerHudComponentVisible("clock", false)
    setPlayerHudComponentVisible("breath", false)
    setPlayerHudComponentVisible("ammo", false)
    setPlayerHudComponentVisible("radar", false)

    for _, component in ipairs( components ) do
        setPlayerHudComponentVisible( component, false )
    end
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), setHud)


addEventHandler('onClientPlayerVoiceStart', root,
	function()
		if (source == localPlayer) then
			talking = true
		end
	end
)

addEventHandler('onClientPlayerVoiceStop', root,
	function()
		if (source == localPlayer) then
			talking = false
		end
	end
)



 

configs = {

    ['Elements'] = {

        ['Fome'] = 'hunger',
        ['Sede'] = 'sede',
        ['Stress'] = 'AC-Stress',
        ['fuel'] = 'Gasolina',

    },

}

 

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