Frictional Games Forum (read-only)
[SCRIPT] Give Prop Damage? - 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] Give Prop Damage? (/thread-12754.html)



Give Prop Damage? - Shadowfied - 01-21-2012

I want to make a script where you break a door with an axe, not in the inventory but you lift it up and hit the door, so when I got the idea, my thoughts was to make a script when the axe collide with the door, it subtracts for example 20 of the doors health, so after a few hits it would be 0. There is a function called AddPropHealth but there doesn't seem to be one of for the opposite. I tried using AddPropHealth and using -20 for the value but that doesn't work.

I appreciate any tips on making this script, and even if there are better ways to make a script like this, I would still like to know if there is a way to subtract health from a prop.

Sorry for posting so many questions by the way, but thanks for answering them.

Thanks in advance.



RE: Give Prop Damage? - flamez3 - 01-21-2012

void OnStart()
{
AddEntityCollideCallback("axe", "door", "hurtdoor", false, 1);
}

void hurtdoor(string &in asParent, string &in asChild, int alState)
{
SetPropHealth(-30.0f);
}

Note: I don't know if that works, just putting it out there.


RE: Give Prop Damage? - Shadowfied - 01-21-2012

I've been thinking about that, but wouldn't that mean that every time it collides, it Sets the props health to -30? Cause then it's not subtracting the health, just setting it.

Okay it actually does work with "AddPropHealth" and then using a negative value, but I can't get it to work on the door...nothing works on the door, it worked on a wooden barrel though..



RE: Give Prop Damage? - Streetboat - 01-21-2012

Interesting idea, I hope it works out!

As it happens, I have a solution for ya, because I did something similar. Hint: use LocalVarInts. Every time the axe collides with the door, check for the LocalVarInt and set the health to a certain level, and at the same time, add 1 to the LocalVarInt. That way, every time the function is called, a different output will be made. For example:

void hurtdoor(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("hit") == 0)
{
SetPropHealth(80.0f);
AddLocalVarInt("hit", 1);
}
if(GetLocalVarInt("hit") == 1)
{
SetPropHealth(60.0f);
AddLocalVarInt("hit", 1);
}

...and so on. Hope that helps!


RE: Give Prop Damage? - Your Computer - 01-21-2012

Try
PHP Code:
if (GetPropHealth("prop_name") > 0)
    
SetPropHealth("prop_name"GetPropHealth("prop_name")-10); 



RE: Give Prop Damage? - Shadowfied - 01-21-2012

(01-21-2012, 05:53 PM)Streetboat Wrote: Interesting idea, I hope it works out!

As it happens, I have a solution for ya, because I did something similar. Hint: use LocalVarInts. Every time the axe collides with the door, check for the LocalVarInt and set the health to a certain level, and at the same time, add 1 to the LocalVarInt. That way, every time the function is called, a different output will be made. For example:

void hurtdoor(string &in asParent, string &in asChild, int alState)
{
if(GetLocalVarInt("hit") == 0)
{
SetPropHealth(80.0f);
AddLocalVarInt("hit", 1);
}
if(GetLocalVarInt("hit") == 1)
{
SetPropHealth(60.0f);
AddLocalVarInt("hit", 1);
}

...and so on. Hope that helps!
I think I know how you're thinking, but I need to see more of the script to understand it, I think.
Edit: Nevermind I'm just stupid. I pasted your script and fixed the names but it didn't work on the door or the barrel.
Edit2: Oh wait I'm even more stupid. Hold on..
Edit3: Ok I got it working the way you were thinking (I guess) and made it all the way down to 0, which should take 4 hits but it breaks instantly (the barrel right now), probably cause there are a lot of tiny collisions. I would need to make it so that it only counts when it collides with a pretty big amount of force..


(01-21-2012, 05:59 PM)Your Computer Wrote: Try
PHP Code:
if (GetPropHealth("prop_name") > 0)
    
SetPropHealth("prop_name"GetPropHealth("prop_name")-10); 
Did not work, at least not with the way I inserted it. Besides, I don't understand that at all, and I hate using scripts which I don't understand how to make, or how they work. I appreciate the tip, though.




RE: Give Prop Damage? - Your Computer - 01-21-2012

(01-21-2012, 06:04 PM)Shadowfied Wrote: Did not work, at least not with the way I inserted it. Besides, I don't understand that at all, and I hate using scripts which I don't understand how to make, or how they work. I appreciate the tip, though.

First line checks to see if the health of the prop is greater than 0 (there is no point in giving a prop health that is below 0). Second line takes away 10 health points from the prop. That's part of the same script that i used to break open a door. Taking away 10 health points each time requires more banging on the door (possibly over 5 hits) before completely breaking, assuming the door starts off at 100 health points.


RE: Give Prop Damage? - Streetboat - 01-21-2012

I didn't know one could break barrels and that they had a damage model. Interesting...


RE: Give Prop Damage? - Shadowfied - 01-21-2012

(01-21-2012, 07:11 PM)Streetboat Wrote: I didn't know one could break barrels and that they had a damage model. Interesting...
I saw that several times during my first playthrough of the Dark Descent when monsters smashed them.

I also saw in the super_secret folder in an early alpha build that they threw a barrel / box and it broke. In my upcoming story I have modified all of those crates and barrels to be breakable when you throw them, allowing you to find items inside them.