I'm working on a script thats meant to monitor the players sanity (which is measured by an invisible dummy inventory item), and cause effects as it gets lower and lower. Unfortunately, this has turned into a nightmare as the loops I'm using will not behave in the way I intend, no matter what I do.
In short, it consists of a "While" loop that checks the sanity item against a set of 6 "If" statements, then if it meets any of those statements, checks a random variable to determine which effect will be played.
The main "While" loop seems to work fine, its the inner loops that check the SanityEffectWeight variable that are the (current) problem. I set up test messages to play to ensure its cycling through the different effects correctly, but the only problem is it never cycles through them. It only iterates through the first "If" statement, despite my test message showing the SanityEffectWeight should make the other effects play, none of them ever do.
I'm at a complete loss of how to fix this, since it worked before I started adding effects, but the loops should be no different no compared to how they were previously. Could anyone please advise me?
Code: Select all
script "SanityLoop" ENTER
{
While(TRUE)
{
int Sanity = CheckInventory("Sanity");
int SanityEffectWeight = Random(1, 6);
Delay(35);
If(Sanity >= 80)
{
Restart;
}
If(Sanity < 80 && Sanity >= 60)
{
//Delay(35 * 1);
Print(i:SanityEffectWeight);
If(SanityEffectWeight == 1 || 2)
{
//AmbientSound("sanity/effect/randomsound/minor", 48);
HudMessage(s:"Baa Baa"; HUDMSG_PLAIN|HUDMSG_LOG, 1, CR_GREEN, 0.5, 0.5, 3.0);
Restart;
}
If(SanityEffectWeight == 3 || 4)
{
HudMessage(s:"Black Sheep"; HUDMSG_PLAIN|HUDMSG_LOG, 1, CR_GREEN, 0.5, 0.5, 3.0);
Restart;
}
If(SanityEffectWeight == 5 || 6)
{
HudMessage(s:"I aint payed to do this"; HUDMSG_PLAIN|HUDMSG_LOG, 1, CR_GREEN, 0.5, 0.5, 3.0);
FadeTo(0, 0, 0, 0.25, 1.50);
Delay(35 * 1.5);
FadeTo(0, 0, 0, 0.0, 1.50);
Restart;
}
}
If(Sanity < 60 && Sanity >= 40)
{
HudMessage(s:"you have moderate sanity loss"; HUDMSG_PLAIN|HUDMSG_LOG, 1, CR_GREEN, 0.5, 0.5, 3.0);
AmbientSound("sanity/effect/flicker", 63);
Restart;
}
If(CheckInventory("Sanity") < 40 && CheckInventory("Sanity") >= 20)
{
HudMessage(s:"you have major sanity loss"; HUDMSG_PLAIN|HUDMSG_LOG, 1, CR_GREEN, 0.5, 0.5, 3.0);
AmbientSound("sanity/effect/flicker", 63);
Restart;
}
If(CheckInventory("Sanity") < 20 && CheckInventory("Sanity") >= 1)
{
HudMessage(s:"you have severe sanity loss"; HUDMSG_PLAIN|HUDMSG_LOG, 1, CR_GREEN, 0.5, 0.5, 3.0);
AmbientSound("sanity/effect/flicker", 63);
Restart;
}
If(CheckInventory("Sanity") == 0)
{
HudMessage(s:"you have gone insane"; HUDMSG_PLAIN|HUDMSG_LOG, 1, CR_GREEN, 0.5, 0.5, 3.0);
AmbientSound("sanity/effect/flicker", 63);
Restart;
}
}
}