No but this should:
-- Script By AuShadow
-- Decrease health if player is hungry and decrease appetite when food is consumed
-- Start appetite at 5000 and decrease over time at 1 per second
-- 3 levels of hunger, 1 at 3000 getting hungry, 1 at 2000 I am really hungry,
-- at 1000 start losing health 1 per 1 seconds, and also displays Starving
-- Including Drinks as well, start at 3000, and dehydrated at 1000, -1hp per second
function food_drink_init
-- These are the 2 global variables
-- Global means any script can access/read and write them
Appetite = 5000
Thirst = 3000
-- These are local
-- Local meaning they are only affected by this script
-- Using Local means you could run the exact same timer code in another script
-- and it would be completely separate and not affect each other
local TimeStamp1 = 0
local TimePassed = 0
local Time1 = 0
local Time2 = 0
end
-- the function name must be the same as the file name just with _main(e) added
-- for example script1.lua would have the function name script1_main(e)
function food_drink_main(e)
--This is the timer code, it stamps a time in Time1
-- and then constantly updates Time2 and calculates the difference
if TimeStamp1 == 0 then
Time1 = g_Time
-- The TimeStamp1 getting set to 1 means the if statement above is now false and it wont run again
-- until TimeStamp1 == 0 again which we do after everything we wanted to happen at the end of our time
-- has happened
TimeStamp1 = 1
end
-- This is where we constantly update Time2 and check the difference between Time1 and Time2 and write it to TimePassed
Time2 = g_Time;
TimePassed = Time2 - Time1;
-- so TimePassed is the calculated difference in milliseconds, 1000 to 1 second
-- so here we check if the difference is greater then 1 second, when it is it will run the code under the if statement
if TimePassed > 1000 then
-- Here we remove 1 from appetite and thirst values every 1 second
Appetite = Appetite - 1;
Thirst = Thirst - 1;
--Here we check for when the Thirst and Appetite values fall below 1000,
--Remember it drops by 1 every second
if Thirst < 1000 then
-- If its true we display a text on screen with the Prompt command,
Prompt ("I'm Dehydrated");
-- Here we hurt player by a set amount
--when the if statements are true
HurtPlayer(e,1);
--Now we end the if statement for checking thirst
end
-- And then do the same for Appetite
if Appetite < 1000 then
Prompt ("Starving");
HurtPlayer(e,1);
end
-- Once everything we wanted to happen every second is done, we reset the timer by making timestamp1 = 0
TimeStamp1 = 0;
-- And now end the if statement that checks for TimePassed > 1000
end
-- These 2 if statements check to see if the Appetite and Thirst Values have gone over their maximum which you can change here
-- For example if you ate 6 bits of food in game with +1000 appetite on each it will see that and stop the value going over the maximum
-- In this case 5000 for Appetite and 3000 for Thirst
if Appetite >= 5001 then
Appetite = 5000;
end
if Thirst >= 3001 then
Thirst = 3000;
end
-- In the sections below we check when the Appetite and Thirst values are getting low and we warn the player with a text prompt
if Appetite > 2000 and Appetite < 3000 then
Prompt ("Getting Hungry");
-- Make sure to end all your if statements when everything you want to happen is in
end
if Appetite > 1000 and Appetite < 2000 then
Prompt ("Getting Really Hungry");
end
if Thirst > 1000 and Thirst < 2000 then
Prompt ("I'm getting Thirsty");
end -- AuShadow
-- And lastly don't forget to end the Entire function
end
-- Some things to remember,
-- 1. These scripts run very quickly and constantly repeat so if you have something as just +1 you will see that value increase very quickly
-- 2. Scripts are extremely unforgiving to spelling mistakes and not using capitals.
-- For example if you use prompt ("") instead of Prompt ("") you will get the error of trying to assign a variable to prompt incorrectly
Not tested but if doesn't work then move the variables out of the _init function and place them between that and the _main function but NOT INSIDE the main function and save as food_drink.lua
lol i think this may have been the last script i actually wrote, need to find time to get abck into learning lua again.
lol almost forgot to update to the HurtPlayer function instead of AddPlayerHealth, but spotted it and sorted now
by the way make sure what ever entity this is applied to has ALWAYS ON ticked in the properties tab otherwise it will stop working once you are 3000 game units away from it. and must be dynamic also
PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz