Resource (Entity Condition Type)
Compares the value of an apoli:resource power with a number. It also reads any power type with a built-in cooldown, using the remaining ticks as the value.
Type ID: apoli:resource
Fields
| Field | Type | Default | Description |
|---|---|---|---|
resource | Identifier | required | The ID of the power to read. |
position | Integer or Expression | optional | Which slot of a table resource to read. Leave it out and the condition passes if any slot satisfies the comparison. index and slot are accepted as aliases. |
comparison | Comparison | required | How the power's value is compared with compare_to. |
compare_to | Integer or Expression | required | The value the resource is compared against. check is accepted as an alias. An expression is evaluated again every time the condition is tested, so you can compare a resource against another resource, an entity stat or any arithmetic on them. |
Checking one slot of a table
When resource names an apoli:resource with a size above 1, position picks the slot to read:
"condition": {
"type": "apoli:resource",
"resource": "example:table",
"position": 2,
"comparison": "==",
"compare_to": 5
}That reads the value at position 2 and passes when it is 5.
Leave position out and the condition asks whether the value is anywhere in the table:
"condition": {
"type": "apoli:resource",
"resource": "example:table",
"comparison": "==",
"compare_to": 5
}position is an expression too, so the slot can be worked out when the condition runs. "position": "example:cursor" reads whichever slot another resource points at.
On a resource with one value (no size, or a size of 1), leaving position out reads that single value.
Cooldowns as resources
resource doesn't have to name an apoli:resource or apoli:cooldown power. Every power type with a built-in cooldown field exposes that cooldown as a read-only resource whose value is the number of ticks left, where 0 means the power is ready:
- apoli:action_on_key_press (and its
active_selfalias) - apoli:action_on_key_sequence
- apoli:fire_projectile
- apoli:action_on_hit, apoli:action_when_hit
- apoli:action_on_kill
- apoli:action_on_collision
- apoli:game_event_listener
So the usual check for whether an ability is off cooldown compares against 0:
"condition": {
"type": "apoli:resource",
"resource": "example:dash",
"comparison": "==",
"compare_to": 0
}The same IDs work in apoli:modify_resource and /apoli:resource, so a data pack can shorten or clear an ability's cooldown. Writes are clamped between 0 and cooldown.
Comparing against an expression
compare_to accepts a full expression, as well as a plain number. On top of the usual expression variables, these are bound here:
value: the current value of the resource named inresource, the same number as on the left of the comparison.<namespace>:<path>: the value of any other resource or cooldown power the entity has, written as its full power ID. This is how you compare one resource against another.- Every other expression variable, such as
health,max_health,xp_levelandworld_time. See the Expression page for the full list.
Examples
"condition": {
"type": "apoli:resource",
"resource": "example:a_simple_resource",
"comparison": "==",
"compare_to": 1
}This checks whether the player has a value of 1 in the example:a_simple_resource resource power (data/example/powers/a_simple_resource.json).
"condition": {
"type": "apoli:resource",
"resource": "example:a_multiple_power_with_resource_subpower",
"comparison": ">",
"compare_to": 50
}This checks whether the player has a value above 50 in the with_resource_subpower sub-power of the example:a_multiple_power power (data/example/powers/a_multiple_power.json).
"condition": {
"type": "apoli:resource",
"resource": "example:mana",
"comparison": ">=",
"compare_to": "example:spell_cost"
}This compares one resource against another, and passes when the entity's example:mana resource is at least as large as its example:spell_cost resource.
"condition": {
"type": "apoli:resource",
"resource": "example:rage",
"comparison": ">",
"compare_to": "max_health / 2"
}Expressions can mix resources with entity stats and arithmetic. This passes when the example:rage resource is more than half the entity's maximum health.