set_trigger_result not overriding melee inflicted damage for ti_on_agent_hit trigger, works fine for ranged

Users who are viewing this thread

Garedyr

Master Knight
Greetings,

Any idea what might be the cause of set_trigger_result operation not overriding the damage for ti_on_agent_hit trigger if the damage was inflicted using melee weapon? It works fine for ranged damage. I was fiddling around with multiple placement combinations (both at the top of the code and at the very bottom etc) of set_trigger_result with various different values for at least 3 hours now yet without success. I can even put a solid 500 damage as a param and only ranged weapon damage gets overridden. Am I missing something or is there some black magics involved in that specific trigger that I still haven't figured out for years (since I didn't need to override melee damage earlier) or could that be an engine bug of some sort?

I won't show you the actual script since it's pointless (and I would rather avoid it) because I even tried removing everything from it and leaving only the basic stuff (params) + set_trigger_result to make sure it wasn't caused by my poorly written code. Also - I'm using all of the ti_on_gent_hit trigger params, agent_set_damage_modifier isn't a viable workaround option in that specific case I need to override the melee damage for.

Thank you in advance.
 
Solution
[...]

I even tried removing everything from it and leaving only the basic stuff (params) + set_trigger_result to make sure it wasn't caused by my poorly written code.

[...]

As I mentioned earlier, there is no point in posting the actual code and I would rather not do that.
It doesn't even work for such a simple test:

Python:
damage_test = (
    ti_on_agent_hit, 0, 0, [],
    [
    (store_trigger_param_1, ":agent"),
    (store_trigger_param_2, ":dealer_agent"),
    (store_trigger_param_3, ":damage"),
    (assign, ":reg0_backup", reg0),
   
    (assign, ":item_id", reg0),
   
    (neg|agent_is_non_player, ":dealer_agent"),
   
    (try_begin),
        (agent_is_human, ":agent"),
        (neq, ":item_id", -1)...
check if you dont have multiple triggers of the same type (agent_hit), otherwise you may need to do this to preserve the damage

Code:
  (ti_on_agent_hit, 0, 0, [],
  [
    (assign, ":reg0_backup", reg0), #    
 
    .... # code here
 
    (assign, reg0, ":reg0_backup"), # restores the value
  ]),

{reg0} can be overriden by other operations and it will break the new trigger in the chain. You need to preserve it if you are not messing with {reg0} or make sure to update it at the end (so the next trigger starts with the correct value).

If that is not your issue then add debug messages to test your code.
 
Last edited:
Upvote 0
check if you dont have multiple triggers of the same type (agent_hit), otherwise you may need to do this to preserve the damage

Code:
  (ti_on_agent_hit, 0, 0, [],
  [
    (assign, ":reg0_backup", reg0), #
    (assign, ":inflicted_damage", reg0),

    .... # code here

    (assign, reg0, ":reg0_backup"), # restores the value
  ]),

{reg0} can be overriden by other operations and it will break the new trigger in the chain. You need to preserve it if you are not messing with {reg0} or make sure to update it at the end (so the next trigger starts with the correct value).

If that is not your issue then add debug messages to test your code.

I understand your point with reg0 however why would I replace inflicted damage with reg0? It's supposed to be weapon_item_id, not damage inflicted. I'm using ":reg0_backup" for weapon_item_id as it is done in Viking Conquest triggers. Everything I need for ti_on_agent_hit is in one single trigger so it's impossible that other triggers interfere with it after I correctly set up reg0 backup system. Regarding debug messages - yeah, I use them and all of my tests are passed however the melee damage still remains the same.
 
Upvote 0
would I replace inflicted damage with reg0?
lol that was a bad ctrl+c ctrl+v from the trigger, you can ignore that line. As long you keep the chain with the backups you are safe. And if you dont have a chain, as in, just one trigger, you dont need that at all.

Regarding debug messages - yeah, I use them and all of my tests are passed however the melee damage still remains the same.
yeah at this point you need to show code and the result of your tests (logs), as we cant see what you did until you do that.
 
Upvote 0
[...]

I even tried removing everything from it and leaving only the basic stuff (params) + set_trigger_result to make sure it wasn't caused by my poorly written code.

[...]

As I mentioned earlier, there is no point in posting the actual code and I would rather not do that.
It doesn't even work for such a simple test:

Python:
damage_test = (
    ti_on_agent_hit, 0, 0, [],
    [
    (store_trigger_param_1, ":agent"),
    (store_trigger_param_2, ":dealer_agent"),
    (store_trigger_param_3, ":damage"),
    (assign, ":reg0_backup", reg0),
   
    (assign, ":item_id", reg0),
   
    (neg|agent_is_non_player, ":dealer_agent"),
   
    (try_begin),
        (agent_is_human, ":agent"),
        (neq, ":item_id", -1),
       
        (item_get_type, ":typ", ":item_id"),
        (eq, ":typ", itp_type_one_handed_wpn),
        (set_trigger_result, -1),
        (ge, ":damage", 1),
       
        (set_trigger_result, 5),
        (display_message, "@Your melee attack should cause only 5 damage."),
    (try_end),
   
    (assign, reg0, ":reg0_backup"),
   ])

The message appears yet the damage isn't changed to 5 as it should.


EDIT:

PROBLEM SOLVED.

So it turned out that Formations & AI has this #kludge formation superiority ti_on_agent_hit trigger which I was not aware of and it was overriding almost every type of the damage except the ranged one :facepalm:

After commenting out that code (which I'll merge later) everything works like a charm. Therefore, I'm terribly sorry for the trouble I have caused and time of other people that I wasted.

So yeah guys, remember to always check Formations & AI for 'interesting things' if you installed it (especially if you use Modmerger ver).
 
Last edited:
Upvote 0
Solution
if you cant figure out where the bug is you can try a workaround

Code:
          (store_agent_hit_points, ":agent_hp", ":inflicted_agent_id", 1),
          (val_sub, ":agent_hp", DAMAGE_HERE),
          (agent_set_hit_points, ":inflicted_agent_id", ":agent_hp", 1),
 
Upvote 0
Back
Top Bottom