Function; SobGroup_SetDamageMultiplier - HWRM/KarosGraveyard GitHub Wiki
SobGroup_SetDamageMultiplier(<sSobGroupName>, <fMultiplier>)
Description
Sets the 'damage multiplier' of sSobGroup
. This function works somewhat strangely: The damage is set to current + (base * (fMultiplier - 1))
, where current
is the current damage this ship deals (which may have already been altered by previous SobGroup_SetDamageMultiplier
calls), and base
is the base damage this weapon usually deals.
This will modify all the effects for the weapons (set by Function;-AddWeaponResult) used by the ships within sSobGroupName
, including "Push"
effects and so on. The damage a weapon deals cannot become negative, although these other effects are not limited in this way.
If a weapons damage is multiplied to a negative value, the weapon instead deals 0 damage and may not play its projectile effects correctly (i.e an ion beam will flare its muzzle and spawn hit clouds on the target, but the beam itself will not appear).
There is no upper or lower bound on the results of this function, so you can achieve crazy numbers pretty easily.
Example
-- adds `base * (3 - 1)` damage to the current damage for all ships in "my-group"
SobGroup_SetDamageMultiplier("my-group", 3);
Since this function works with running totals, if the above call was run within a ship's update
customcode hook, the ship's damage would have base * (3 - 1)
damage added every time the hook was called. If we start with 100
base damage we get: 100 -> 300 -> 500 -> 700 -> ...
Call # | Base | Current | base * (fMultiplier - 1) |
Result |
---|---|---|---|---|
1 | 100 | 100 | 100 * (3 - 1) = 200 |
100 + 200 = 300 |
2 | 100 | 300 | 100 * (3 - 1) = 200 |
300 + 200 = 500 |
3 | 100 | 500 | 100 * (3 - 1) = 200 |
500 + 200 = 700 |
This has the consequence that it's a little tricky to change this value back later:
-- b = base damage
-- here, c = b
SobGroup_SetDamageMultiplier("my-group", 3); -- c = c + (b * (3 - 1)) = c + 2b = 3b
-- but here, c is now 3b
-- so we need to figure out which value will produce -2b
SobGroup_SetDamageMultiplier("my-group", -1); -- c = c + (b * (-1 - 1)) = c + -2b = b
You can see we don't pass 0.3
, -3
, or anything that you may have initially assumed. The comments show how this works (b
is the base damage, and c
is initially set to this value). You can see that to get back to the base value, we need to figure out which value will undo passing 3
initially. This happens to be -1
, and the relationship is: abs(1 - 3) = abs(1 - -1)
.
Knowing this relationship between positive and negative calls to this function, you should be able to figure out what values you need to supply to achieve a desired value.
Arguments
Param | Type | Description |
---|---|---|
sSobGroupName |
string |
The group who's attack will be modified. |
fMultiplier |
number |
base * (fMultiplier - 1) will be added to the current attack of the group's ships. |
Returns
Type | Description |
---|---|
number |
Always 1 . |