Attack Meter Handler
The Attack Meter Handler manages entity-based threats and player damage sequences. AddInstance uses start and end distances for the threat, while AutoDamage schedules damage after a delay. Custom and after-damage callbacks allow a map to replace or continue the damage sequence.
Contents
Before you start
- Open the map script inside your own mod. Keep its generated includes,
cScrMap : iScrMapclass and callback structure. See Add your first script if you have not edited a map script yet. - Add the helper include shown below alongside the script’s other includes.
- Read the stock example before copying its calls: named entities, voice subjects, materials and callbacks must belong to the map or resources you are using.
Follow the stock example
#include "helpers/helper_modules.hps"
AttackMeter_AddInstance
Adds an entity as something that is about to damage the player.
| Parameter | Meaning |
|---|---|
a_idEntity |
ID for the entity |
afStartDistance |
How close entity needs to be before the attack meter starts. |
afEndDistance |
How close the entity needs to be for the player to take damage |
afDamage |
How much damage will the attack take? |
abFatal |
Whether this attack is fatal. |
abFastNonLookKill |
If true, the entity will damage quickly even if the player isn't looking at it. |
abInstantKnockOut |
if true, the player will be knocked out on the first attack |
In script/custom_depth/agent_construct_worker.hps, SOMA calls AttackMeter_AddInstance as follows.
AttackMeter_AddInstance(mBaseObj.GetID(), 4, 2, 0.2);
| Parameter | Value in this stock call |
|---|---|
a_idEntity |
mBaseObj.GetID()
|
afStartDistance |
4
|
afEndDistance |
2
|
afDamage |
0.2
|
This is an excerpt from that stock script; its referenced names and variables belong to that script.
AttackMeter_SetAfterDamageCallback
This sets a callback that is called after taken daming.
| Parameter | Meaning |
|---|---|
asCallback |
The callback function to be used. Syntax: void f(const tString& in asSource) |
In maps/_e3/_e3_01_02/_e3_01_02.hps, SOMA calls AttackMeter_SetAfterDamageCallback as follows.
AttackMeter_SetAfterDamageCallback("VentBotDamage");
| Parameter | Value in this stock call |
|---|---|
asCallback |
"VentBotDamage"
|
This is an excerpt from that stock script; its referenced names and variables belong to that script.
AttackMeter_RemoveInstance
Removes an entity as something that is about to damage the player.
| Parameter | Meaning |
|---|---|
a_idEntity |
ID for the entity |
In maps/chapter02/02_06_theta_tunnels/02_06_theta_tunnels.hps, SOMA calls AttackMeter_RemoveInstance as follows.
AttackMeter_RemoveInstance(Map_GetEntity(msElevatorPuppet).GetID());
| Parameter | Value in this stock call |
|---|---|
a_idEntity |
Map_GetEntity(msElevatorPuppet).GetID()
|
This is an excerpt from that stock script; its referenced names and variables belong to that script.
Check your change
Save the script and restart the map in development mode with F5. If the script fails, open F1 and use Show Error List or Show HPL Log. See the development loop for the launch and debugging steps.