Making Moveables Damage Things
Originally written by Ishtvan on http://forums.thedarkmod.com/topic/4723
To make a moveable damage something:
- Find or create a damage def. A good generic one is damage_generic. This does 20 damage with a small knockback.
- Add the following keys/values to your moveable's def:
"damage" "<name of your damage def, INCLUDING the "damage_" prefix>"
This is all you need to do damage when the moveable hits something, but it can be customized further with these keys:
- "minDamageVelocity" : When the moveable strikes something when moving below this velocity, no damage is done.
- "maxDamageVelocity" : Velocity dependent damage clamps above this value.
The damage vs. velocity has a square root dependence:
Sqrt[ ( v - minDamageVelocity ) / ( maxDamageVelocity - minDamageVelocity ) ]
"damageWhenActive" : Set to 1 or 0. This means the moveable will only do damage after some script calls "activate" on it. This is used by the Vagary in D3, so that the objects it throws only do damage after the vagary script calls "activate" on it. (There's also a scriptEvent for moveables called "enableDamage" that you can call with 1 or 0 to toggle damage on and off. Not sure why Id has two options to do the same thing). If this is set to 1, the moveable will NOT do damage initially. "Active" doesn't mean when it's moving, it means when a script calls "activate()" on it (or maybe when a script calls enableDamage, but I tried that and it didn't seem to work).
Frequency of the damage
The code as-is only does damage with a moveable once a second. I think this might be bad, because what if we have two AI that get crushed at the same time under a giant boulder? Ideally you'd do damage to both pretty much instantly and they'd die. If the moveable can only dish out damage to one thing every second though, that means that in this situation, one AI would die, the other would be fine under the boulder for a second, then if the boulder came to rest in that second, the boulder would no longer be above its min_damage_velocity, so the AI underneath would just support the whole weight of the boulder and be fine.
Or if you had a bunch of boxes that could be crushed by damage, giant moveable boulder falls on them, only one of them would be crushed for the first second, and they'd sequentially crush one by one each second, which is pretty crappy. So we may have to change this so that it only uses a timer to track damage done to the same entity twice in a row.