Frictional Games Forum (read-only)

Full Version: Make things play in a specific order?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want this to play

void OnStart()
{
AddEntityCollideCallback("Player", "scary_trigger", "ScaryTriggerFunc", true, 1);
}

void ScaryTriggerFunc(string &in asParent, string &in asChild, int alState)
{

StartPlayerLookAt("look_blood", 4, 2, "");
AddTimer("", 2.5f, "ScaryMoment");
PlayGuiSound("react_scare.snt", 100); <------------ play this first
GiveSanityDamage(25, true);


StartPlayerLookAt("look_stair", 4, 2, "");
PlayGuiSound("react_breath_slow.snt", 100); <------------ play this seconde
PlayGuiSound("notice.snt", 40);
StartScreenShake(0.1f, 2, 0.2f, 1);


StartPlayerLookAt("look_monster", 4, 2, "");
AddTimer("", 2.5f, "ScaryMoment");
PlayGuiSound("react_pant.snt", 100); <------------ play this last
GiveSanityDamage(15, true);

}

At the moment it jumps to the last one
If I'm not mistaken, you seem to be under the misconception that AddTimer() waits for the given amount of time. Instead, it calls the given function (in your case it would be "ScaryMoment") after the specified time interval, but the flow of execution will not be halted in the meantime.
Thus, what you need is either a cascade of functions that each add a timer to the respective next one or one function that adds a timer to call itself and decide based on a state variable which action to take on each iteration.

The following should work; I haven't tested it, though.

Spoiler below!

Sorry for the lack of indentation:

void OnStart()
{
AddEntityCollideCallback("Player", "scary_trigger", "ScaryTriggerFunc", true, 1);
}

void ScaryTriggerFunc(string &in asParent, string &in asChild, int alState)
{
AddLocalVarInt("ScaryState", 0);
AddTimer("ScaryTimer", 0.0f, "ScaryTimerFunc");
}

void ScaryTimerFunc(string &in timer_name)
{
int state = GetLocalVarInt("ScaryState");

switch(state) {
case 0:
StartPlayerLookAt("look_blood", 4, 2, "");
PlayGuiSound("react_scare.snt", 100);
GiveSanityDamage(25, true);
break;
case 1:
StartPlayerLookAt("look_stair", 4, 2, "");
PlayGuiSound("react_breath_slow.snt", 100);
PlayGuiSound("notice.snt", 40);
StartScreenShake(0.1f, 2, 0.2f, 1);
break;
case 2:
StartPlayerLookAt("look_monster", 4, 2, "");
PlayGuiSound("react_pant.snt", 100);
GiveSanityDamage(15, true);
break;
default:
return;
}

SetLocalVarInt("ScaryState", state + 1);
AddTimer(timer_name, 2.5f, "ScaryTimerFunc");
}


Also note that all of the script functions of the HPL2 are non-blocking.
Could not get that code to work, but i fixed it with triggers instead.
Thanks anyway.