• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Ability That Gives Gold Every So Often

Status
Not open for further replies.
Level 3
Joined
Jun 22, 2016
Messages
31
I need a trigger that allows a player to gain gold every 10 seconds based on that player having a certain unit with an ability (it can stack as well), and i also want a trigger that increases the damage of said unit based on the current gold of said player but i can do that myself.
 
  • Some fancy ass trigger
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red) of type Mortar Team) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Banish for (Picked unit)) Equal to 1
            • Then - Actions
              • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) + 1337)
            • Else - Actions

EDIT:

Here you have a leakless one
  • Some fancy ass trigger
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by Player 1 (Red) of type Your Unit)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Your Ability for (Picked unit)) Equal to 1
            • Then - Actions
              • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) + 1337)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)
 
Last edited:
Level 8
Joined
May 21, 2019
Messages
435
EDIT:

Here you have a leakless one
  • Some fancy ass trigger
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by Player 1 (Red) of type Your Unit)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Your Ability for (Picked unit)) Equal to 1
            • Then - Actions
              • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) + 1337)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)

This leaks a reference to the group generated with "of type" because that thing apparently leaks every time that it is used, as the pointer isn't nulled. To be fully leakless, you'd have to use "units matching condition, type of unit is your unit" instead.

EDIT: The above is WRONG. See instead the solution suggested by Dr Super Good for a leakless and more optimised implementation.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,290
This leaks a reference to the group generated with "of type" because that thing apparently leaks every time that it is used, as the pointer isn't nulled. To be fully leakless, you'd have to use "units matching condition, type of unit is your unit" instead.
Or use Lua. Since Lua does not suffer from that bug.

Ideally one should track which units have the ability rather than picking all units belonging to a player on the entire map.

For damage one can try the new functions to modify attack damage. Otherwise one must use a bonus modifier system which gives the unit a combination of different attack raising abilities to increase attack damage.
 
Level 8
Joined
May 21, 2019
Messages
435
Or use Lua. Since Lua does not suffer from that bug.
"Have you heard the gospel of our lord and savior, LUA?"
- Dr Super Good, every thread.

It may be a bit above the paygrade of this thread though. Personally, I don't wanna swap to LUA before the community builds up a better support infrastructure, and I think that may be even moreso the case for the OP of this thread, going by the relatively low level of complexity for this trigger.
I think the argument that the existing LUA support is directly transferable to WC3 Map Making assumes a relatively high level of technical competency and willingness to remake and adapt existing solutions.

Ideally one should track which units have the ability rather than picking all units belonging to a player on the entire map.
Yeah, good point, that would be lighter to execute in general.
I was just raising awareness though, not really commenting on the trigger as a whole.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
This leaks a reference to the group generated with "of type" because that thing apparently leaks every time that it is used, as the pointer isn't nulled. To be fully leakless, you'd have to use "units matching condition, type of unit is your unit" instead.
They all have an unfixable locally declared handle leak-on-return. Using one over any other changes nothing.
JASS:
function GetUnitsInRectMatching takes rect r, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, r, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsOfPlayerMatching takes player whichPlayer, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsOfPlayerAndTypeId takes player whichPlayer, integer unitid returns group
    local group g = CreateGroup()
    set bj_groupEnumTypeId = unitid
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterGetUnitsOfPlayerAndTypeId)
    return g
endfunction
 
Level 8
Joined
May 21, 2019
Messages
435
They all have an unfixable locally declared handle leak-on-return. Using one over any other changes nothing.
JASS:
function GetUnitsInRectMatching takes rect r, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, r, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsOfPlayerMatching takes player whichPlayer, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsOfPlayerAndTypeId takes player whichPlayer, integer unitid returns group
    local group g = CreateGroup()
    set bj_groupEnumTypeId = unitid
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterGetUnitsOfPlayerAndTypeId)
    return g
endfunction
Oh, I wasn't aware that this affected the condition check as well.
Thanks for clarifying. I will edit my response to prevent further confusion.
 
Level 3
Joined
Jun 22, 2016
Messages
31
You insult me good sir, the reason i asked for someone to make the trigger for me was because i was being an idiot and not realizing what i needed to make the trigger work. Also i did say that i already knew how to do the damage based on gold trigger which is really simple.
 
Level 8
Joined
May 21, 2019
Messages
435
You insult me good sir, the reason i asked for someone to make the trigger for me was because i was being an idiot and not realizing what i needed to make the trigger work. Also i did say that i already knew how to do the damage based on gold trigger which is really simple.
All I said was that I assume that you aren't exaclty primed to jump into full on LUA scripting (which is pretty hard) based on the fact that you didn't know how to count units (which is pretty simple).

Was I wrong in that assumption?
 
Status
Not open for further replies.
Top