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.
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%
Thank you very much for your quick response!
I'll try this right away and inform if it does work or not.
Quick question, do you want a particular order to how the candles are lit or it doesn't matter?
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.
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
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; x <= 5; x++)
{
SetEntityCallbackFunc("candlestick_wall_"+x, "MyFunc");
}
}
void MyFunc(string &in asEntity, string &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; x <= 5; x++)
{
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 == 5 && 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;
}