Frictional Games Forum (read-only)
If All Candles Inactive, Fade To Black Script? - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: If All Candles Inactive, Fade To Black Script? (/thread-21388.html)

Pages: 1 2


If All Candles Inactive, Fade To Black Script? - FurtherGames - 05-04-2013

Hello, again!

Is there a script so that if, for example, there are three candles in a room. To blow them out the player must collide with the script area surrounding that candle. Basically, when the player collides with the area it renders the candle inactive. Is there a way so that once all candles are inactive the screen fades to black? Like this:

Walks over to Candle 1 Area - Blows the candle out
Candle2&3 still active, so no Fade To Black

Walks over to Candle 2 Area - Blows the candle out
Candle3 still active, so no Fade To Black

Walks over to Candle 3 Area - Blows the candle out
All candles inactive, fade to black occurs

Also, would it matter if the player did blew the candles out in a random order?



RE: If All Candles Inactive, Fade To Black Script? - OriginalUsername - 05-04-2013

Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..


RE: If All Candles Inactive, Fade To Black Script? - FurtherGames - 05-04-2013

(05-04-2013, 12:52 PM)Smoke Wrote: Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..


Okay, I understand most of that, but why would "lamplit" equal to three when you set the varients to zero? Does that mean if the three "lamplit" items all equal the same fade out?


RE: If All Candles Inactive, Fade To Black Script? - OriginalUsername - 05-04-2013

No, I just added a variable in OnStart() with the number 0. Everytime he collides with the script_area, the AddLocalVarInt adds 1 on top of that. So first time 0 + 1 = 1. So after the player unlits the first candle, the lamplit variable = 1. Same with the second and third candle. You can check this with if(GetLocalVarInt("lamplit")===1) and if(GetLocalVarInt("lamplit")===2). And letting them play a sound or something in brackets.

This script would do the same:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 5);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===8)
{
FadeOut(2);
}
else
{

}
}

It's just easier to start with 0 instead of 5.


RE: If All Candles Inactive, Fade To Black Script? - FurtherGames - 05-04-2013

(05-04-2013, 01:01 PM)Smoke Wrote: No, I just added a variable in OnStart() with the number 0. Everytime he collides with the script_area, the AddLocalVarInt adds 1 on top of that. So first time 0 + 1 = 1. So after the player unlits the first candle, the lamplit variable = 1. Same with the second and third candle.

You can check this with if(GetLocalVarInt("lamplit")===1) and if(GetLocalVarInt("lamplit")===2). And letting them play a sound or something in brackets.

Ah! I get it now. Thank you, this is perfect!


RE: If All Candles Inactive, Fade To Black Script? - OriginalUsername - 05-04-2013

No problem Wink


RE: If All Candles Inactive, Fade To Black Script? - FurtherGames - 05-04-2013

(05-04-2013, 01:06 PM)Smoke Wrote: No problem Wink

To add another candle, would I just have to add another script area, another function and set the "=== 3" to "=== 4"?


RE: If All Candles Inactive, Fade To Black Script? - WALP - 05-04-2013

(05-04-2013, 12:52 PM)Smoke Wrote: Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..

Im curious, whats the difference between using 2 is equal to signs and using 3, to be more specific whats the difference between "==" and "==="


RE: If All Candles Inactive, Fade To Black Script? - PutraenusAlivius - 05-04-2013

(05-04-2013, 02:05 PM)martinnord Wrote:
(05-04-2013, 12:52 PM)Smoke Wrote: Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..

Im curious, whats the difference between using 2 is equal to signs and using 3, to be more specific whats the difference between "==" and "==="

Me too. This isn't in the comparison operators.


RE: If All Candles Inactive, Fade To Black Script? - FurtherGames - 05-04-2013

(05-04-2013, 01:06 PM)Smoke Wrote: No problem Wink

Doesn't seem to be working. I keep getting fatal errors