The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



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
Question about a timed book script
Linus Ågren Offline
Senior Member

Posts: 309
Threads: 58
Joined: Jan 2011
Reputation: 5
#1
Question about a timed book script


Edit: I solved it by putting an if-statement within the timers that checks:
Let's say you pull book 1. I made an if-statement for the reset timers that checks if book 2, 3 and 4 has NOT been pulled, then the code shall proceed. I put the same code on the rest of the four books but replacing the numbers (if book 2, then it should check for book 1, 3 and 4 etc..).
Hello! I have a script for some books in a library that works so when you pulled all four books within the timelimit, something happens.

Now the problem is, I don't know how to apply this code to the specific book that the player will pull, so I added the timer that activates the timer that controls how much time the player has left to pull all the books. The problem is, that the reset timer (that resets all the books) loops four times, and therefore playing the "resetsound" four times.

Is there any workaround for this?

Here's the code if you want to check:

Quote:void FirstBook_Out(string &in asParent, string &in asChild, int alState)
{
SetPropObjectStuckState("book_moveable_1", 1);
AddDebugMessage("Collides!", true);
SetLocalVarInt("Book1Out", 1);

PlaySoundAtEntity("tick1", "gameplay_tick.snt", "Area_BookCollide_1", 0.0f, false);

AddTimer("Reset", 20.0f, "ResetTimer");
AddTimer("ResetBooks", 20.5f, "ResetTimer");

if((GetLocalVarInt("Book1Out") == 1) && (GetLocalVarInt("Book2Out") == 1) && (GetLocalVarInt("Book3Out") == 1) && (GetLocalVarInt("Book4Out") == 1)){
RemoveTimer("ResetBooks");
RemoveTimer("Reset");

StopSound("tick1", 0.5f);
StopSound("tick2", 0.5f);
StopSound("tick3", 0.5f);
StopSound("tick4", 0.5f);

PlaySoundAtEntity("", "gameplay_open_chest.snt", "Player", 0.0f, false);

SetPropObjectStuckState("book_moveable_1", 1);
SetPropObjectStuckState("book_moveable_2", 1);
SetPropObjectStuckState("book_moveable_3", 1);
SetPropObjectStuckState("book_moveable_4", 1);

AddDebugMessage("Both books have been pulled!", true);
}
}

void SecondBook_Out(string &in asParent, string &in asChild, int alState)
{
SetPropObjectStuckState("book_moveable_2", 1);
AddDebugMessage("Collides!", true);
SetLocalVarInt("Book2Out", 1);

PlaySoundAtEntity("tick2", "gameplay_tick.snt", "Area_BookCollide_2", 0.0f, false);

AddTimer("Reset", 20.0f, "ResetTimer");
AddTimer("ResetBooks", 20.5f, "ResetTimer");

if((GetLocalVarInt("Book1Out") == 1) && (GetLocalVarInt("Book2Out") == 1) && (GetLocalVarInt("Book3Out") == 1) && (GetLocalVarInt("Book4Out") == 1)){
RemoveTimer("ResetBooks");
RemoveTimer("Reset");

StopSound("tick1", 0.5f);
StopSound("tick2", 0.5f);
StopSound("tick3", 0.5f);
StopSound("tick4", 0.5f);

PlaySoundAtEntity("", "gameplay_open_chest.snt", "Player", 0.0f, false);

SetPropObjectStuckState("book_moveable_1", 1);
SetPropObjectStuckState("book_moveable_2", 1);
SetPropObjectStuckState("book_moveable_3", 1);
SetPropObjectStuckState("book_moveable_4", 1);

AddDebugMessage("All four books have been pulled!", true);
}
}

