Announcement

Collapse

Forum Rules

  • No flaming or derogatory remarks, directly or through insinuation.
  • No discussion, sharing or referencing illegal software such as hacks, keygen, cracks and pirated software.
  • No offensive contents, including but not limited to, racism, gore or pornography.
  • No excessive spam/meme, i.e. copious one liners in a short period of time, typing with all caps or posting meme responses (text/image).
  • No trolling, including but not limited to, flame incitation, user provocation or false information distribution.
  • No link spamming or signature advertisements for content not specific to Dota 2.
  • No Dota 2 key requests, sell, trade etc.
  • You may not create multiple accounts for any purpose, including ban evasion, unless expressly permitted by a moderator.

  • Please search before posting. One thread per issue. Do not create another thread if there is an existing one already.
  • Before posting anything, make sure you check out all sticky threads (e.g., this). Do not create new threads about closed ones.
  • It is extremely important that you post in correct forum section.

  • Balance discussion only in Misc.
  • All art related (such as hero model) feedbacks go to Art Feedback Forum.
  • All matchmaking feedback should go here: Matchmaking Feedback
  • All report/low priority issues should go here: Commend/Report/Ban Feedback
  • No specific workshop item feedback. These should go to workshop page of that item.
  • When posting in non-bugs section (such as this), use [Bugs], [Discussion] or [Suggestion] prefix in your thread name.



In case you object some action by a moderator, please contact him directly through PM and explain your concerns politely. If you are still unable to resolve the issue, contact an administrator. Do not drag these issues in public.



All rules are meant to augment common sense, please use them when not conflicted with aforementioned policies.
See more
See less

Lua modifier property functions triggering twice?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lua modifier property functions triggering twice?

    In my code, I have a lua modifier that calls a function during OnAttack. But the modifier triggers twice every time the unit attacks. I think this is because the code is run on both the client and the server, but my function is surrounded by a IsServer() call just like the example on the wiki. The IsServer() call also returns true for both times, which we should expect from the results. I am calling the code from the Dota 2 Reborn Beta Tools with no other players, but I still do not think that this should happen, because that means the game logic will happen twice whenever the event happens on the host. Unless I am doing something wrong, in which case, I would greatly appreciate it if someone shows me how to do it properly.

  • #2
    OnAttack will trigger on both the unit attacks and attacked. when the unit attacks something else. if you put OnTakeDamage in your modifier , when the unit attack something else, function will be called, boththe attacker and the target are the unit has the modifier, maybe this is another way the bug show up.

    Comment


    • #3
      I have done some more testing and I think dota2jili is right. It looks like whenever a modifier property function triggers, it triggers for each unit with the modifier. So if I have 10 units with the modifier and one of them attacks another, the function triggers 10 times, one for each modifier, even if the unit with the modifier is not attacking or being attacked. This seems very much like a bug.
      Last edited by ersafd; 07-16-2015, 10:03 PM.

      Comment


      • #4
        It's not a bug, you need add some conditions(like in Sven`s Great Cleave example on this page)

        Comment


        • #5
          I still think that is a very unintuitive behavior to have. In the datadriven abilities, the modifier events only triggered for the unit that caused the event. And most of the time, you will not care about any other units besides the triggered unit and any other units in the params, so why make it trigger for each one? It does not make any sense.

          As for me, I have a single function that I would like to reuse between events. However, it is hard because each of the events have different keys for the unit which caused the event. Sometimes it is params.attacker, sometimes it is params.unit, etc. May I at least suggest that each event have a consistent params.caller or params.unit key for each event which refers to the triggering unit?

          Comment


          • #6
            In datadriven modifiers you havent another way, because you cant check any conditions.
            triggering unit - who this? attacker? or attacked? or modifier parent?

            Comment


            • #7
              The triggering unit is the parent of the modifier that triggers the event. It can be the attacker or attacked depending on the event. But my point is that we don't care about other units with the modifier 99.9% of the time, just the triggering unit and any other units related to the event (like attacker, caster, target, etc.), so the way it is currently set up does not make sense.

              In datadriven modifiers, you can check for conditions with a script if you want to, but most of the time you don't have to because it only triggers for the modifier parent. With the lua modifiers, I have to check each time if the unit/attacker/target is the modifier parent for each of my property functions, which is unnecessary since it should only trigger for the modifier parent anyways.

              Comment


              • #8
                http://dev.dota2.com/showthread.php?...=1#post1247001

                It's intended that the events trigger on every unit and not just on the unit with the modifier. Yes needing to check that the unit is the modifier parent is one extra line every time but this way you can do more complex logic if needed.

                Comment

                Working...
                X