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?
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#1
Script for falling tree/knock player out?

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?

-Grind to the Gore-
(This post was last modified: 08-17-2013, 11:33 PM by GoreGrinder99.)
08-09-2013, 01:19 AM
Find
Tomato Cat Offline
Senior Member

Posts: 287
Threads: 2
Joined: Sep 2012
Reputation: 20
#2
RE: Script for falling tree/knock player out?

What do you have so far?
08-09-2013, 02:00 AM
Find
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#3
RE: Script for falling tree/knock player out?

(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.

-Grind to the Gore-
08-09-2013, 02:05 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#4
RE: Script for falling tree/knock player out?

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.
(This post was last modified: 08-09-2013, 10:47 PM by Neelke.)
08-09-2013, 10:46 PM
Find
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
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#6
RE: Script for falling tree/knock player out?

(08-10-2013, 12:28 AM)Kiandra Wrote: 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

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!

-Grind to the Gore-
08-10-2013, 02:54 AM
Find
CarnivorousJelly Offline
Posting Freak

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

(spoilers for size)
Spoiler below!

PHP Code: (Select All)
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: (Select All)
SetPlayerCrouching(true); 
So, all together, you get this:

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_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).

[Image: quote_by_rueppells_fox-d9ciupp.png]
(This post was last modified: 08-10-2013, 08:27 AM by CarnivorousJelly.)
08-10-2013, 07:45 AM
Find
Rapsis Offline
Member

Posts: 69
Threads: 6
Joined: Oct 2012
Reputation: 0
#8
RE: Script for falling tree/knock player out?

Don't you think a falling tree would kill a person instead of just knocking him out?
08-10-2013, 12:36 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#9
RE: Script for falling tree/knock player out?

(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.

"Veni, vidi, vici."
"I came, I saw, I conquered."
08-10-2013, 01:00 PM
Find
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#10
RE: Script for falling tree/knock player out?

(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.

-Grind to the Gore-
08-10-2013, 01:26 PM
Find




Users browsing this thread: 1 Guest(s)