Jump to content

[HELP] Hunger system


furruz

Recommended Posts

Well i have seen a little and i have thinked bout use exported functions. I'm tryin it

CLIENT

hamburgerPositions = { {450,-83,999.55,4} } -- The positions for the hamburger, in the style: x,y,z,interior 
--[[ 
  
This is the hunger script. You can add hamburgers by adding it in hamburgerPositions. 
It works easy, just a after it, and filling in! 
  
{x,y,z,interiorID} 
When it isn't the last position, it needs a "," after it 
  
]]-- 
  
-- DONT CHANGE ANYTHING AFTER THIS WITHOUT KNOWLEDGE! 
addEventHandler ("onClientResourceStart",getResourceRootElement(getThisResource()), 
function () 
  hungerProcess = guiCreateProgressBar(0.7763,0.28,0.1775,0.04,true) 
  guiMoveToBack (hungerProcess) 
  guiProgressBarSetProgress(hungerProcess,100) 
  hungerLabel = guiCreateLabel(0.7775,0.2817,0.1737,0.0367,"Hambre",true) 
  guiLabelSetColor(hungerLabel,200,0,0) 
  guiLabelSetVerticalAlign(hungerLabel,"center") 
  guiLabelSetHorizontalAlign(hungerLabel,"center",false) 
  guiSetFont(hungerLabel,"default-bold-small") 
  for i,v in ipairs (hamburgerPositions) do 
    local hamburger = createPickup (v[1],v[2],v[3],3,2768,100) 
    local hamburgerMarker = createMarker (v[1],v[2],v[3],"corona",2,255,255,0,255) 
    setElementData (hamburgerMarker,"HAMBURGER!",true) 
    setElementInterior (hamburgerMarker,v[4]) 
    setElementInterior (hamburger,v[4]) 
  end 
  setTimer (dropDownHungerState,45000,0,getLocalPlayer()) 
end) 
  
function setHungerState (player,hungerState) 
  if (player == getLocalPlayer()) then 
    guiProgressBarSetProgress(hungerProcess,hungerState) 
  end 
end  
  
function getHungerState (player) 
  if (player == getLocalPlayer()) then 
    return guiProgressBarGetProgress(hungerProcess) 
  end 
end 
  
function dropDownHungerState (player) 
  if (player == getLocalPlayer()) then 
    guiProgressBarSetProgress(hungerProcess,guiProgressBarGetProgress(hungerProcess) -1) 
    if (guiProgressBarGetProgress(hungerProcess) == 0) then 
      setElementHealth (player,getElementHealth (player) -25) 
      outputChatBox ("Rapido! Debes alimentarte si no quieres morir!",255,0,0,false) 
    elseif (guiProgressBarGetProgress(hungerProcess) == 10) then 
      outputChatBox ("Sientes hambre",255,0,0,false) 
    end 
  end 
end  
  
addEventHandler ("onClientPlayerSpawn",getRootElement(), 
function (team) 
  setHungerState (source,100) 
end) 
  
addEventHandler ("onClientMarkerHit",getRootElement(), 
function(hitEle,dim) 
  if (getLocalPlayer() == hitEle) and (getElementData (source,"HAMBURGER!") == true) then 
    if (getHungerState (hitEle) < 80) then 
      setHungerState (hitEle,100) 
      outputChatBox ("Comes algo y renuevas tus fuerzas.",255,0,255,false) 
      outputChatBox ("Ya no sientes hambre.",255,0,255,false) 
    else 
      outputChatBox ("No necesitas comer en este momento.",255,0,255,false) 
    end 
  end 
end) 
  
addEvent("setHungerState", true) 
addEventHandler("setHungerState", root, setHungerState) 
  
addEvent("getHungerState", true) 
addEventHandler("getHungerState", root, getHungerState) 
  
-- Made by JasperNL=D  

SERVER

function getHungerStateSrv(player) 
        triggerClientEvent(player, "getHungerState", player) 
    end 
     
function setHungerStateSrv(player, hungerState) 
        triggerClientEvent(player, "setHungerState", player, hungerstate) 
    end 

META

<meta> 
  <info author="JasperNL=D" version="1.0" name="Hunger!" description="The Super-hunger snippet! every server needs it :D" type="script" /> 
  <script src="hunger.lua" type="client" /> 
  <script src="server.lua" type="server" /> 
  <export function="setHungerStateSrv" type="server"/> 
  <export function="getHungerStateSrv" type="server"/> 
</meta> 

used function:

exports.hunger:setHungerStateSrv ( source, math.max( 100, exports.hunger:getHungerStateSrv( source ) + 20 ) ) 

