• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Is there a better way of doing this trigger?

Status
Not open for further replies.
Level 3
Joined
May 30, 2010
Messages
35
  • Events
    • Player - Player 2 (Blue) types a chat message containing -str max as An exact match
    • Player - Player 4 (Purple) types a chat message containing -str max as An exact match
    • Player - Player 6 (Orange) types a chat message containing -str max as An exact match
    • Player - Player 8 (Pink) types a chat message containing -str max as An exact match
    • Player - Player 10 (Light Blue) types a chat message containing -str max as An exact match
  • Conditions
    • ((Triggering player) Current gold) Greater than 100
  • Actions
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units owned by (Triggering player)) and do (Actions)
      • Loop - Actions
        • Hero - Modify Strength of (Picked unit): Add 1
    • Player - Add -100 to (Triggering player) Current gold
    • Trigger - Run (This trigger) (checking conditions)
Also I'm really not interested in doing jass
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Pharaoh_ said:
  • For each (IntegerA) from 1 to (Current gold of (Triggering Player)), do (Actions)
  • Loop - Actions
  • Hero - Modify Strength of (Picked unit): Add ((IntegerA)/100)

Okay, so let's say the player has 200 gold. This trigger will add far more than +2 strength. There would also be no reason to start it at 1, since anything from 0-99/100 (integer division) is just 0. Tisk tisk.

In fact there is no need for a loop at all. Just calculate how much strength needs to be added based on the current gold amount (integer division by 100) and then deduct however much strength was added multiplied by 100. This should leave the player with less than 100 gold, and a couple of bonus strength points. Not to mention you leak a unit-group. Let me demonstrate:

  • Actions
    • Set BonusStrength = (((Triggering player) Current gold) / 100)
    • Set BonusGroup = (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))
    • Unit Group - Pick every unit in BonusGroup and do (Actions)
      • Loop - Actions
        • Hero - Modify Strength of (Picked unit): Add BonusStrength
    • Player - Set (Triggering player) Current gold to (((Triggering player) Current gold) - (BonusStrength x 100))
    • Custom script: call DestroyGroup(udg_BonusGroup)
 
Level 3
Joined
May 30, 2010
Messages
35
Okay, so let's say the player has 200 gold. This trigger will add far more than +2 strength. There would also be no reason to start it at 1, since anything from 0-99/100 (integer division) is just 0. Tisk tisk.

In fact there is no need for a loop at all. Just calculate how much strength needs to be added based on the current gold amount (integer division by 100) and then deduct however much strength was added multiplied by 100. This should leave the player with less than 100 gold, and a couple of bonus strength points. Not to mention you leak a unit-group. Let me demonstrate:

  • Actions
    • Set BonusStrength = (((Triggering player) Current gold) / 100)
    • Set BonusGroup = (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))
    • Unit Group - Pick every unit in BonusGroup and do (Actions)
      • Loop - Actions
        • Hero - Modify Strength of (Picked unit): Add BonusStrength
    • Player - Set (Triggering player) Current gold to (((Triggering player) Current gold) - (BonusStrength x 100))
    • Custom script: call DestroyGroup(udg_BonusGroup)

What is the variable type for the BonusStrength?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well the trigger I posted would instantly apply the bonuses to all heroes owned by a player and reduce the appropriate amount of gold. The variable BonusStrength is only required in an instant of a thread, so changing it in another trigger shouldn't have any harmful effects.
 
Level 13
Joined
Mar 24, 2010
Messages
950
yeah Berb has it spot on pretty much that way you did it before only allows you to use the group once because it destroys it and doesnt recreate it to be used again from your removed leaks..

Also how do you easily take that text from the GUI in W.E. and past it on here? I know the BB code part of wrapping gui code around it but how to do you get it from W.E to begin with?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You right-click on whatever it is you want to copy and select Copy as Text. This can be done on individual lines, a block of code (such a loop, or the "actions" section), and on the whole trigger itself.
 
Status
Not open for further replies.
Top