Frictional Games Forum (read-only)
Script for falling tree/knock player out? - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Script for falling tree/knock player out? (/thread-22373.html)

Pages: 1 2


Script for falling tree/knock player out? - GoreGrinder99 - 08-09-2013

I've been working on a script which isn't working so well and I've tossed it to start new. I have also copied the script from the Study map and the tree does falling after increasing the prop force to 10000 vs. 1000 and the camera does it's shake and the scared sound and such but no falling tree music or sound.

I want the tree to fall on the player and knock him out by fading the screen out with a collision sound and such and have it fade in a few later. Anyone know a good way to do this?


RE: Script for falling tree/knock player out? - Tomato Cat - 08-09-2013

What do you have so far?


RE: Script for falling tree/knock player out? - GoreGrinder99 - 08-09-2013

(08-09-2013, 02:00 AM)Tomato Cat Wrote: What do you have so far?

Umm, nothing, I got rid of it because I couldn't get the map to load anymore from changing things so much. I later copied over the forest script from the study hps and used that but couldnt get any falling tree sound or music to play with it that's supposed to like in the original game. But I also want it to fall on the player when entering a script area and knock him out.


RE: Script for falling tree/knock player out? - Neelke - 08-09-2013

It might not be a genius solution, but try to turn off the players movements or slow him down. Make some other stuff happen also during this event. Like creaking sounds a little bit everywhere.

Just a tip, buddy.


RE: Script for falling tree/knock player out? - CarnivorousJelly - 08-10-2013

Hmmmm, for the falling tree
Explanation:
Spoiler below!

PHP Code:
AddPropForce(stringasNamefloat afXfloat afYfloat afZstringasCoordSystem); 
  • string& asName = name of object falling
  • float afX = magnitude along x axis
  • float afY = magnitude along y axis
  • float afZ = magnitude along z axis
  • string& asCoordSystem = coordinates to use (should be "world")
Use the level editor to figure out which direction the tree should fall.
Arrows point in the positive directions when you're using the move tool
red is x, green is y, blue is z in the level editor

So something like this:
PHP Code:
AddPropForce("falling_tree_1"003000"world"); 

Which you would have to use in a script, probably the one where the tree falls. I would personally do something similar to ATDD where Daniel's in the Wine Cellar and a barrel falls on his head. This isn't exactly the same, but:
(using ko as an abbreviation for knock-out, assuming area_ko is right under the tree)
PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""area_ko""script_ko"true0);
}
void script_ko(string &in asParentstring &in asChildint alState)
{
    
SetPlayerCrouching(true); // make tree fall further
    
SetPlayerJumpDisabled(true); //slow movement
    
StartPlayerLookAt("falling_tree_1"5.0f8.0f""); //makes them look at tree
    
AddTimer("timer_stoplook"7.0f"timer_stoplook"); //terminates "look"
    
AddTimer("timer_blackout"7.0f"timer_blackout"); //this will depend on how long the tree takes to fall, 4.0f is 4 seconds
    
AddTimer("timer_wakeup"17.0f"timer_wakeup"); //revives player
    
AddPropForce("falling_tree_1"001000"world"); //makes tree fall
    
SetPlayerMoveSpeedMul(0.5f); //slows down player a ton
    
SetPlayerRunSpeedMul(0.5f); //applies slowness to running
    
StartScreenShake(0.05f4.0f0.5f10.0f); //shakes screen for 10 seconds
}

void timer_stoplook(string &in asTimer)
{
    
StopPlayerLookAt();
}

void timer_blackout(string &in asTimer)
{
    
FadeOut(0.0f); //instant blackout
}

void timer_wakeup(string &in asTimer)
{
    
FadeIn(4.0f); //4 seconds to wake up, takes a little longer
    
SetPlayerMoveSpeedMul(1.0f); //returns normal speed
    
SetPlayerRunSpeedMul(1.0f);
    
SetPlayerCrouching(false);
    
SetPlayerJumpDisabled(false);



Make sure the tree has room to fall and that it has the same name in the level editor (falling_tree_1) as it does in your script.

I'm going to test this out quickly so I can let ya know if it works.

Also, make sure you're actually using one of the trees that fall (under Entities/Special)

UPDATE
Tree stops falling because the ground is in the way, lift the tree up to 1.25 above the plane it's on.
5 seconds isn't long enough for the tree to fall, changed times a bit

I made the script better c:
PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""area_ko""script_ko"true0);
}

