Script:on hit: Difference between revisions

From Arx Libertatis Wiki
Jump to navigation Jump to search
(Created page with "{{ScriptEventPage |sender=the damage source |target=NPCs and props |trigger=when the the entity is damaged |parameters=<code>^&param1</c...")
 
m (Mention use of ^class_… to get the spell type)
 
(6 intermediate revisions by the same user not shown)
Line 35: Line 35:
| n || Drain mana
| n || Drain mana
|-
|-
| n || Push
| u || Push
|}
|}


Spell IDs are made up of the [[Script:spellcast#Spell_names|spell name]] followed by <code>_</code> and then a unique instance number. Use the {{Command|if|isin}} command to check for spell or damage types:
Spell IDs are made up of the [[Script:spellcast#Spell_names|spell name]] followed by <code>_</code> and then a unique instance number. Use <code>^spelllevel_~^$param3~</code> to check the spell level and use the {{Command|if|isin}} command or the [[Script:Variables#System_variables|<code>^class_…</code> system variable]] to check for spell or damage types:


  {{Command|if}} {{Highlight|string|fireball}} isin {{Highlight|string|^$param3}} {
'''on hit''' {
    // Hit by a fireball
  {{Command|if}} {{Highlight|string|lightning_strike}} isin {{Highlight|string|^$param3}} {
  }
    // Hit by a {{Spell|lightning projection}} or {{Spell|mass lightning projection}} spell
  {{Command|if}} {{Highlight|string|l}} isin {{Highlight|string|^$param4}} {
  }
    // Hit with lightning damage
  {{Command|if}} {{Highlight|string|^class_~^$param3~}} == {{Highlight|string|lightning_strike}} {
  }
    // Hit by a {{Spell|lightning projection}} spell
  }
  {{Command|if}} {{Highlight|string|l}} isin {{Highlight|string|^$param4}} {
    // Hit with lightning damage
  }
}
 
For [[:Category:NPCs|NPCs]], scripts can prevent the damage to the entity by responding to the {{Event|hit}} event with {{Command|refuse}}.
 
When 0 life or durability is reached for [[:Category:NPCs|NPCs]] or [[:Category:Props|props]], the {{Event|die}} or {{Event|break}} events are sent respectively.

Latest revision as of 02:36, 13 January 2022

The hit script event is sent by the damage source to NPCs and props when the the entity is damaged. ^&param1 will be set to the damage received by the entity while ^$param2 is set to the weapon type if the damage source is the player: spell, bare, dagger, 1h, 2h, arrow or (for NPC targets only before Arx Libertatis 1.3) summoned if the damage is from a summoned entity. In this case, the event ^sender will be the player.

With Arx Libertatis 1.3 or newer, ^$param3 holds the spell ID or entity ID of the weapon or summoned entity used to inflict the damage and ^$param4 specifies the damage type flags as used in the dodamage and damager commands:

f Fire
m Magical
p Poison
l Lightning
c Cold
g Gas
e Metal
w Wood
s Stone
a Acid
o Organic
r Drain life
n Drain mana
u Push

Spell IDs are made up of the spell name followed by _ and then a unique instance number. Use ^spelllevel_~^$param3~ to check the spell level and use the if isin command or the ^class_… system variable to check for spell or damage types:

on hit {
  if lightning_strike isin ^$param3 {
    // Hit by a Lightning projection (Aam Rune (create)Folgora Rune (lightning)Taar Rune (missile)) or Mass lightning projection (Aam Rune (create)Folgora Rune (lightning)Spacium Rune (field)) spell
  }
  if ^class_~^$param3~ == lightning_strike {
    // Hit by a Lightning projection (Aam Rune (create)Folgora Rune (lightning)Taar Rune (missile)) spell
  }
  if l isin ^$param4 {
    // Hit with lightning damage
  }
}

For NPCs, scripts can prevent the damage to the entity by responding to the hit event with refuse.

When 0 life or durability is reached for NPCs or props, the die or break events are sent respectively.