Linus Ågren
Senior Member
Posts: 309
Threads: 58
Joined: Jan 2011
Reputation:
5
|
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 |
|
devin413
Member
Posts: 175
Threads: 7
Joined: Jul 2011
Reputation:
3
|
RE: Question about a timed book script
//BOOK1//
void book4(string &in asParent, string &in asChild, int alState)
{
{
SetPropStaticPhysics("book_moveable_4", true);
AddLocalVarInt("Var2", 1);
enter();
}
}
//BOOK2//
void book1(string &in asParent, string &in asChild, int alState)
{
{
SetPropStaticPhysics("book_moveable_2", true);
AddLocalVarInt("Var2", 1);
enter();
}
}
//BOOK3//
void book3(string &in asParent, string &in asChild, int alState)
{
{
SetPropStaticPhysics("book_moveable_3", true);
AddLocalVarInt("Var2", 1);
enter();
}
}
void enter()
{
///////////////////////////
if(GetLocalVarInt("Var2") == 3)
{
StopSound("book", 0);
RemoveTimer("booktimer");
SetMoveObjectState("shelf_secret_door_2", 1.0f);
}
//Timer Start's if get Var2 == 1
if(GetLocalVarInt("Var2") == 1)
{
AddTimer("booktimer", 6, "resetbook");
PlaySoundAtEntity("book", "gameplay_tick.snt", "Player", 0, false);
}
}
//////////////////////////////////
void resetbook(string &in asTimer)
{
StopSound("book", 0);
SetPropStaticPhysics("book_moveable_4", false);
SetPropStaticPhysics("book_moveable_3", false);
SetPropStaticPhysics("book_moveable_1", false);
AddPropImpulse("book_moveable_3", 0.0f, 0.0f, 5.0f, "World");
AddPropImpulse("book_moveable_1", 0.0f, 0.0f, 5.0f, "World");
AddPropImpulse("book_moveable_4", 0.0f, 0.0f, 5.0f, "World");
SetLocalVarInt("Var2", 0);
enter();
}
void OnEnter()
{
AddEntityCollideCallback("book_moveable_4", "areacode_4", "book4", false, 1);
AddEntityCollideCallback("book_moveable_2", "areacode_2", "book1", false, 1);
AddEntityCollideCallback("book_moveable_3", "areacode_3", "book3", false, 1);
}
i scipt it for you hope it will help you ^^
Boris Game Studios: Devin413 Moddels Maps Scripts.
Tenebris Lake
Killings In Altstadt
(This post was last modified: 11-03-2011, 07:14 PM by devin413.)
|
|
11-03-2011, 07:13 PM |
|
Linus Ågren
Senior Member
Posts: 309
Threads: 58
Joined: Jan 2011
Reputation:
5
|
RE: Question about a timed book script
I'm not entirely sure what you meant with your code, but I solved it! Thanks
Creator of The Dark Treasure.
|
|
11-04-2011, 06:45 PM |
|
|