• 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.

[Solved] Income problems

Status
Not open for further replies.
Level 6
Joined
Sep 24, 2015
Messages
174
I wanna do a trigger like that : all the time when one specific unit owned by neutral hostile dies and a player got another spécific unit, then the player gets 3 gold otherwhise give 1 gold to the owner of this specific unit.

I did like this way, but i'm in struggle...a little help would be appreciate :)

  • Small gold supplier income
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Gold supplier - small (1/3 gold)
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Boucle - Actions
          • Set UnitSlay = (Matching unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in (Units in (Playable map area) owned by (Owner of (Matching unit)))) Greater than 0
            • Then - Actions
              • Player - Set (Owner of (Matching unit)) Current gold to 3
            • Else - Actions
 
Last edited:
Level 6
Joined
Sep 24, 2015
Messages
174
yes gimli i just saw myself what you noticed ahha

Hmm...when the gold supplier dies, if players 1 to 10 on map have got 1 slayer then give 3 gold to the owner of the slayer(it's the unit) otherwhise give 1 gold

Slayer is the unit owned by players 1 to 10

gold supplier is unit owned by hostile player
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
  • Gold
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold Supplier
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in (Units owned by (Player((Integer A))) of type Slayer)) Greater than 0
            • Then - Actions
              • Player - Add 3 to (Player((Integer A))) Current gold
            • Else - Actions
              • Player - Add 1 to (Player((Integer A))) Current gold
Is this what you want to accomplish?
In this state it leaks and is bad design (very inefficient)
 
Level 6
Joined
Sep 24, 2015
Messages
174
yes it's kinda like that...
Conditon is a hashtable? I don't get it

How is it leaking? i didn't create groupes or else ...i wonder
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
  • Trigger
    • Events
      • Unit - a unit dies
    • Conditions
      • (Unit-type of (Triggering unit)) equal to UNIT
    • Actions
      • For each (Integer int) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set group = (Units owned by (Player(int)) of type Slayer)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (group is empty) equal to True
            • Then - Actions
              • Player - Add 1 to (Player(int)) Current gold
            • Else - Actions
              • Player - Add 3 to (Player(int)) Current gold
              • Unit Group - Remove all units from group
without leaks
 
Level 6
Joined
Sep 24, 2015
Messages
174
for each integer A or for each integer int?

Edit: Ah so the integer int is a variable if i'm correct i have to set a player groupe into an integer?
 
Level 13
Joined
May 10, 2009
Messages
868
I guess using set bj_wantDestroyGroup = true on top of that if-statement would solve the leak problem too, though that's an unusual way to do so.

  • Actions
    • For each (Integer MyIntegerVariable) from 1 to 10, do (Actions)
      • Loop - Actions
        • Custom script: set bj_wantDestroyGroup = true
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Number of units in (Units owned by (Player(MyIntegerVariable)) of type Footman)) Greater than 0
          • Then - Actions
            • -------- ... --------
          • Else - Actions
 
Level 13
Joined
May 10, 2009
Messages
868
isnt it better to add/remove units to one group instead of creating/destroying it in a loop?

Yes, but this function
  • (Units owned by (PLAYER of type UNIT-TYPE)
creates a new unit group handle. So, you have to destroy it later.

JASS:
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 16
Joined
Mar 25, 2016
Messages
1,327
The best thing would be to have an integer array, that stores the number of Slayers for each player and increase/decrease it when they are created/die.
With this method you would no longer have to create groups at runtime.

The GUI function (group is empty) is also rather expensive and not much better than counting the units, because both iterate through the while group.
 
Level 6
Joined
Sep 24, 2015
Messages
174
So I did (i guess) like you guys showed but it seems still not working at all...did i mess lot of things?

  • Small gold supplier income
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold supplier - small (1/3 gold)
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Set UnitSlay = (Units owned by OwnerSlay of type Slayer)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Units owned by OwnerSlay) is empty) Equal to TRUE
            • Then - Actions
              • Player - Add 1 to OwnerSlay Current gold
            • Else - Actions
              • Player - Add 3 to OwnerSlay Current gold
Unite of type = slayer


and there is the variable i did :

OwnerSlay = player
 
Level 6
Joined
Sep 24, 2015
Messages
174
is it like this? i converted player index to number of players

  • Small gold supplier income
    • Event
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold supplier - small (1/3 gold)
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Set UnitSlay = (Units owned by (Player((Number of players))) of type Slayer)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Units owned by (Player((Player number of (Triggering player))))) is empty) Equal TRUE
            • Then - Actions
              • Player - Add 1 to OwnerSlay Current gold
            • Else - Actions
              • Player - Add 3 to OwnerSlay Current gold
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
Now, replace
"Number of players" with "(Integer A)"
"((Units owned by (Player((Player number of (Triggering player))))) is empty) Equal TRUE" with "UnitSlay is empty Equal TRUE"
and
Player - Add 1 to Player((Integer(A)) Current gold
Player - Add 3 to Player((Integer(A)) Current gold
 
Level 6
Joined
Sep 24, 2015
Messages
174
Here's the solution :)

  • Small gold supplier income
    • Event
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold supplier - small (1/3 gold)
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Set UnitSlay = (Units owned by (Player((Integer A))) of type Slayer)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (UnitSlay is empty) Equal to TRUE
            • Then - Actions
              • Player - Add 1 to (Player((Integer A))) Current gold
            • Else - Actions
              • Player - Add 3 to (Player((Integer A))) Current gold
Thank you Guys for the help :)
 
Status
Not open for further replies.
Top