error:

attempt to perform arithmetic on a nil value 

Can anyone help me? thanks

Edited by Guest
Link to post
Nevermind, we're going off topic. ( DayZ is a mod of Arma2 and makes it a huge MMO Zombie game, its the best thing I've played, EVER ).

I don't know whats wrong with your script, sorry.

really interesting, i will see it. thnx ;)

I want to make the script serverside to allow food items to increase hunger

Edited the code in english

Link to post

(sorry for double post)

It is posible to take this script http://community.multitheftauto.com/index.php?p=resources&s=details&id=906

hamburgerPositions = { {372.82,-65.68,1001.51,10}, {380.44,-8.65,1001.85,9}, {379.42,-119.65,1001.49,5} } -- The positions for the hamburger, in the style: x,y,z,interior 
--[[ 
  
This is the hunger script. You can add hamburgers by adding it in hamburgerPositions. 
It works easy, just a after it, and filling in! 
  
{x,y,z,interiorID} 
When it isn't the last position, it needs a "," after it 
  
]]-- 
  
-- DONT CHANGE ANYTHING AFTER THIS WITHOUT KNOWLEDGE! 
addEventHandler ("onClientResourceStart",getResourceRootElement(getThisResource()), 
function () 
  hungerProcess = guiCreateProgressBar(0.7763,0.28,0.1775,0.04,true) 
  guiMoveToBack (hungerProcess) 
  guiProgressBarSetProgress(hungerProcess,100) 
  hungerLabel = guiCreateLabel(0.7775,0.2817,0.1737,0.0367,"Hunger State",true) 
  guiLabelSetColor(hungerLabel,255,255,255) 
  guiLabelSetVerticalAlign(hungerLabel,"center") 
  guiLabelSetHorizontalAlign(hungerLabel,"center",false) 
  guiSetFont(hungerLabel,"default-small") 
  for i,v in ipairs (hamburgerPositions) do 
    local hamburger = createPickup (v[1],v[2],v[3],3,2768,100) 
    local hamburgerMarker = createMarker (v[1],v[2],v[3],"corona",1,255,255,0,80) 
    setElementData (hamburgerMarker,"HAMBURGER!",true) 
    setElementInterior (hamburgerMarker,v[4]) 
    setElementInterior (hamburger,v[4]) 
  end 
  setTimer (dropDownHungerState,45000,0,getLocalPlayer()) 
end) 
  
function setHungerState (player,hungerState) 
  if (player == getLocalPlayer()) then 
    guiProgressBarSetProgress(hungerProcess,hungerState) 
  end 
end  
  
function getHungerState (player) 
  if (player == getLocalPlayer()) then 
    return guiProgressBarGetProgress(hungerProcess) 
  end 
end 
  
function dropDownHungerState (player) 
  if (player == getLocalPlayer()) then 
    guiProgressBarSetProgress(hungerProcess,guiProgressBarGetProgress(hungerProcess) -1) 
    if (guiProgressBarGetProgress(hungerProcess) == 0) then 
      setElementHealth (player,getElementHealth (player) -25) 
      outputChatBox ("FAST! You'll get die when you don't eat!",255,0,0,false) 
    elseif (guiProgressBarGetProgress(hungerProcess) == 10) then 
      outputChatBox ("Warning! You begin to become hungry!",255,0,0,false) 
    end 
  end 
end  
  
addEventHandler ("onClientPlayerSpawn",getRootElement(), 
function (team) 
  setHungerState (source,100) 
end) 
  
addEventHandler ("onClientMarkerHit",getRootElement(), 
function(hitEle,dim) 
  if (getLocalPlayer() == hitEle) and (getElementData (source,"HAMBURGER!") == true) then 
    if (getHungerState (hitEle) < 50) then 
      setHungerState (hitEle,100) 
      outputChatBox ("HAMBURGER POWER!",255,0,255,false) 
      outputChatBox ("You haven't got hunger any more :D",255,0,255,false) 
    else 
      outputChatBox ("You don't need to eat!",255,0,255,false) 
    end 
  end 
end) 
  
-- Made by JasperNL=D  

and change the markers to a server-side function? I want to make my items (from mta paradise, modified) trigger the client function to increase hunger.

apologyze my poor english

---

(spanish)

Es posible tomar el script http://community.multitheftauto.com/index.php?p=resources&s=details&id=906 y cambiar los marcadores (donde uno va a subir su nivel de hambre) por una funcion ejecutada desde el server? Me gustaria que mis items (de mta paradise, modificados) mandaran a subir el nivel de hambre.

Link to post
  • 2 weeks later...

