Frictional Games Forum (read-only)
Doubt about a puzzle idea (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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Doubt about a puzzle idea (script) (/thread-41563.html)

Pages: 1 2


Doubt about a puzzle idea (script) - sabrinagsoledad - 03-07-2016

Hi

I was thinking in make a puzzle in one of my maps. I dont want a complete script just a few questions about an idea.

I want to make a puzzle of a breaking in a specific order some vases. But not all! just a few in a specific order. If the incorrect vase is broken then restart all over again.

But then raises some concerns.

1. I supose I should start the "game" calling for a breakup function on the level editor on my "first" correct vase...

2. If I want to make a reset in making a error I supouse with a chekpoint before the event? that checkpoint should have an auto save? or the chekpoint is enough to make the vases unbroken again?.

3. And which leads me more doubt is... how to make a specific order. Should consider the if statement? If setprophealth == 0 in my second vase... and keep going?...


Thanks for the attention.


RE: Doubt about a puzzle idea (script) - Mudbill - 03-07-2016

Feel free to use CheckPoint() to restart the room, but to call it the player has to die. CheckPoints are only really used upon death if I remember correctly. Unsure if a CheckPoint will reset the vases though, so use ResetProp() for that.

As for the order itself, since breaking the wrong order will force you to restart, it can simply be an incrementing local variable.

PHP Code:
int vasesBroken 0;

void BreakVase(string &in asEntitystring &in type)//This can be a standard SetEntityFuncCallback as OnBreak
{
    if(
type != "OnBreak") return;

    if(
vasesBroken == && asEntity == "vase_1") {
        
vasesBroken++;
        return;
    } 
    if(
vasesBroken == && asEntity == "vase_2") {
        
vasesBroken++;
        return;
    }
    if(
vasesBroken == && asEntity == "vase_3") {
        
//Success, you reached the end of the order. Add your success code here, before return;
        
return;
    }

    
//If you get here, it's the wrong order, restart code here, call CheckPoint, ResetProp etc...


This code might do it. I'm sure there are better ways to write it but this is the first that popped into my head. I haven't tested it though.
Change the vase names to the order you need, and add this callback to all your vases.
(If nothing happens, try removing the OnBreak line. I might be remembering it wrong)


RE: Doubt about a puzzle idea (script) - sabrinagsoledad - 03-07-2016

Hi. Thanks!! I will try it!


RE: Doubt about a puzzle idea (script) - Spelos - 03-07-2016

I agree with Mudbill,
but let's be cute with our code for a second. Tongue

Set the variable to the first vase's suffix. "vase_1" => vasesBroken = 1;
Grab the suffix of currently broken entity by SubString and convert it to an Integer.

Compare those...
(this code prevents you from writing if statements for each vase)

While it's not a problem here, some codes could work with thousands of vases.

PHP Code:
int vasesBroken 1;

void BreakVase(string &in asEntitystring &in type)//This can be a standard SetEntityFuncCallback as OnBreak
{
    if(
type != "OnBreak") return;

    if(
vasesBroken == StringToInt(StringSub(asEntity51)))
    {
        if(
vasesBroken == 4// 4 in this case is the last vase
        
{
            
//YAAAY! Player Got it right!
        
}
        
vasesBroken++;
        return;
    }

      
vasesBroken 1// And Mudbill surely wanted to include resetting his variable... right?  

//If you get here, it's the wrong order, restart code here, call CheckPoint, ResetProp etc...




RE: Doubt about a puzzle idea (script) - Mudbill - 03-07-2016

Yeah I figured someone would come and clean it up a bit. Personally I wouldn't use an if-statement for each vase if I can help it, I just didn't bother with it since I typed it all by hand in a comment at 3 am xP

Though I guess it slipped me because I expected the vases to not be named in the order they were gonna be broken in. And resetting the value is correct. I just assumed it to be included in the reset lose-code, but always good to point out just in case.

One thing; your vasesBroken++; should be before the win-check, or else they won't actually win upon breaking the last one, but rather the next time the break occurs.


RE: Doubt about a puzzle idea (script) - Spelos - 03-08-2016

Oh no...
The vasesBroken++; is at a correct spot.
I just have the initial vasesBroken value set to 1.


RE: Doubt about a puzzle idea (script) - Mudbill - 03-08-2016

My bad. Forgot that the value is incremented before the vase name equivalent, from the previous round. Derp.


RE: Doubt about a puzzle idea (script) - Spelos - 03-08-2016

Well, I agree with Spelos,
but let's be cute & SMART with our code.

Instead of grabbing the number and converting it to Int.
Let's have "vase_" and combine it with the number we have.

PHP Code:
int vasesBroken 1;

void BreakVase(string &in asEntitystring &in type)
{
    if(
type != "OnBreak") return;

    if(
asEntity == "vase_" vasesBroken)
    {
        if(
vasesBroken == 4)
        {
            
//The Player got it right!
            
return;
        }
        
vasesBroken++;
        return;
    }

    
vasesBroken 1;
    
ResetProp("vase_*");




RE: Doubt about a puzzle idea (script) - sabrinagsoledad - 03-08-2016

Hi.

Sorry for the delay to much stuff at the university.

I try the last code and nothing hapens.

int vasesBroken = 1;

void BreakVase(string &in asEntity, string &in type)
{
if(type != "OnBreak") return;

if(asEntity == "vase_" + vasesBroken)
{
if(vasesBroken == 4)
{
GiveSanityBoost();
SetEntityActive("Coins_5", true);
return;
}
vasesBroken++;
return;
}

vasesBroken = 1;

CheckPoint("Checkpoint", "PlayerStartArea_2","", "DeathCategory", "Deathtext3");
SetPlayerHealth(0.0f);
ResetProp("vase_1");
ResetProp("vase_2");
ResetProp("vase_3");
ResetProp("vase_4");
ResetProp("vase_5");
ResetProp("vase_6");
ResetProp("vase_7");
ResetProp("vase_8");
ResetProp("vase_9");
ResetProp("vase_10");
ResetProp("vase_11");
ResetProp("vase_12");
ResetProp("vase_13");
ResetProp("vase_14");
ResetProp("vase_15");
ResetProp("vase_16");

}

I already chek.. every vase name is vase_1... to the last vase vase_16.
And every vase has the BreakVase callfunction.

If its


RE: Doubt about a puzzle idea (script) - Mudbill - 03-09-2016

Can you show a screenshot of the entity tab for the vases?

Add
PHP Code:
Print("Running BreakVase function"); 
at the top of the BreakVase() function (before the if-check for OnBreak), and then check the log after shutting down to see if it's written there. If not, then the function is never ran.