Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple shelf puzzle?
Potato Offline
Senior Member

Posts: 678
Threads: 10
Joined: Jun 2012
Reputation: 37
#1
Simple shelf puzzle?

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?

[Image: o8JPTkt.jpg]
upsilon floorbot is a qt pa2t
11-29-2012, 07:13 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#2
RE: Simple shelf puzzle?

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)
}

Trying is the first step to success.
(This post was last modified: 11-29-2012, 07:54 AM by FlawlessHappiness.)
11-29-2012, 07:51 AM
Find
Potato Offline
Senior Member

Posts: 678
Threads: 10
Joined: Jun 2012
Reputation: 37
#3
RE: Simple shelf puzzle?

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. ^^

[Image: o8JPTkt.jpg]
upsilon floorbot is a qt pa2t
11-29-2012, 08:16 AM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#4
RE: Simple shelf puzzle?

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.

(This post was last modified: 11-29-2012, 08:35 AM by Damascus.)
11-29-2012, 08:34 AM
Find
Potato Offline
Senior Member

Posts: 678
Threads: 10
Joined: Jun 2012
Reputation: 37
#5
RE: Simple shelf puzzle?

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.

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);}}}

[Image: o8JPTkt.jpg]
upsilon floorbot is a qt pa2t
12-02-2012, 01:34 AM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#6
RE: Simple shelf puzzle?

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
}
}

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
(This post was last modified: 12-02-2012, 01:56 AM by The chaser.)
12-02-2012, 01:56 AM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#7
RE: Simple shelf puzzle?

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

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.
12-02-2012, 02:00 AM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#8
RE: Simple shelf puzzle?

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.

12-02-2012, 03:27 AM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#9
RE: Simple shelf puzzle?

(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

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
12-02-2012, 11:24 AM
Find




Users browsing this thread: 2 Guest(s)