Well i have seen a little and i have thinked bout use exported functions. I'm tryin it

CLIENT

hamburgerPositions = { {450,-83,999.55,4} } -- The positions for the hamburger, in the style: x,y,z,interior 
--[[ 
  
This is the hunger script. You can add hamburgers by adding it in hamburgerPositions. 
It works easy, just a after it, and filling in! 
  
{x,y,z,interiorID} 
When it isn't the last position, it needs a "," after it 
  
]]-- 
  
-- DONT CHANGE ANYTHING AFTER THIS WITHOUT KNOWLEDGE! 
addEventHandler ("onClientResourceStart",getResourceRootElement(getThisResource()), 
function () 
  hungerProcess = guiCreateProgressBar(0.7763,0.28,0.1775,0.04,true) 
  guiMoveToBack (hungerProcess) 
  guiProgressBarSetProgress(hungerProcess,100) 
  hungerLabel = guiCreateLabel(0.7775,0.2817,0.1737,0.0367,"Hambre",true) 
  guiLabelSetColor(hungerLabel,200,0,0) 
  guiLabelSetVerticalAlign(hungerLabel,"center") 
  guiLabelSetHorizontalAlign(hungerLabel,"center",false) 
  guiSetFont(hungerLabel,"default-bold-small") 
  for i,v in ipairs (hamburgerPositions) do 
    local hamburger = createPickup (v[1],v[2],v[3],3,2768,100) 
    local hamburgerMarker = createMarker (v[1],v[2],v[3],"corona",2,255,255,0,255) 
    setElementData (hamburgerMarker,"HAMBURGER!",true) 
    setElementInterior (hamburgerMarker,v[4]) 
    setElementInterior (hamburger,v[4]) 
  end 
  setTimer (dropDownHungerState,45000,0,getLocalPlayer()) 
end) 
  
function setHungerState (player,hungerState) 
  if (player == getLocalPlayer()) then 
    guiProgressBarSetProgress(hungerProcess,hungerState) 
  end 
end  
  
function getHungerState (player) 
  if (player == getLocalPlayer()) then 
    return guiProgressBarGetProgress(hungerProcess) 
  end 
end 
  
function dropDownHungerState (player) 
  if (player == getLocalPlayer()) then 
    guiProgressBarSetProgress(hungerProcess,guiProgressBarGetProgress(hungerProcess) -1) 
    if (guiProgressBarGetProgress(hungerProcess) == 0) then 
      setElementHealth (player,getElementHealth (player) -25) 
      outputChatBox ("Rapido! Debes alimentarte si no quieres morir!",255,0,0,false) 
    elseif (guiProgressBarGetProgress(hungerProcess) == 10) then 
      outputChatBox ("Sientes hambre",255,0,0,false) 
    end 
  end 
end  
  
addEventHandler ("onClientPlayerSpawn",getRootElement(), 
function (team) 
  setHungerState (source,100) 
end) 
  
addEventHandler ("onClientMarkerHit",getRootElement(), 
function(hitEle,dim) 
  if (getLocalPlayer() == hitEle) and (getElementData (source,"HAMBURGER!") == true) then 
    if (getHungerState (hitEle) < 80) then 
      setHungerState (hitEle,100) 
      outputChatBox ("Comes algo y renuevas tus fuerzas.",255,0,255,false) 
      outputChatBox ("Ya no sientes hambre.",255,0,255,false) 
    else 
      outputChatBox ("No necesitas comer en este momento.",255,0,255,false) 
    end 
  end 
end) 
  
addEvent("setHungerState", true) 
addEventHandler("setHungerState", root, setHungerState) 
  
addEvent("getHungerState", true) 
addEventHandler("getHungerState", root, getHungerState) 
  
-- Made by JasperNL=D  

SERVER

function getHungerStateSrv(player) 
        triggerClientEvent(player, "getHungerState", player) 
    end 
     
function setHungerStateSrv(player, hungerState) 
        triggerClientEvent(player, "setHungerState", player, hungerstate) 
    end 

META

<meta> 
  <info author="JasperNL=D" version="1.0" name="Hunger!" description="The Super-hunger snippet! every server needs it :D" type="script" /> 
  <script src="hunger.lua" type="client" /> 
  <script src="server.lua" type="server" /> 
  <export function="setHungerStateSrv" type="server"/> 
  <export function="getHungerStateSrv" type="server"/> 
</meta> 

used function:

exports.hunger:setHungerStateSrv ( source, math.max( 100, exports.hunger:getHungerStateSrv( source ) + 20 ) ) 

error:

attempt to perform arithmetic on a nil value 

Can anyone help me? thanks

Link to post

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