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


Messages In This Thread
Three Books puzzle - by serbusfish - 06-01-2016, 10:54 PM
RE: Three Books puzzle - by Mudbill - 06-02-2016, 03:04 AM
RE: Three Books puzzle - by serbusfish - 06-02-2016, 11:30 AM
RE: Three Books puzzle - by Mudbill - 06-02-2016, 05:30 PM



Users browsing this thread: 1 Guest(s)