trigger_damagethreshold simulator

I think it was the hipnotic expansion pack which added an entity called trigger_damagethreshold. This entity works like a shootable trigger, except that there is a minimum amount of damage which it takes to set it off. While working on a different hack I came up with a way to recreate this entity in stock quake by setting some fields and exploiting things about floats.

So the plan is to create an trigger_once with “health” “1”, and then give it “armortype” and “armorvalue” keys so that weaker attacks don’t even do one damage. For example we want the trigger to only fire when we do 30 or more damage in a single attack. In quake, an entity with armortype a which takes d points of damage will lose ceil(a*d) armour, and any remaining damage will be lost as health. If we pick a so that when d = 30, d * a = 29 exactly, attacks of 30 damage will do exactly 1 health, but attacks of 29 damage or less will do none (remember that damage to armour is rounded up).

We need to solve the following equation for a
a * d = d - 1
Divide by d and we get:
a = (d - 1) / d

29 / 30 = 0.966666..., so round that down in the last decimal place to ensure damage of exactly 30 will succeed, and enter it as the “armortype” key. This works great until the trigger runs out of armour points, at which point any attack will set off the trigger. How do we prevent weak attacks from chipping away like this? Well, this is where the infinite ammo trick comes in handy. Just set the “armorvalue” key to a number large enough that subtracting values less than 30 from it doesn’t actually change the number! The linked article showed that 99999999 is large enough to ignore subtractions of 1, so 99999999999 is more than enough to ensure you can’t subtract 30 from it.

And that’s it, one calculation and two keys later, your trigger is complete. Little brainteaser to end with: if we wanted to use a trigger_multiple instead, what potential problem might we encounter? Is it a realistic worry? Can we do something about it?

Advertisements

3 thoughts on “trigger_damagethreshold simulator

  1. “armortype” “0.966667”
    “armorvalue” “999999616.000000” taken from save game
    applied to monster_dog makes a tough puppy

  2. Nice! Didn’t know you could even have other arbitrary armortype values.
    And I used to make ‘tough dogs’ with negative value trigger_hurt lol.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s