Frictional Games Forum (read-only)
Simple shelf puzzle? - 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: Simple shelf puzzle? (/thread-19377.html)



Simple shelf puzzle? - Potato - 11-29-2012

So, my friend and I are working on a relatively short custom story, and we're experiencing some trouble with a certain puzzle that we're trying to set up.

Essentially, it's the interactive shelf from the main game propped up in front of a doorway. Simply enough, when the player locates it and tries to pull it open, it'll display a message saying something along the lines of "This shelf is a bit too heavy to pry open, it is definitely covering something though." So, the player won't be able to pull the door outward before manually taking individual objects off the shelf. When it's been emptied, it should be able to open with no hesitation.

What would be the most effective way to go about this and make it work?


RE: Simple shelf puzzle? - FlawlessHappiness - 11-29-2012

Have an area cover the shelf.




When you touch the shelf you should call:




void TouchShelf(string &in asEntity)

{

if(GetLocalVarInt("MovableShelf") == 0)

{

SetMessage("Messages", "YourMessage", 0);

SetEntityInteractionDisabled(string& asName, true);

}




if(GetLocalVarInt("MovableShelf") == 1)

{

SetEntityInteractionDisabled(string& asName, false);

}

}







Now you make collide functions for the stuff in the shelf. It should look like this:

(You should have more than one. They should all call "CollideFunction", but you can change "Stuff" to what you want.)




AddEntityCollideCallback("AreaAroundBookshelf", "Stuff_1", "CollideFunction", false, 0);

AddEntityCollideCallback("AreaAroundBookshelf", "Stuff_2", "CollideFunction", false, 0);




voice CollideFunction(string &in asParent, string &in asChild, int alState)

{

if(asChild == "Stuff_1")

{

if(alState == 1)

{

AddLocalVarInt("StuffVar", -1)

}




if(alState == -1)

{

AddLocalVarInt("StuffVar", 1)

}

}




if(asChild == "Stuff_2")

{

if(alState == 1)

{

AddLocalVarInt("StuffVar", -1)

}




if(alState == -1)

{

AddLocalVarInt("StuffVar", 1)

}

}




//And in the end of the script:




if(GetLocalVarInt("StuffVar") == 0) //Desired number. This defines how many boxed there were taken off the shelf. If 0, then all boxes are off. If less than 0 (-1, -2, -3) Some boxes can remain.

{

SetLocalVarInt("MovableShelf", 1)

}




if(GetLocalVarInt("StuffVar") == -10) //Desired number of boxes on the shelf.

}
SetLocalVarInt("MovableShelf", 0)
}


RE: Simple shelf puzzle? - Potato - 11-29-2012

Thanks, this helps a lot, I'll see to getting this working, if I have any other questions about this specifically, I'll drop them here. ^^


RE: Simple shelf puzzle? - Damascus - 11-29-2012

I actually do something fairly similar in my custom story. I just took a shelf and turned it into a Push object with high mass (like 30). Just by itself, the Player can tip it over, but when I put enough books on it, it actually adds enough weight to keep the player from moving it. No scripts needed!

Keep in mind, though, that the shelf will most likely just fall over instead of sliding upright.


RE: Simple shelf puzzle? - Potato - 12-02-2012

Alright, well, it didn't go exactly as planned. The shelf itself can be moved before any items are removed from it, and the once you let go of it, you're unable to interact with it further. Removing the items don't exactly help.

If you could, could you possibly take a look at this script and see if there's any damning factors here.

Code:
void TouchShelf(string &in asEntity)
{
if(GetLocalVarInt("MovableShelf") == 0)
{
SetMessage("Messages", "YourMessage", 0);
SetEntityInteractionDisabled("MovableShelf", true);
}



if(GetLocalVarInt("MovableShelf") == 1)
{
SetEntityInteractionDisabled("MovableShelf", false);
}
}void EnableMove(string &in asParent, string &in asChild, int alState)
{
if(asChild == "Stuff_1")
{
if(alState == 1)
{
AddLocalVarInt("StuffVar", -1);
}
if(alState == -1)
{
AddLocalVarInt("StuffVar", 1);
}
}
if(asChild == "Stuff_2")
{
if(alState == 1)
{
AddLocalVarInt("StuffVar", -1);
}



if(alState == -1)
{
AddLocalVarInt("StuffVar", 1);
}if(GetLocalVarInt("StuffVar") == 0) //Desired number. This defines how many boxed there were taken off the shelf. If 0, then all boxes are off. If less than 0 (-1, -2, -3) Some boxes can remain.
{
SetLocalVarInt("MovableShelf", 1);
}
if(GetLocalVarInt("StuffVar") == -2) //Desired number of boxes on the shelf.
{SetLocalVarInt("MovableShelf", 0);}}}



RE: Simple shelf puzzle? - The chaser - 12-02-2012

You could use a "for" in this case.

void OnStart()
{
for (int i = 1, i =30, i++) ///Supposing that there are 30 stuff
{
AddEntityCollideCallback("Stuff"+i, "Area", "Call", true, 1);
}

void Call (string &in asParent, string &in asChild, int alState)
{
AddLocalVarInt("Shelf_variable", 1);
check();
}

void check()
{
if (GetLocalVarInt("Shelf_variable")==30)
{
/////Let the player interact and do something with the shelf
}
}


RE: Simple shelf puzzle? - TheGreatCthulhu - 12-02-2012

I didn't go through all of it or test it, but the problem is probably here

Code:
void TouchShelf(string &in asEntity)
{
    if(GetLocalVarInt("MovableShelf") == 0)
    {
        SetMessage("Messages", "YourMessage", 0);
        SetEntityInteractionDisabled("MovableShelf", true);
    }

    if(GetLocalVarInt("MovableShelf") == 1)
    {
        SetEntityInteractionDisabled("MovableShelf", false);
    }
}

When you touch the shelf for the first time, interaction facilities get disabled, so this function is never called again.

You could either count if all the items are picked off the shelf, and then call SetEntityInteractionDisabled("MovableShelf", false) when the last item is picked, or you could add a script area that encompasses, but is slightly larger than the shelf, and then on collision with it simply check if GetLocalVarInt("MovableShelf") == 1, enabling the interaction if it is.


RE: Simple shelf puzzle? - Damascus - 12-02-2012

AddEntityCollideCallback("Stuff"+i, "Area", "Call", true, 1);

Set this value to false, so that the callback isn't auto-removed, and you'll be able to keep interacting with it.


RE: Simple shelf puzzle? - The chaser - 12-02-2012

(12-02-2012, 03:27 AM)Damascus Wrote: AddEntityCollideCallback("Stuff"+i, "Area", "Call", true, 1);

Set this value to false, so that the callback isn't auto-removed, and you'll be able to keep interacting with it.
Oh, it's true! Silly me Big Grin