Arx Libertatis Bug Tracker
star_faded.png
Please log in to bookmark issues
feature_request_small.png
CLOSED  Feature request #1599  -  ON HIT event not specific enough when detecting spells
Posted Dec 31, 2021 - updated Jan 13, 2022   Shortlink: http://arx.vg/1599
action_vote_minus_faded.png
1
Votes
action_vote_plus_faded.png
icon_info.png This issue has been closed with status "Done" and resolution "RESOLVED".
Issue details
  • Type of issue
    Feature request
  • Status
     
    Done
  • Assigned to
    Not assigned to anyone
  • Progress
       
  • Type of bug
    Not triaged
  • Likelihood
    Not triaged
  • Effect
    Not triaged
  • Posted by
     Lalike
  • Owned by
    Not owned by anyone
  • Estimated time
    Not estimated
  • Category
    Not determined
  • Resolution
    RESOLVED
  • Priority
    Not determined
  • Targetted for
    icon_milestones.png Not determined
  • OS
    icon_customdatatype.png Any
  • Architecture
    icon_customdatatype.png Any
  • Fixed in
    icon_customdatatype.png Arx Libertatis 1.3
Issue description

My goal: being able to detect when an entity gets hit by a lightningbolt.  ⇑ top

When an entity gets hit by either a weapon or a spell it triggers the ON HIT event. The event has 2 parameters: PARAM1 = some floating point number (probably damage or distance) PARAM2 = source of damage

When it is a magic spell that hits the entity then PARAM2 is "spell", but there is no way of knowing what spell is causing it.

There is another event, which gives more info: ON SPELLCAST, where PARAM1 contains the name of the spell as a string. However the event only gets called once at the start of the spell. If a spell lasts for longer and the player moves around hitting entities then it will not get information on it.

I found these events on this wiki page: https://wiki.arx-libertatis.org/Script:Events

My solution is to keep track of the player's last spell in a variable that have been cast and whether it was lightningbolt or not. Then if the entity gets hit and PARAM2 is "spell" and my tracking variable is set, then I'm good to go. I'm also checking if the SENDER in the spellcast event is the player.

Limitations:

  1. will not detect if the player is casting multiple spells at once (having life drain and lightningbolt being triggered the same time). If I would to detect both of these events, then I would have to keep 2 tracking variables for the 2 spells, 3 variables for 3 spells, etc.
  2. would also require extra coding and variables for all enemy creatures (liches, snake women), who can also fight the player using lightningbolts and accidentally hit the target entity, which is because of my workaround implementation.


My workaround:

  1. ON INIT {
  2. SET §lightningWasCast 0
  3. ACCEPT
  4. }
  5.  
  6. ON SPELLCAST {
  7. IF (^SENDER != PLAYER) ACCEPT
  8.  
  9. IF (^$PARAM1 == lightning_strike) {
  10. SET §lightningWasCast 1
  11. } ELSE {
  12. SET §lightningWasCast 0
  13. }
  14.  
  15. ACCEPT
  16. }
  17.  
  18. ON HIT {
  19. IF (^$PARAM2 == "spell") {
  20. IF (§lightningWasCast == 1) {
  21. HEROSAY "buzz!"
  22. }
  23. }
  24. ACCEPT
  25. }


My ideal implementation:

  1. ON HIT {
  2. IF (^$PARAM2 == "spell") {
  3. IF (^$PARAM3 == "lightning_bolt") {
  4. HEROSAY "buzz!"
  5. }
  6. }
  7. ACCEPT
  8. }



#4
icon_reply.pngReply
Comment posted by
 Daniel Scharrer
Jan 13, 02:38
I have extended the on hit event to include information about the spell and damage type. Instead of a spell type it passes a spell instance ID which is a new concept I have added for this and part of the long-term plan to make spells into normal entities so you will have to use he new ^class_… system variable to get the spell type or use the isin operator from the if command.

The issue was updated with the following change(s):
  • This issue has been closed
  • The status has been updated, from New to Done.
  • The resolution has been updated, from Not determined to RESOLVED.
  • This issue's progression has been updated to 100 percent completed.