Code:
fullBarSize = 128
setElementData ( lp, "hunger", 50, false )
function showHungerBar()
if tonumber ( getElementData ( lp, "loggedin" ) ) == 1 and not isCursorShowing () then
if gImage["foodbarBeginning"] then
guiSetVisible ( gImage["foodbarBeginning"], false )
guiSetVisible ( gImage["foodbarMiddle"], false )
guiSetVisible ( gImage["foodbarEnding"], false )
else
local screenwidth, screenheight = guiGetScreenSize ()
if screenwidth == 1440 then
gImage["foodbarBeginning"] = guiCreateStaticImage(screenwidth-211,113,5,18,"images/foodbar2.bmp",false)
gImage["foodbarMiddle"] = guiCreateStaticImage(screenwidth-206,113,fullBarSize,18,"images/foodbar1.bmp",false)
gImage["foodbarEnding"] = guiCreateStaticImage(screenwidth-211,113,5,18,"images/foodbar2.bmp",false)
else
gImage["foodbarBeginning"] = guiCreateStaticImage(screenwidth-211,0+20,5,18,"images/foodbar2.bmp",false)
gImage["foodbarMiddle"] = guiCreateStaticImage(screenwidth-206,0+20,fullBarSize,18,"images/foodbar1.bmp",false)
gImage["foodbarEnding"] = guiCreateStaticImage(screenwidth-211,0+20,5,18,"images/foodbar2.bmp",false)
end
end
resizeHungerBar()
end
end
function hungerDeathFix ()
if source == lp then
setElementData ( lp, "hunger", 40 )
end
end
addEventHandler ( "onClientPlayerWasted", getRootElement(), hungerDeathFix )
function resizeHungerBar()
local screenwidth, screenheight = guiGetScreenSize ()
local curfood = tonumber ( getElementData ( lp, "hunger" ) )
local barxsize = curfood/100*fullBarSize
guiSetSize ( gImage["foodbarMiddle"], barxsize, 18, false )
if screenwidth == 1440 then
guiSetPosition ( gImage["foodbarEnding"], screenwidth-206+barxsize, 113, false )
guiBringToFront ( gImage["foodbarEnding"] )
else
guiSetPosition ( gImage["foodbarEnding"], screenwidth-206+barxsize, 0+20, false )
guiBringToFront ( gImage["foodbarEnding"] )
end
end
function hideHungerBar()
guiSetVisible ( gImage["foodbarBeginning"], false )
guiSetVisible ( gImage["foodbarMiddle"], false )
guiSetVisible ( gImage["foodbarEnding"], false )
end
function moreHunger()
if getElementData ( lp, "jailtime" ) then
if getElementData ( lp, "jailtime" ) <= 0 and not pokering and not invulnerable then
local curhunger = getElementData ( lp, "hunger" ) - 1
if curhunger < 0 then curhunger = 0 end
setElementData ( lp, "hunger", curhunger, false )
if curhunger == 33 then
outputChatBox ( "Achtung, Du Wirst Bald Hungern , besorg dir etwas zu Essen!", 125, 0, 0 )
elseif curhunger < 25 then
local loss = math.floor((25-curhunger)/2*20)/10
setElementHealth ( lp, getElementHealth ( lp ) - loss )
hudEinblendenDmg_func ( 0, 0, 0, 0, false )
end
end
end
end
setTimer ( moreHunger, 50000, -1 )
function eatSomething_func ( value )
if not value then value = 100 end
setElementData ( lp, "hunger", getElementData ( lp, "hunger" )+value, false )
if getElementData ( lp, "hunger" ) > 100 then
setElementData ( lp, "hunger", 100, false )
end
showHungerBar()
setTimer ( hideHungerBar, 4000, 1 )
end
addEvent ( "eatSomething", false )
addEventHandler ( "eatSomething", getRootElement(), eatSomething_func )