1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] periodically damage units in area

Discussion in 'Triggers & Scripts' started by mecatronic, Mar 11, 2009.

  1. mecatronic

    mecatronic

    Joined:
    Jun 20, 2005
    Messages:
    112
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I'm having problems with this new spell I'm making. It should damage surrounding units by 3% of its total hit points each second, for 20 seconds.

    Here's the first version of the spell, but it obviously doesn't work because something might overlap the "triggering unit":

    • Actions
      • Set L_POINT = (Target point of ability being cast)
      • For each (Integer A) from 1 to 20, do (Actions)
        • Loop - Actions
          • Set L_UGROUP = (Units within 500.00 of L_POINT matching (((((Matching unit) is A Hero) Equal to True) and ((Level of Invulnerable (Neutral) for (Matching unit)) Not equal to 1)) and (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True)))
          • Unit Group - Pick every unit in L_UGROUP and do (Actions)
            • Loop - Actions
              • Unit - Set life of (Matching unit) to ((Life of (Matching unit)) - ((Max life of (Matching unit)) x 0.03))


    so, how could I make this MUI? I tried a simle jass code with local variables and so, but When it reaches the unit group, i can't call the local variables from another function.

    Thanks for you help
     
  2. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,590
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    You attach the unit onto a timer via a handle system like the tables of handle vars. You then get that timer and the unit from it when it expires and run your damage actions. After the timer has fired 20 times (you also store that onto the timer) you then recycle it or destroy it.

    You could also use a list system, where you use 1 timer fireing every second to loop through all current instances of that spell being cast. When the spell is cast, you add the instance onto the end of the list. Each instance stores the unit and the number of times it has run. If it reaches 20 times, you then remove that instance and replace it with that from the top of the list and deallocate that. The list is an array. If the spell has no instances you pause the timer until it is cast again appon which you resume the timer. This method will keep 100% time accurate, and be highly efficent as well as MUI. However it will mean that the effect will run exactly at the same time for all units casting it (minor timing problem hardly noticable).

    I would advise method 2.
    Also you should add code to credit the kills made by the spell to the killing unit by not allowing you to reduce health below 0.405 and then killing the unit via dealing damage to it.