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
Script Help Three Books puzzle
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#1
Three Books puzzle

I am wanting to have the player pull out three books and have a door unlock, and if possible have a time limit + the ticking sound as in the base Amnesia game. I looked how Frictional did it but I cant make much sense of how it works to be honest and I looked for a tutorial but cant find any.

I have added 3x script areas in front of each book for them to collide with but that's all I dont know what to do with the script. I'm guessing some sort of local var is needed? Any help would be really appreciated.

06-01-2016, 10:54 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Three Books puzzle

When you pull the book out, it touches the area in front of it. So in your script you will need to add a collision callback to check for this event, one for each book & area.

I'm sure they can all call the same code block event.

To start off, you'll want to start the timer and ticking noise. Next up, you'll want to add a local variable which will be used to count the amount of books currently positioned. By the end you'll add a check for when that variable is equal to 3, and run the completion event.

The timer needs to reset these values and all when it expires.



This is just me thinking it in my head, but I believe it will work just fine. But if you need help with the script, here's an example. Hopefully you understand it.

PHP Code: (Select All)
void OnStart()
{
    for(
int i 1<= 3i++) //this will loop the following line 3 times.
        
AddEntityCollideCallback("Book_"+i"Area_"+i"PullBook"false1); 
        
//Adds callbacks for Book_1 and Area_1, and for 2 and 3.
}

void PullBook(string &in asParentstring &in asChildint alState)
{
    
AddTimer("expire"20.0f"TimerExpired"); //Change time to how long it should last
    //Add a PlaySoundAtEntity here

    
AddLocalVarInt("Books"1); //This adds +1 to this variable for every book that collides with the area.
    //Add something to make asParent not movable so that they dont cheat by 
    //using the same book several times to enter the area, like SetPropStaticPhysics 
    //or something better. Alternatively you can disable the area and reset it later.

    
if(GetLocalVarInt("Books") == 3) {
        
//This will complete the event, put your code here
        
RemoveTimer("expire");
        
//Run StopSound
    
}
}

void TimerExpired(string &in asTimer)
{
    
//This will reset the event because you ran out of time.
    
for(int i 1<= 3i++) ResetProp("Book_"+i);
    
SetLocalVarInt("Books"0);//Resets the counter
    //Run StopSound here.
    //Run any additional resets here as well if you have any.


Disclaimer: I might've forgotten something.

(This post was last modified: 06-02-2016, 03:11 AM by Mudbill.)
06-02-2016, 03:04 AM
Find
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#3
RE: Three Books puzzle

(06-02-2016, 03:04 AM)Mudbill Wrote: When you pull the book out, it touches the area in front of it. So in your script you will need to add a collision callback to check for this event, one for each book & area.

I'm sure they can all call the same code block event.

To start off, you'll want to start the timer and ticking noise. Next up, you'll want to add a local variable which will be used to count the amount of books currently positioned. By the end you'll add a check for when that variable is equal to 3, and run the completion event.

The timer needs to reset these values and all when it expires.



This is just me thinking it in my head, but I believe it will work just fine. But if you need help with the script, here's an example. Hopefully you understand it.

PHP Code: (Select All)
void OnStart()
{
    for(
int i 1<= 3i++) //this will loop the following line 3 times.
        
AddEntityCollideCallback("Book_"+i"Area_"+i"PullBook"false1); 
        
//Adds callbacks for Book_1 and Area_1, and for 2 and 3.
}

void PullBook(string &in asParentstring &in asChildint alState)
{
    
AddTimer("expire"20.0f"TimerExpired"); //Change time to how long it should last
    //Add a PlaySoundAtEntity here

    
AddLocalVarInt("Books"1); //This adds +1 to this variable for every book that collides with the area.
    //Add something to make asParent not movable so that they dont cheat by 
    //using the same book several times to enter the area, like SetPropStaticPhysics 
    //or something better. Alternatively you can disable the area and reset it later.

    
if(GetLocalVarInt("Books") == 3) {
        
//This will complete the event, put your code here
        
RemoveTimer("expire");
        
//Run StopSound
    
}
}

void TimerExpired(string &in asTimer)
{
    
//This will reset the event because you ran out of time.
    
for(int i 1<= 3i++) ResetProp("Book_"+i);
    
SetLocalVarInt("Books"0);//Resets the counter
    //Run StopSound here.
    //Run any additional resets here as well if you have any.


Disclaimer: I might've forgotten something.

Brilliant thanks a lot it works perfectly, well almost perfectly. After the first book is pulled the ticking starts, but when the second book is pulled another ticking sound plays on top of the other one, I cant figure out why but to be honest it doesnt matter that much, i'm just happy the puzzle works properly Big Grin

06-02-2016, 11:30 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: Three Books puzzle

Ah, right yeah, that makes sense. You can easily fix that by checking the variable first.

PHP Code: (Select All)
if(GetLocalVarInt("Books") == 0PlaySoundAtEntity(...); 

(This post was last modified: 06-02-2016, 05:31 PM by Mudbill.)
06-02-2016, 05:30 PM
Find




Users browsing this thread: 1 Guest(s)