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 for falling tree/knock player out?
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#5
RE: Script for falling tree/knock player out?

Hmmmm, for the falling tree
Explanation:
Spoiler below!

PHP Code: (Select All)
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: (Select All)
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: (Select All)
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: (Select All)
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

[Image: quote_by_rueppells_fox-d9ciupp.png]
(This post was last modified: 08-10-2013, 01:12 AM by CarnivorousJelly.)
08-10-2013, 12:28 AM
Find


Messages In This Thread
RE: Script for falling tree/knock player out? - by CarnivorousJelly - 08-10-2013, 12:28 AM



Users browsing this thread: 3 Guest(s)