Edit Attachment wasn't working so put in a new post
Edit: Have modified the script with new information come to light so the globals are included in the script itself now and local's have been identified as such. Have attached a zipped file to this post with the 3 scripts and also the 3 FPE's which replace the FPE files in the collectables section. Have also updated the script here under the code headers.
EDIT: Ok i finally have a working Hunger and Thirst Script and here it is:
Note: For this to work i took the syringe pickup and modified the FPE so quantity is -1 and then attached this script to and hid it on the level somewhere, doesnt really need hiding as once it has this script on it it just becomes a static object anyway. For the creative this script can be applied to anything thats not going to be interacted with so go nuts, just modify the FPE to say its a health pickup and make the quantity -1 or whatever you want.
Edit: Yes another Edit, heres a video of it working:
-- 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
Appetite = 5000
Thirst = 3000
local TimeStamp1 = 0
local TimePassed = 0
local Time1 = 0
local Time2 = 0
function food_drink_main(e)
if TimeStamp1 == 0 then
Time1 = g_Time
TimeStamp1 = 1
end
Time2 = g_Time;
TimePassed = Time2 - Time1;
if TimePassed > 1000 then
Appetite = Appetite - 1;
Thirst = Thirst - 1;
if Thirst < 1000 then
Prompt ("I'm Dehydrated");
AddPlayerHealth(e);
end
if Appetite < 1000 then
Prompt ("Starving");
AddPlayerHealth(e);
end
TimeStamp1 = 0;
end
if Appetite >= 5001 then
Appetite = 5000;
end
if Thirst >= 3001 then
Thirst = 3000;
end
if Appetite > 2000 and Appetite < 3000 then
Prompt ("Getting Hungry");
end -- AuShadow
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
end
heres the one for food:
-- Script by AuShadow
-- Player eats to replenish Appetite
function food_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
if PlayerDist < 80 then
Prompt ("Press E to consume food");
if g_KeyPressE == 1 then
Appetite = Appetite + 1000;
Destroy(e)
end
end
end
and the one for drink:
-- Script by AuShadow
-- Player drinks to replenish Thirst
function drink_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
if PlayerDist < 80 then
Prompt ("Press E to Drink Liquid");
if g_KeyPressE == 1 then
Thirst = Thirst + 1000;
Destroy(e)
end
end
end
If anyone is interested i wouldn't mind some food and drink entities made that i could put FPE files onto and different values and put this all together as a pack so people don't have to modify the chips and milk entities.