Frictional Games Forum (read-only)
[SCRIPT] Candle scripting help - 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: [SCRIPT] Candle scripting help (/thread-15589.html)



Candle scripting help - Hatred - 05-23-2012

Hi everybody.

I made a room with 5 candles in the center of it and now I want that when you have lit all the candles,
in order from 1 to 5, it sets something active, like a key on the floor.

All help appreciated.


RE: Candle scripting help - Obliviator27 - 05-23-2012

Use SetLocalVarInt, and AddLocalVarInt. Like so.

void OnStart()
{
SetLocalVarInt("CandlesLit", 0); // Sets a variable "CandlesLit" to zero.
SetEntityCallbackFunc("candlename", "CandleLight");
// Replace candlename with the names of your candles, and call as many times as there are candles. Could be done under the interactcallback tab of the candle itself.
}
void CandleLight(string &in asEntity, string &in type)
{
if(asType == OnIgnite) // If it's ignited.
{
AddLocalVarInt("CandlesLit", 1);
if(GetLocalVarInt("CandlesLit") == 5) // If the variable is equal to five, execute following statement
{
//SetEntityActive script goes here, along with anything else.
}
}
}

Written off of the top of my head, so I'm not sure if it'll work 100%


RE: Candle scripting help - Hatred - 05-23-2012

Thank you very much for your quick response!
I'll try this right away and inform if it does work or not.


RE: Candle scripting help - Rapture - 05-23-2012

Quick question, do you want a particular order to how the candles are lit or it doesn't matter?


RE: Candle scripting help - Hatred - 05-23-2012

Order from candle 1 to 5.
For example if the candles are in a straight row like this candle1 candle3 candle5 candle2 candle4
you would have to light the candle 1 first and then candle 2 and so on.
And if you light them in wrong order, nothing would happen.

@Obliviator27

It worked almost perfectly, only this order thing did not work.
Still, thanks for your help. Much appreciated. Smile


RE: Candle scripting help - FlawlessHappiness - 05-24-2012

Then you have to make the script a litte longer and make every candle-script individual.

Something like, if candle 1 is lit, then add 1 when lighting candle 2. If candle 2 is lit then add 1 when lighting candle 3


RE: Candle scripting help - FragdaddyXXL - 05-24-2012

Or, you could keep track of your recent lit candle with a prevCandle and curCandle. (Previous and current).

You'll also need a variable to keep track of how many you currently have in-a-row. Set that variable to 1.
When player lights a second candle, check to see if it's next in line:

PHP Code:
int prevCandle 0;
int combo 1;
void OnStart()
{
     for(
int x 1<= 5x++)
     {
          
SetEntityCallbackFunc("candlestick_wall_"+x"MyFunc");
     }
}

void MyFunc(string &in asEntitystring &in type//This function is ran when a player interacts with a candle
{
//GET WHICH CANDLE NUMBER. In my case I have candles candlestick_wall_1 thru candlestick_wall_5
for(int x 1<= 5x++)
{
     if(
asEntity == "candlestick_wall_"+x)
     {
          
int curCandle x;
     }
}

if(
curCandle == (prevCandle 1))
{
     
combo++;
}
else
{
     
combo 1//if they break the combo, set combo back to 1.
//also, set all the candles here to turn off as to restart the puzzle
curCandle 0//This allows you to start from 1 again.
}
//now check for if you have lit candle 5 while keeping the combo up

if(combo == && curCandle == 5)
{
     
//run code for solving  puzzle here
     
return;
}

//At the end of this block, make sure you set the curCandle to prevCandle
prevCandle curCandle;