void ThirdBook_Out(string &in asParent, string &in asChild, int alState)
{
SetPropObjectStuckState("book_moveable_3", 1);
AddDebugMessage("Collides!", true);
SetLocalVarInt("Book3Out", 1);

PlaySoundAtEntity("tick3", "gameplay_tick.snt", "Area_BookCollide_3", 0.0f, false);

AddTimer("Reset", 20.0f, "ResetTimer");
AddTimer("ResetBooks", 20.5f, "ResetTimer");

if((GetLocalVarInt("Book1Out") == 1) && (GetLocalVarInt("Book2Out") == 1) && (GetLocalVarInt("Book3Out") == 1) && (GetLocalVarInt("Book4Out") == 1)){
RemoveTimer("ResetBooks");
RemoveTimer("Reset");

StopSound("tick1", 0.5f);
StopSound("tick2", 0.5f);
StopSound("tick3", 0.5f);
StopSound("tick4", 0.5f);

PlaySoundAtEntity("", "gameplay_open_chest.snt", "Player", 0.0f, false);

SetPropObjectStuckState("book_moveable_1", 1);
SetPropObjectStuckState("book_moveable_2", 1);
SetPropObjectStuckState("book_moveable_3", 1);
SetPropObjectStuckState("book_moveable_4", 1);

AddDebugMessage("All four books have been pulled!", true);
}
}

void FourthBook_Out(string &in asParent, string &in asChild, int alState)
{
SetPropObjectStuckState("book_moveable_4", 1);
AddDebugMessage("Collides!", true);
SetLocalVarInt("Book4Out", 1);

PlaySoundAtEntity("tick4", "gameplay_tick.snt", "Area_BookCollide_4", 0.0f, false);

AddTimer("Reset", 20.0f, "ResetTimer");
AddTimer("ResetBooks", 20.5f, "ResetTimer");

if((GetLocalVarInt("Book1Out") == 1) && (GetLocalVarInt("Book2Out") == 1) && (GetLocalVarInt("Book3Out") == 1) && (GetLocalVarInt("Book4Out") == 1)){
RemoveTimer("ResetBooks");
RemoveTimer("Reset");

StopSound("tick1", 0.5f);
StopSound("tick2", 0.5f);
StopSound("tick3", 0.5f);
StopSound("tick4", 0.5f);

PlaySoundAtEntity("", "gameplay_open_chest.snt", "Player", 0.0f, false);

SetPropObjectStuckState("book_moveable_1", 1);
SetPropObjectStuckState("book_moveable_2", 1);
SetPropObjectStuckState("book_moveable_3", 1);
SetPropObjectStuckState("book_moveable_4", 1);

AddDebugMessage("All four books have been pulled!", true);
}
}

void ResetTimer(string &in asTimer)
{
if(asTimer == "Reset"){
SetPropObjectStuckState("book_moveable_1", -1);
SetPropObjectStuckState("book_moveable_2", -1);
SetPropObjectStuckState("book_moveable_3", -1);
SetPropObjectStuckState("book_moveable_4", -1);

PlaySoundAtEntity("", "gameplay_open_chest_reversed.snt", "Player", 0.0f, false);

StopSound("tick1", 0.5f);
StopSound("tick2", 0.5f);
StopSound("tick3", 0.5f);
StopSound("tick4", 0.5f);

SetLocalVarInt("Book1Out", 0);
SetLocalVarInt("Book2Out", 0);
SetLocalVarInt("Book3Out", 0);
SetLocalVarInt("Book4Out", 0);

AddDebugMessage("Books Resetting!", true);
}
if(asTimer == "ResetBooks"){
SetPropObjectStuckState("book_moveable_1", 0);
SetPropObjectStuckState("book_moveable_2", 0);
SetPropObjectStuckState("book_moveable_3", 0);
SetPropObjectStuckState("book_moveable_4", 0);

AddDebugMessage("Books have been resetted!", true);
}
}
]

Creator of The Dark Treasure.
(This post was last modified: 11-04-2011, 06:48 PM by Linus Ågren.)
11-03-2011, 05:16 PM
Website Find


Messages In This Thread
Question about a timed book script - by Linus Ågren - 11-03-2011, 05:16 PM



Users browsing this thread: 1 Guest(s)