Sorry I didn't find you sooner I have a single script that covers most of what your asking for..
This script should be pasted into the globals.lua
Includes:
Time and Date (also AM/PM)
Lighting corresponding to time.
Hunger, Thirst, Starvation, Dehydration
Auto Heal (or lose health if starving/dehydrated)
Configurable random fog, With adaptive culling behind fog line.
Money or points system.
Scrolling Hud output.
(I had more planned to be there but have been busy). Most things are well documented in labels.
Globals
---------------------------------------------------------------------------------------------
---------------------------Uniform--Open--World--Game--Handler-------------------------------
--------------------------------------EXADION------------------------------------------------
---------------------------------------------------------------------------------------------
--Main Config
local UseTime = 1 -- Generally this control all of the script, if disabled, time will stop! (other functions won't work when this is off!)
local LightControl = 1 -- The time controls lighting in the enviroment!
local HungerControl = 1 -- Food/Starvation system
local ThirstControl = 1 -- Thirst/dehydration system
local AutoRegenHealth = 1 -- If the players food and thirst are more than 0 we will give them health every minute
local UseFogSystem = 1 -- Every passing hour auto change fog amounts
local AdaptiveCulling = 1 -- Call "VisibilityCheck(e)" from the objects to use this! bets to call this from default.lua! if enabled culling will be determined by max fog distance.
-- --You may still use objectculling the same way with this disabled. If you do set "visibilityRange" below. In that case objects will be culled at static distance.
local UseMoneySystem = 1 -- Use Money system
local ShowHud = 1 -- Show text Change hud
--Time Setup
local Min = 0 -- Starting Minute
local Hour = 12 -- Starting Hour
local MinuteDelay = 500000 -- MS per minute
local MinPerHour = 59 -- Minutes in a hour
local HoursPerDay = 23 -- How many hours per day cycle
--Date
local Day = 1 -- First or current day of the week
local Week = 1 -- Starting week of the year
local DayPerWeek = 7 -- How many days in a week?
local DayNames = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"} -- Day Names
--Money
local CurrencyName = "$" -- Name of currency for use in HUD display (if activated)
local CurrencyAmt = 10000 -- Ammount of money the player starts with
local regularIncome = 1000 -- Your player earns this each game week
local Payday = "Wednesday" -- Day of the week player recieves income (use either name or day number)
-- Fog setup
local MaximumFogDistance = 10000 -- Fog is opaque at this distance
local MinimumFogDistance = 4000 -- Start of fog
local FogAdjust = 1000 -- Minimum distance between Min and max
--Lighting setup
local MaximumLighting = 100 -- Max Brightness (in normal game day)
local MinimumLighting = 20 -- Darkest it gets (in normal game day)
--Hunger setup
local Maxfood = 1000000 -- Max you can get
local Food = 100000 -- How much you start with or have
local ConsumedPerMin = 1 -- How much used each minute
local Firstwarning = .5 -- Percent of food before warning
local FirstwarningMessage = "Getting a little hungry!" -- Message to player
local Secondwarning = .25 -- Percent of food before warning
local SecondwarningMessage = "Getting very hungry!" -- Message to player
local StarvingMessage = "I am starving!" -- Message to player
local FoodLoseHealth = 1 -- How much health is taken each minute
local NotHungryMessage = "I'm not hungry" -- Your not hungry
--Thirst setup
local MaxThirst = 100000 -- Max you can get
local Thirst = 100000 -- How much you start with or have
local TConsumedPerMin = 10 -- How much used each minute
local TFirstwarning = .5 -- Percent of Thirst before warning
local TFirstwarningMessage = "Getting a little thirsty!" --Message to player
local TSecondwarning = .25 -- Percent of thirst before warning
local TSecondwarningMessage = "Getting very thirsty!" -- Message to player
local DehydratedMessage = "I am dehydrated!" -- Message to player when thirsty
local ThirstLoseHealth = 1 -- How much health is taken each minute
local NotThirstyMessage = "I'm not thirsty" -- your not hungry
--AutoRegen
local RegenHealth = 1 -- How much health is regenerated each minute!
local RegenHealthCap = 1000 -- AutoRegen wont go higher than this ammount.
--Health Other
local CapHealth = 1 -- Use Max Health Cap
local MaxHealthCap = 2000 -- Prevent Player health from exceeding this for any reason
--Object culling
local visibilityRange = 500 -- Set max visual range. (only used if adaptive culling is off!)
-- Water culling
VisibilityWaterMul = 1 -- If your triggere zone covers a large body of water, visibility is calculated from center, we may need to use a longer range to adjust for that.
--Lower number will show water less and reduce processing. If water stays invisible even when your close, try upping the multiplier.
-- Also note This depends on the visible range, if using adaptive you may need to experiment on finding a good range.
--Hud
local HudTime = 10 -- mins between time change
---------------------------------------------------------------------------------------------
-----------------------------------For internal use------------------------------------------
local TimeStart = 0 -- The time the minute started
local TS = 1 -- Indicates a new min has started
local light = 0 -- Measure of light intensity
local AMPM = "" -- Hold AM Pm value
local FlashStateSwitch = 10 -- Dark first or light
local FogNearestSetting = 0 -- Save and retrieve distance for fog
local FogFurthestSetting = 0 -- Save and retrieve distance for fog
local FirstLoop = 1 -- Used to determin if this is the first run instance (sets things up).
local waterVisible = 0 -- Keeps track of visible status so its only set once.
local CurDayName = "" -- Day of the week name
local HudStamp = 3 -- stores current loop
local ThirstState = 0 -- Used for hud message
local HungerState = 0 -- Used for hud message
local HudFoodHunger1 = "" -- Hud Decides What message to give.
local HudFoodHunger2 = "" -- Hud Decides What message to give.
local MaxHudOutPut = 1 -- How many view are in the HUD
local HudDelay = 0 -- Stored current
--Special Prameters
local Dream = 0 -- Dream mode is enabled (Disables day/night lighting)
local Flash = 0 -- Causes screen flash (Disables day/night lighting)
local FlashDarkest = 100 -- Darkest Flash ammount between 0 - 255
local FlashBrightest = 200 -- Brightest Flash ammount between 0 - 255
local DarkZone = 0 -- Is darkzone on?
local DZIntensity = 100 -- How dark is a darkZone
---------------------------------------------------------------------------------------------
------------------------------------Start Function-------------------------------------------
function hudscript()
--PromptTextSize(1)
if ShowHud == 1 then -- Not the hud stamps are in reverse order. since they oly run once per min, i dont always want the next one to override it.
if HudStamp == 3 then
if UseMoneySystem == 1 then
Prompt ("I have " .. CurrencyName .. CurrencyAmt)
end
end
if HudStamp == 2 then
if ThirstControl == 1 then
if ThirstState == 0 then
HudFoodHunger1 = NotThirstyMessage
end
if ThirstState == 1 then
HudFoodHunger1 = TFirstwarningMessage
end
if ThirstState == 2 then
HudFoodHunger1 = TSecondwarningMessage
end
if ThirstState == 3 then
HudFoodHunger1 = DehydratedMessage
end
else
HudFoodHunger = ""
end
if HungerControl == 1 then
if HungerState == 0 then
HudFoodHunger2 = NotHungryMessage
end
if HungerState == 1 then
HudFoodHunger2 = FirstwarningMessage
end
if HungerState == 2 then
HudFoodHunger2 = SecondwarningMessage
end
if HungerState == 3 then
HudFoodHunger2 = StarvingMessage
end
else
HudFoodHunger = ""
end
if ThirstControl == 1 and HungerControl == 1 then
Prompt ("Food:" .. Food .. " Thirst:" .. Thirst .. " I am " .. HudFoodHunger1 .. " and " .. HudFoodHunger2, MinuteDelay)
end
if ThirstControl == 1 and HungerControl == 0 then
Prompt ("Thirst:" .. Thirst .. " I am " .. HudFoodHunger1, MinuteDelay)
end
if ThirstControl == 0 and HungerControl == 1 then
Prompt ("Food:" .. Food .. " I am " .. HudFoodHunger2, MinuteDelay)
end
if ThirstControl == 0 and HungerControl == 0 then
--Nothing to do
end
end
if HudStamp == 1 then
Prompt ("Today is " .. CurDayName .. ", " .. Day .. " of week " .. Week .. ". The time is" .. Hour .. ":" .. Min, MinuteDelay)
end
end
if HudDelay > HudTime then
if HudStamp == 1 then
HudStamp = 2
elseif HudStamp == 2 then
HudStamp = 3
elseif HudStamp == 3 then
HudStamp = 1
end
HudDelay = 0
else
HudDelay = HudDelay + 1
end
end
------------------------------------------------------------------------------------------------------
function Time(e) -- Start function
if UseTime == 1 then
if TS == 1 then -- New Min switch on/off
TimeStart = g_Time * 1000 -- Stamp time in
TS = 0 -- Mark Done
end -- End the if
if g_Time * 1000 - TimeStart >= MinuteDelay then -- Determing if a minute has occured
--handling food
if HungerControl == 1 then
if Food > Maxfood then
Food = Maxfood -- incase it was set above the max
end
if Food <= 0 then
--Prompt (StarvingMessage)
HungerState = 3
Food = 0
SendMessageI("hurtplayer",e,FoodLoseHealth)
else
Food = Food - ConsumedPerMin
end
if Food < Maxfood * Firstwarning and Food > Maxfood * Secondwarning then
Prompt (FirstwarningMessage)
HungerState = 1
end
if Food < Secondwarning and Food > 0 then
Prompt (SecondwarningMessage)
HungerState = 2
end
if Food > Maxfood * Firstwarning then -- There above any warning
HungerState = 0
end
end
if ThirstControl == 1 then
if Thirst > MaxThirst then
Thirst = MaxThirst -- incase it was set above the max
end
if Thirst <= 0 then
--Prompt (DehydratedMessage)
ThirstState = 3
Thirst = 0
SendMessageI("hurtplayer",e, ThirstLoseHealth)
else
Thirst = Thirst - ConsumedPerMin
end
if Thirst < MaxThirst * TFirstwarning and Thirst > MaxThirst * TSecondwarning then
--Prompt (TFirstwarningMessage)
ThirstState = 1
end
if Thirst < TSecondwarning and Food > 0 then
--Prompt (SecondwarningMessage)
ThirstState = 2
end
if Thirst > MaxThirst * TFirstwarning then -- There above any warning
ThirstState = 0
end
end
if AutoRegenHealth == 1 then
if Food > 0 and Thirst > 0 then
if RegenCap == 1 then
if g_PlayerHealth <= RegenHealthCap then
SetPlayerHealth(g_PlayerHealth+RegenHealth)
end
else
SetPlayerHealth(g_PlayerHealth+RegenHealth)
end
end
end
if g_PlayerHealth >= MaxHealthCap and CapHealth == 1 then
SetPlayerHealth(MaxHealthCap)
end
--minute delay has passed
if Min >= MinPerHour then -- Add hour or not?
if Hour >= HoursPerDay then -- NewDay
Hour = 0 -- Resets hour
Min = 0 -- Reset Minute
Day = Day + 1
--since we added a day
if Day == DayPerWeek then
Week = Week + 1
Day = 1
end
CurDayName = DayNames[Day]
if CurDayName == Payday or Day == Payday then
CurrencyAmt = CurrencyAmt + regularIncome
end
else -- New Hour
Hour = Hour + 1 -- Add an hour
Min = 0 -- Set min back to zero
end -- end Hour/day check
if UseFogSystem == 1 then -- An hour past, lets generate new fog settings.
math.randomseed(Hour) -- We will use game hour to seed the random
FogNearestSetting = math.random(MinimumFogDistance, ((MaximumFogDistance - 1) - FogAdjust)) -- From the min to 1 below the max (so that we have room for a max)
FogFurthestSetting = math.random((FogNearestSetting + FogAdjust), (MaximumFogDistance)) -- What ever the nearest setting was to the max choice.
SetFogNearest(FogNearestSetting)
SetFogDistance(FogFurthestSetting)
if AdaptiveCulling == 1 then
visibilityRange = FogFurthestSetting
end
end
else -- New minute
-- Hour isn't affected
Min = Min + 1 -- add minute
end -- end min/hour check
hudscript()
TS = 1 -- Marks new minute So a new time stamp will occure)
if Dream == 1 or Flash == 1 or DarkZone == 1 then
-- Disable lighting loop
light = "Random"
else
TotalMinutesPassed = (Hour * MinPerHour) + Min -- Indicates How many Minutes have occured.
MinutesCanOccure = (HoursPerDay * MinPerHour) / 2 -- Based on the Config, How many minutes will happen. Gets brighter only half day
LightRange = MaximumLighting - MinimumLighting -- determing change range max to min
if LightControl == 1 then
if Hour >= HoursPerDay / 2 then -- it is afternoon get darker
light = math.floor(((MinutesCanOccure - (TotalMinutesPassed - MinutesCanOccure)) / MinutesCanOccure) * LightRange + MinimumLighting) -- Calculates brightness based on the time and the given ranges.
AMPM = "PM"
else -- Morning get brighter
light = math.floor((TotalMinutesPassed / MinutesCanOccure) * LightRange + MinimumLighting) -- Calculates brightness based on the time and the given ranges.
AMPM = "AM"
end -- Done with calculating light
SetAmbienceRed(light) -- Setting ambience
SetAmbienceGreen(light)
SetAmbienceBlue(light)
SetSurfaceRed(light) --Setting surface brightness
SetSurfaceGreen(light)
SetSurfaceBlue(light)
--HideTerrain() -- the terrain becomes visible every minute after lighting change, if in a map where terrain is removed (indoors) this should be on here.
HideWater()
--if UseFogSystem == 1 then --We color the fog to match
SetFogRed(light)
SetFogGreen(light)
SetFogBlue(light)
end
end
end
-- " Light intensity: " .. light ..
if Dream == 1 then
DreamState()
end
if Flash == 1 then
FlashState()
end
if DarkZone == 1 then
DarkZoneState()
end
if FirstLoop == 1 then -- This loop only runs once at startup. this is to prevent the first hour from not having fog or adaptive culling setup!
if UseFogSystem == 1 then -- An hour past, lets generate new fog settings.
math.randomseed(Hour) -- We will use game hour to seed the random
FogNearestSetting = math.random(MinimumFogDistance, ((MaximumFogDistance - 1) - FogAdjust)) -- From the min to 1 below the max (so that we have room for a max)
FogFurthestSetting = math.random((FogNearestSetting + FogAdjust), (MaximumFogDistance - FogAdjust)) -- What ever the nearest setting was to the max choice.
CurDayName = DayNames[Day]
SetFogNearest(FogNearestSetting)
SetFogDistance(FogFurthestSetting)
if AdaptiveCulling == 1 then
visibilityRange = FogFurthestSetting
end
FirstLoop = 0
end
end
end
end
end
function FlashState()
if FlashStateSwitch == 1 then
SetAmbienceRed(FlashDarkest) -- Setting ambience
SetAmbienceGreen(FlashDarkest)
SetAmbienceBlue(FlashDarkest)
SetSurfaceRed(FlashDarkest) --Setting surface brightness
SetSurfaceGreen(FlashDarkest)
SetSurfaceBlue(FlashDarkest)
if UseFogSystem == 1 then --We color the fog to match
SetFogRed(FlashDarkest)
SetFogGreen(FlashDarkest)
SetFogBlue(FlashDarkest)
end
FlashStateSwitch = 0
else
SetAmbienceRed(FlashBrightest) -- Setting ambience
SetAmbienceGreen(FlashBrightest)
SetAmbienceBlue(FlashBrightest)
SetSurfaceRed(FlashBrightest) --Setting surface brightness
SetSurfaceGreen(FlashBrightest)
SetSurfaceBlue(FlashBrightest)
if UseFogSystem == 1 then --We color the fog to match
SetFogRed(FlashBrightest)
SetFogGreen(FlashBrightest)
SetFogBlue(FlashBrightest)
end
FlashStateSwitch = 1
end
end
function DreamState()
math.randomseed(os.time())
SetAmbienceRed(math.random(0, 255)) -- Setting ambience
SetAmbienceGreen(math.random(0, 255))
SetAmbienceBlue(math.random(0, 255))
SetSurfaceRed(math.random(0, 255)) --Setting surface brightness
SetSurfaceGreen(math.random(0, 255))
SetSurfaceBlue(math.random(0, 255))
end
function DarkZoneState()
SetAmbienceRed(DZIntensity) -- Setting ambience
SetAmbienceGreen(DZIntensity)
SetAmbienceBlue(DZIntensity)
SetSurfaceRed(DZIntensity) --Setting surface brightness
SetSurfaceGreen(DZIntensity)
SetSurfaceBlue(DZIntensity)
-- Prompt(DZIntensity)
end
---------------------------------------Culling--------------------------------------------
--Entities
function VisibilityCheck(e) -- Call this from default.lua!
if GetPlayerDistance(e) <= visibilityRange then
Show(e);
return 1;
else
Hide(e);
return 0;
end;
end
--Water
function WaterCulling(e) --
--CheckWater
if GetPlayerDistance(e) <= visibilityRange * VisibilityWaterMul then
if waterVisible == 0 then -- Only call show if its hidden
ShowWater()
waterVisible = 1
end
else
if waterVisible == 1 then -- Only call show if its hidden
HideWater()
waterVisible = 0
end
end
end
---------------------------------------------------------------------------------------------
------------------------------------Control-Functions----------------------------------------
function SetLighting(intensity) -- Allows A script to stop day night lighting and set a specific intensity.
DZIntensity = intensity
DarkZone = 1
end
function StopLighting() -- Ends the dark zone or light zone
DarkZone = 0
end
function FlashStart(DarkestI, LightestI) -- Call to start flashing
FlashDarkest = DarkestI
FlashBrightest = LightestI
Flash = 1
end
function FlashStop() -- Stop flashing
Flash = 0
end
function DreamsStart() -- Funny color changin dreams
Dream = 1
end
function DreamStop() -- ends dreams
Dream = 0
end
function SetMaxHealth(MaxHealth) -- Set maximumhealth
MaxHealthCap = MaxHealth
end
function GetMaxHealth() -- Get current maximum health
return MaxHealthCap
end
function SetMaxHealthRegen(MaxHealthRegen) -- Sets the maximum health that can be regained
MaxHealthCap = MaxHealthRegen
end
function GetMaxHealthRegen() -- Get max regen health
MaxHealthCap = MaxHealthRegen
end
function SetTime(hourI, minuteI) -- Set the current Time
MaxHealthCap = MaxHealthRegen
end
function GetTimeHour() -- Get the current Hour
return Hour
end
function GetTimeMinute() -- Get the current Minute
return Min
end
function AddFood(Ammount) -- Eat something
Food = Food + Ammount
end
function AddDrink(Ammount) -- Drink Something
Thirst = Thirst + Ammount
end
function SetMaxFood(Ammount) -- Alter max food
MaxFood = Ammount
end
function GetMaxFood(Ammount) -- Get max food
return MaxFood
end
function SetMaxThirst(Ammount) -- Alter max thirst
MaxThirst = Ammount
end
function GetMaxFood(Ammount) -- Get Max thirst
return MaxFood
end
function ShowHudMenu() -- Show the Hud
ShowHud = 1
end
function HideHudMenu() -- Hide the hud
ShowHud = 0
end
With that in globals you will now need to place triggers to continuously call Time()
function runtimer_init()
end
function runtimer_main()
Time()
end
Now you can choose to give the player money or points which can be spent on drinks or food.
Drinks
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Health
function vendingdrink_init(e)
end
drinkcost = 100 -- Define cost of drink
drinkgivesthirst = 100 -- How much it effects thirst level
function vendingdrink_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 150 then
HideHUD()
PromptDuration("Press 'e' to buy drink for " .. drinkcost .. ". I have " .. GetMoney() .. ". My thirst level is " .. GetThirst() .. "/" .. GetMaxThirst() .. ". This will add " .. drinkgivesthirst .. ".",3000)
if g_KeyPressE == 1 then
if GetMoney() >= drinkcost then
PromptDuration("Much better!",3000)
PlaySound(e,0)
AddDrink(drinkgivesthirst)
ActivateIfUsed(e)
SpendMoney(drinkcost)
else
PromptDuration("Too expensive!",3000)
end
end
else
if PlayerDist < 200 then
ShowHUD()
end
end
end
Food
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Health
function vendingfood_init(e)
end
foodcost = 100 -- Define cost of food
foodgivesthirst = 100 -- How much it effects food level
function vendingfood_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 150 then
HideHUD()
PromptDuration("Press 'e' to buy food for " .. foodcost .. ". I have " .. GetMoney() .. ". My food level is " .. GetFood() .. "/" .. GetMaxFood() .. ". This will add " .. foodgivesthirst .. ".",3000)
if g_KeyPressE == 1 then
if GetMoney() >= foodcost then
PromptDuration("Much better!",3000)
PlaySound(e,0)
AddFood(foodgivesthirst)
ActivateIfUsed(e)
SpendMoney(foodcost)
else
PromptDuration("Too expensive!",3000)
end
end
else
if PlayerDist < 200 then
ShowHUD()
end
end
end
Note: The ShowHud and HideHud must occur whenever you want to output another message.
Waterzone - Hurts player in water and activates water culling. (add to a trigger over water)
function waterzone_init(e)
end
announceonceHurt = 0
function waterzone_main(e)
if g_Entity[e]['plrinzone']==1 then
ActivateIfUsed(e)
if announceonceHurt == 0 then
PlaySound(e,0)
announceonceHurt = 1
end
SendMessageI("hurtplayer",e,5)
else
end
WaterCulling(e)
end
default.lua for entity culling
--Exadion Script
--free to use for any use but please give credit!
function default_init(e)
--do nothing or add some init code here if you want
end
function default_main(e)
VisibilityCheck(e);
end;
eating an picked up item
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Health
function eat_init(e)
end
function eat_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 80 then
--PromptDuration("Food is Good!",3000)
PlaySound(e,0)
AddFood(100)
Destroy(e)
ActivateIfUsed(e)
end
end
Drinking
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Health
function eat_init(e)
end
function eat_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 80 then
PlaySound(e,0)
AddDrink(100)
Destroy(e)
ActivateIfUsed(e)
end
end
Add the code above to a trigger in the water to drink.
Hope it helps. But I can code anything... looking for a good level designer and artist.
My blog site, free artwork, scripts, textures etc.
http://jadenstockartwork.blogspot.com/