Ok, I got the script working
mostly, but giveSanity isnt working as it should
What this script does, Lowers sanity on a random timed event, used for showing sanity props and entities that spawn when then players sanity is low enough
Create a random number on start, Creates timer on start
when timer goes higher then random number, runs script
void OnStart()
{//"event_delay", Create a number between 30 and 120
int event_delay = RandFloat(30.0f, 120.0f);
//"global_timer", timer start/create and run script "sanity_drop_loop"
AddTimer("global_timer", event_delay, "sanity_drop_loop");
}
the script detects player sanity, if higher then 60%, does 10 sanity damage then loops back
if its lower then 60%, heals 40% sanity damage then loops back (doesn't work yet)
(do
NOT place in void OnStart () )
void sanity_drop_loop(string &in asTimer)
{ if (float (GetPlayerSanity()) > 60) // if sanity is higher then 60%
{ GiveSanityDamage(10, false); // Give 10 sanity dmg
int random_event_delay = RandFloat(30.0f, 120.0f); // call new random number
AddTimer("loop", random_event_delay, "sanity_drop_loop"); //loop timer
}
if (float (GetPlayerSanity()) < 60) // if sanity is lower then 60%
{ // currently doesnt work for unknown reasons
AddPlayerSanity(40); //heal sanity by 40%
int random_event_delay = RandFloat(30.0f, 120.0f);
AddTimer("loop", 1, "sanity_drop_loop"); // loop after 1 second
}
}