| 
		
	
		| AnthonyTrix   Junior Member
 
 Posts: 17
 Threads: 5
 Joined: Apr 2012
 Reputation: 
0
 | 
			| Force to trigger function. 
 
				Hi,
 I was just wondering how I trigger a function when a certain force is applied.
 
 Example: The wall in the archives with the holes in it. If you throw a rock on it hard enough it breaks. How do I do that?
 
 EDIT: In my case I want the player to slam a sledgehammer into a wall in order for it to break.
 
				
(This post was last modified: 04-15-2012, 05:38 PM by AnthonyTrix.)
 |  |  
	| 04-15-2012, 05:11 PM |  |  
	
		| Acies   Posting Freak
 
 Posts: 1,643
 Threads: 60
 Joined: Feb 2011
 Reputation: 
73
 | 
			| RE: Force to trigger function. 
 
				I am no scripting guru, but I think the "destroy on certain force" can be assigned in the ModelEditor. You can also assign a "deathentity" created when the wall is destroyed. Perhaps some rocks?
 As for what force you should specify, no idea :>
 
  ![[Image: mZiYnxe.png]](http://i.imgur.com/mZiYnxe.png)  ジ
 |  |  
	| 04-15-2012, 05:19 PM |  |  
	
		| Homicide13   Senior Member
 
 Posts: 323
 Threads: 41
 Joined: Nov 2010
 Reputation: 
14
 | 
			| RE: Force to trigger function. 
 
				You can either use the model editor to set the health of the prop you want to destroy, or you can put an area in front of the wall and have it set to destroy the wall when the hammer enters the area.
 Both solutions have their benefits, but the first solution is more realistic.
 
 
 |  |  
	| 04-15-2012, 05:21 PM |  |  
	
		| AnthonyTrix   Junior Member
 
 Posts: 17
 Threads: 5
 Joined: Apr 2012
 Reputation: 
0
 | 
			| RE: Force to trigger function. 
 
				Thanks for the quick replies. 
I will try both now    |  |  
	| 04-15-2012, 05:23 PM |  |  
	
		| DRedshot   Senior Member
 
 Posts: 374
 Threads: 23
 Joined: Jun 2011
 Reputation: 
11
 | 
			| RE: Force to trigger function. 
 
				You place two areas a certain distance from one another. 
Place the first area a few inches away from the wall, and put the second on the wall. 
 
Measure the distance between these areas, and declare it in your script as a constant, ie: 
float Distance = 0.25f;
 
Now when the hammer passes through the first area, start a timer, and when it passes through the second timer, call "GetTimerTimeLeft" and use this value to work out the time taken for the collision.
 
Now divide the Distance by this number to calculate the speed, and have an if statement to check if the speed is larger than a certain value!    
Edit: already answered   
 
				
(This post was last modified: 04-15-2012, 05:30 PM by DRedshot.)
 |  |  
	| 04-15-2012, 05:29 PM |  |  
	
		| AnthonyTrix   Junior Member
 
 Posts: 17
 Threads: 5
 Joined: Apr 2012
 Reputation: 
0
 | 
			| RE: Force to trigger function. 
 
				Thanks it worked when I used the way Acies and Homicide suggested (Model editor)
 |  |  
	| 04-15-2012, 05:33 PM |  |  
	
		| Damascus   Senior Member
 
 Posts: 646
 Threads: 118
 Joined: Mar 2012
 Reputation: 
29
 | 
			| RE: Force to trigger function. 
 
				 (04-15-2012, 05:29 PM)DRedshot Wrote:  You place two areas a certain distance from one another.Place the first area a few inches away from the wall, and put the second on the wall.
 
 Measure the distance between these areas, and declare it in your script as a constant, ie:
 float Distance = 0.25f;
 
 Now when the hammer passes through the first area, start a timer, and when it passes through the second timer, call "GetTimerTimeLeft" and use this value to work out the time taken for the collision.
 
 Now divide the Distance by this number to calculate the speed, and have an if statement to check if the speed is larger than a certain value!
  
 
 Edit: already answered
  Could I get some more info on this method? I'd like to use this method to break down a door with any of several large rocks laying around. I don't know how to declare constants, start running timers and calculating speed...
 
This is how I'm planning to start the callbacks (given that there are ten large rocks scattered about the level):
 
void OnStart 
{ 
for(int i=1;i<=10;i++)
 
{ 
AddEntityCollideCallback("rock_debris_01_"+i, "ImpactArea1", "Impact1", false, 1); 
} 
for(int i=1;i<=10;i++)
 
{ 
AddEntityCollideCallback("rock_debris_01_"+i, "ImpactArea2", "Impact2", false, 1); 
} 
}
			 
 |  |  
	| 04-16-2012, 12:41 AM |  |  
	
		| zombiehacker595   Member
 
 Posts: 141
 Threads: 51
 Joined: Mar 2012
 Reputation: 
3
 | 
			| RE: Force to trigger function. 
 
				 (04-16-2012, 12:41 AM)Damascus Wrote:   (04-15-2012, 05:29 PM)DRedshot Wrote:  You place two areas a certain distance from one another. Could I get some more info on this method? I'd like to use this method to break down a door with any of several large rocks laying around. I don't know how to declare constants, start running timers and calculating speed...Place the first area a few inches away from the wall, and put the second on the wall.
 
 Measure the distance between these areas, and declare it in your script as a constant, ie:
 float Distance = 0.25f;
 
 Now when the hammer passes through the first area, start a timer, and when it passes through the second timer, call "GetTimerTimeLeft" and use this value to work out the time taken for the collision.
 
 Now divide the Distance by this number to calculate the speed, and have an if statement to check if the speed is larger than a certain value!
   
 
 Edit: already answered
  
 This is how I'm planning to start the callbacks (given that there are ten large rocks scattered about the level):
 
 void OnStart
 {
 for(int i=1;i<=10;i++)
 
 {
 AddEntityCollideCallback("rock_debris_01_"+i, "ImpactArea1", "Impact1", false, 1);
 }
 for(int i=1;i<=10;i++)
 
 {
 AddEntityCollideCallback("rock_debris_01_"+i, "ImpactArea2", "Impact2", false, 1);
 }
 }
 
here is a much easier way of doing it 
 
{ 
 
AddEntityCollideCallback("ScriptArea_1", "sledge_1", "DestroyDoor", true, 1); 
 
} 
 
void DestroyDoor(string &in asParent, string &in asChild, int alState) 
 
{  
SetEntityActive("cellar_wood01_2", false);  
SetEntityActive("cellar_wood01_broken_1", true);  
PlaySoundAtEntity("", "break_wood.snt", "ScriptArea_1", 0, false);  
} 
 
Place a script area at the door then sledge_1 can be changed to the rocks name, place two doors one working one broken when the rock or whatever youre using collides with the area the door will turn into a broken door with the sound as added effect much more simple and easy 
			 |  |  
	| 04-16-2012, 12:00 PM |  |  |