Here is a quick implementation of hunger and thirst, and two scripts for the food and water items.
Also placed these at the bottom of the main post.
Main script
--this will display the hunger and thirst for the player to see
--[[
this is the timers for the hunger and thirst to go down .
--]]
tbl_timer = {}
--[[
these are global so that you can take my stats script or other scripts
and change these values there like when you level up you may want to give yourself
more hunger or thirst, or you may want to make it as you level up you dont get hungry so fast.
--]]
g_hunger = 100
g_thirst = 100
g_food_amount = math.random(10,20) -- this is how much food you get for finding food
g_take_hunger = math.random(5,30) -- to take hunger away
g_hunger_timer = math.random(5000,60000) -- miliseconds
g_water_amount =math.random(10,20) -- this is how much water you get for finding water
g_take_water = math.random(5,30) -- take water away
g_water_timer = math.random(5000,60000) -- miliseconds
function survival_init(e)
-- start timers
GlobalTimerStart(1)
GlobalTimerStart(2)
end
function survival_main(e)
--Text(1, 1, 1, "Global Timer 1: " .. tostring(GlobalTimerGet(1)))
Text(1, 5, 1, "hunger: " .. g_hunger)
Text(1, 10, 1, "water: " .. g_thirst)
-- reset every 5 seconds
if GlobalTimerGet(1) >= g_hunger_timer then
GlobalTimerStart(1)
g_hunger = g_hunger - math.random(10,25)--g_take_hunger
end
if GlobalTimerGet(2) >= g_water_timer then
GlobalTimerStart(2)
g_thirst = g_thirst - math.random(10,25)--g_take_water
end
end
function GlobalTimerStart(Timer)
tbl_timer[Timer]=g_Time
end
function GlobalTimerGet(Timer)
return math.abs(tbl_timer[Timer]-g_Time)
end
food item
--this is the script you put inside the food items to make the player "eat" teh entity.
function give_food_init(e)
end
local got = false
function give_food_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist <= 80 then
Prompt("Press E to pick up food")
end
if PlayerDist <= 80 then --default 80
if g_KeyPressE == 1 then
PromptDuration("You ate some food",3000)
PlaySound(e,0)
g_hunger = g_hunger + g_food_amount
got = true
Destroy(e)
end
end
end
water item
--put this in the water item that you want the player to "drink"
function give_water_init(e)
end
function give_water_main(e)
pdist = GetPlayerDistance(e)
if pdist < 100 then
Prompt("Press E to drink from well")
end
if g_KeyPressE == 1 and pdist <= 80 then
if g_master_table[1][2] < 100 then
PromptDuration("You drank from the well", 3000)
g_thirst = g_thirst + g_water_amount
Destroy(e)
elseif g_thirst >= 100 then
PromptDuration(" You don't need A drink right now.",1000)
end
end
end -- main
Markchapman10 is my Skype let's have some dev talk.