void OnEnter()
{

}

void Intro()
{

}

void script_ko(string &in asParentstring &in asChildint alState)
{
    
SetPlayerCrouching(true); // make tree fall further
    
SetPlayerJumpDisabled(true); //slow movement
    
StartPlayerLookAt("falling_tree_1"5.0f8.0f""); //makes them look at tree
    
AddTimer("timer_stoplook"7.0f"timer_stoplook"); //terminates "look"
    
AddTimer("timer_blackout"7.0f"timer_blackout"); //this will depend on how long the tree takes to fall, 4.0f is 4 seconds
    
AddTimer("timer_wakeup"17.0f"timer_wakeup"); //revives player
    
AddPropForce("falling_tree_1"001000"world"); //makes tree fall
    
SetPlayerMoveSpeedMul(0.5f); //slows down player a ton
    
SetPlayerRunSpeedMul(0.5f); //applies slowness to running
    
StartScreenShake(0.05f4.0f0.5f10.0f); //shakes screen for 10 seconds
    
PlaySoundAtEntity("fallingtree""11_forest_minor.snt""Player"0false); //makes cracking branches sounds
}

void timer_stoplook(string &in asTimer)
{
    
StopPlayerLookAt();
}

void timer_blackout(string &in asTimer)
{
    
FadeOut(0.0f); //instant blackout
    
PlaySoundAtEntity("insanity_ear_ring""insanity_ear_ring.snt""Player"3.0ffalse); //plays ringing noise
}

void timer_wakeup(string &in asTimer)
{
    
FadeIn(4.0f); //4 seconds to wake up, takes a little longer
    
SetPlayerMoveSpeedMul(1.0f); //returns normal walking speed
    
SetPlayerRunSpeedMul(1.0f); //returns normal running speed
    
SetPlayerJumpDisabled(false); //lets player jump again
    
StopSound("insanity_ear_ring"4.0f); //stops ringing noise


I checked this and it works. If you're still having problems making it work:
  • Check if your .hps and map file are in the same folder (obvious, I know, but that's usually my problem)
  • Make sure the level editor names for areas (area_ko) and objects (falling_tree_1) are the same as in the script
  • Make sure the tree's not actually touching the ground when it's standing - cover up the bottom with bushes (turn off collide)
  • delete any map.cache files you have

Feel free to ask if you want me to explain something in-depth


RE: Script for falling tree/knock player out? - GoreGrinder99 - 08-10-2013

(08-10-2013, 12:28 AM)Kiandra Wrote: Hmmmm, for the falling tree
Explanation:
Spoiler below!

PHP Code:
AddPropForce(stringasNamefloat afXfloat afYfloat afZstringasCoordSystem); 
  • string& asName = name of object falling
  • float afX = magnitude along x axis
  • float afY = magnitude along y axis
  • float afZ = magnitude along z axis
  • string& asCoordSystem = coordinates to use (should be "world")
Use the level editor to figure out which direction the tree should fall.
Arrows point in the positive directions when you're using the move tool
red is x, green is y, blue is z in the level editor

So something like this:
PHP Code:
AddPropForce("falling_tree_1"003000"world"); 

Which you would have to use in a script, probably the one where the tree falls. I would personally do something similar to ATDD where Daniel's in the Wine Cellar and a barrel falls on his head. This isn't exactly the same, but:
(using ko as an abbreviation for knock-out, assuming area_ko is right under the tree)
PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""area_ko""script_ko"true0);
}
void script_ko(string &in asParentstring &in asChildint alState)
{
    
SetPlayerCrouching(true); // make tree fall further
    
SetPlayerJumpDisabled(true); //slow movement
    
StartPlayerLookAt("falling_tree_1"5.0f8.0f""); //makes them look at tree
    
AddTimer("timer_stoplook"7.0f"timer_stoplook"); //terminates "look"
    
AddTimer("timer_blackout"7.0f"timer_blackout"); //this will depend on how long the tree takes to fall, 4.0f is 4 seconds
    
AddTimer("timer_wakeup"17.0f"timer_wakeup"); //revives player
    
AddPropForce("falling_tree_1"001000"world"); //makes tree fall
    
SetPlayerMoveSpeedMul(0.5f); //slows down player a ton
    
SetPlayerRunSpeedMul(0.5f); //applies slowness to running
    
StartScreenShake(0.05f4.0f0.5f10.0f); //shakes screen for 10 seconds
}

void timer_stoplook(string &in asTimer)
{
    
StopPlayerLookAt();
}

void timer_blackout(string &in asTimer)
{
    
FadeOut(0.0f); //instant blackout
}

void timer_wakeup(string &in asTimer)
{
    
FadeIn(4.0f); //4 seconds to wake up, takes a little longer
    
SetPlayerMoveSpeedMul(1.0f); //returns normal speed
    
SetPlayerRunSpeedMul(1.0f);
    
SetPlayerCrouching(false);
    
SetPlayerJumpDisabled(false);



Make sure the tree has room to fall and that it has the same name in the level editor (falling_tree_1) as it does in your script.

I'm going to test this out quickly so I can let ya know if it works.

Also, make sure you're actually using one of the trees that fall (under Entities/Special)

UPDATE
Tree stops falling because the ground is in the way, lift the tree up to 1.25 above the plane it's on.
5 seconds isn't long enough for the tree to fall, changed times a bit

I made the script better c:
PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""area_ko""script_ko"true0);
}

void OnEnter()
{

}

void Intro()
{

}

void script_ko(string &in asParentstring &in asChildint alState)
{
    
SetPlayerCrouching(true); // make tree fall further
    
SetPlayerJumpDisabled(true); //slow movement
    
StartPlayerLookAt("falling_tree_1"5.0f8.0f""); //makes them look at tree
    
AddTimer("timer_stoplook"7.0f"timer_stoplook"); //terminates "look"
    
AddTimer("timer_blackout"7.0f"timer_blackout"); //this will depend on how long the tree takes to fall, 4.0f is 4 seconds
    
AddTimer("timer_wakeup"17.0f"timer_wakeup"); //revives player
    
AddPropForce("falling_tree_1"001000"world"); //makes tree fall
    
SetPlayerMoveSpeedMul(0.5f); //slows down player a ton
    
SetPlayerRunSpeedMul(0.5f); //applies slowness to running
    
StartScreenShake(0.05f4.0f0.5f10.0f); //shakes screen for 10 seconds
    
PlaySoundAtEntity("fallingtree""11_forest_minor.snt""Player"0false); //makes cracking branches sounds
}

void timer_stoplook(string &in asTimer)
{
    
StopPlayerLookAt();
}

void timer_blackout(string &in asTimer)
{
    
FadeOut(0.0f); //instant blackout
    
PlaySoundAtEntity("insanity_ear_ring""insanity_ear_ring.snt""Player"3.0ffalse); //plays ringing noise
}

void timer_wakeup(string &in asTimer)
{
    
FadeIn(4.0f); //4 seconds to wake up, takes a little longer
    
SetPlayerMoveSpeedMul(1.0f); //returns normal walking speed
    
SetPlayerRunSpeedMul(1.0f); //returns normal running speed
    
SetPlayerJumpDisabled(false); //lets player jump again
    
StopSound("insanity_ear_ring"4.0f); //stops ringing noise


I checked this and it works. If you're still having problems making it work:
  • Check if your .hps and map file are in the same folder (obvious, I know, but that's usually my problem)
  • Make sure the level editor names for areas (area_ko) and objects (falling_tree_1) are the same as in the script
  • Make sure the tree's not actually touching the ground when it's standing - cover up the bottom with bushes (turn off collide)
  • delete any map.cache files you have

Feel free to ask if you want me to explain something in-depth

Very nice indeed, thank you! I was wondering if there was any way to implement the player being crashed to the ground as if he was really knocked down by the tree? I want to have the player fall to the ground on their side, if not that's okay I'll see what I can do otherwise, you've helped so much already!


RE: Script for falling tree/knock player out? - CarnivorousJelly - 08-10-2013

(spoilers for size)
Spoiler below!

PHP Code:
void FadePlayerRollTo(float afXfloat afSpeedMulfloat afMaxSpeed); 
It causes the player's head to tilt sideways.
fload afX = angle of rotation, positive is counter-clockwise
fload afSpeedMul = how fast it happens
fload afMaxSpeed = maximum speed of rotation

To lower him/her to the ground, use
PHP Code:
SetPlayerCrouching(true); 
So, all together, you get this:

PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""area_ko""script_ko"true0);
}

void OnEnter()
{

}

void Intro()
{

}

void script_ko(string &in asParentstring &in asChildint alState)
{
    
SetPlayerCrouching(true); // make tree fall further
    
SetPlayerJumpDisabled(true); //slow movement
    
StartPlayerLookAt("falling_tree_1"5.0f8.0f""); //makes them look at tree
    
AddTimer("timer_blackout"7.5f"timer_blackout"); //causes blackout
    
AddTimer("timer_wakeup"17.0f"timer_wakeup"); //revives player
    
AddPropForce("falling_tree_1"001000"world"); //makes tree fall
    
SetPlayerMoveSpeedMul(0.2f); //slows down player a ton
    
SetPlayerRunSpeedMul(0.2f); //applies slowness to running
    
StartScreenShake(0.05f4.0f0.5f10.0f); //shakes screen for 10 seconds
    
PlaySoundAtEntity("fallingtree""11_forest_minor.snt""Player"0false); //makes cracking branches sounds
    
AddTimer("timer_fallsideways"7.0f"timer_fallsideways"); //player falls over just before passing out
}

void timer_fallsideways(string &in asTimer)
{
    
FadePlayerRollTo(65220220); //head is sideways on floor, 65 is highest possible without glitches
    
PlaySoundAtEntity("hit""player_falldamage_max.snt""Player"0.0ffalse); //sound of tree hitting
    
GivePlayerDamage(20.0f"BloodSplat"falsefalse); // non-lethal damage to player
}

void timer_blackout(string &in asTimer)
{
    
FadeOut(0.0f); //instant blackout
    
PlaySoundAtEntity("insanity_ear_ring""insanity_ear_ring.snt""Player"3.0ffalse); //plays ringing noise
    
StopPlayerLookAt();
}

void timer_wakeup(string &in asTimer)
{
    
FadeIn(4.0f); //4 seconds to wake up, takes a little longer
    
SetPlayerMoveSpeedMul(1.0f); //returns normal walking speed
    
SetPlayerRunSpeedMul(1.0f); //returns normal running speed
    
SetPlayerJumpDisabled(false); //lets player jump again
    
StopSound("insanity_ear_ring"4.0f); //stops ringing noise
    
AddTimer("timer_headnormal"4.0f"timer_headnormal"); //forces a bit of recovery time
}

void timer_headnormal(string &in asTimer)
{
    
FadePlayerRollTo(0220220); //head back to normal
}

void OnLeave()
{




By the way, I'm getting all of this from here (in case you didn't know this existed). Just use "ctrl+f" and type in a keyword (crouch brings up SetPlayerCrouching).

Also, play around with the numbers I gave. You might end up with something you like better. If not, the original code is here and the scripts are in that link.



Oh, and one more thing: Have you set up a development environment yet? Once you have, load your map before making the .hps file for it.
Instead of crashing when you go to test your scripts (by clicking "Reload" from the dev bar), it just won't reload. You'll get a message on the screen telling you where the error is in your script and where it is (unless it's a missing ";" or "}" then you'll just get "unexpected end of file" and have to play Spot the Error).


RE: Script for falling tree/knock player out? - Rapsis - 08-10-2013

Don't you think a falling tree would kill a person instead of just knocking him out?


RE: Script for falling tree/knock player out? - PutraenusAlivius - 08-10-2013

(08-10-2013, 12:36 PM)Rapsis Wrote: Don't you think a falling tree would kill a person instead of just knocking him out?

Yeah, it will. Unless if the tree is small.


RE: Script for falling tree/knock player out? - GoreGrinder99 - 08-10-2013

(08-10-2013, 01:00 PM)JustAnotherPlayer Wrote:
(08-10-2013, 12:36 PM)Rapsis Wrote: Don't you think a falling tree would kill a person instead of just knocking him out?

Yeah, it will. Unless if the tree is small.

Well, I'm going to have it fall on them and knock them out and have them wake up near death. The scripts are working like a charm and I thank all of you. But I do have another question...

Where in the redist would you locate the files referring to the ui "hurt_pain" sounds? What I mean is when the player is hurt and near death the sounds he makes when he's in pain, like you've been mauled by the monsters and are about to die, what files are linked to those sounds and where are they? I have looked but with no luck of finding anything.