• 🏆 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!

[Solved] Receive ally gold

Status
Not open for further replies.
Level 10
Joined
Jun 20, 2017
Messages
337
Basically, I'm trying to get my allied gold.
For example: I built a tower in a round, then when a round starts, it becomes a unit so that it can move and kill objects, but I gave the owner to my ally(I mean, it's actually my unit, and I don't want to control the unit when a level starts.), unless the round ends. The problem is that I want to get its gold when it kills things!
I know you can do this with Unit Indexer, as Uncle told me, but I have not worked with this system before. So I have no clue! but I guess it can be done this way!
Do I have to create another variable and set a gold reward for each creep?

  • Setup Creep Types
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet UnitType_BonusLevel = Pit Lord [Level 31]
      • -------- --------
      • -------- Level 1 --------
      • Set VariableSet UnitTypes_Creep[1] = Crab [Level 1]
      • Set VariableSet Strings_CreepName[1] = Crab
      • Set VariableSet Integers_CreepCount[1] = 36
      • Set VariableSet Strings_CreepValueRecommend[1] = 250
      • Set VariableSet Integers_LevelCompletedGold[1] = 11
      • -------- --------
      • -------- Level 2 --------
      • Set VariableSet UnitTypes_Creep[2] = Murloc [Level 2]
      • Set VariableSet Strings_CreepName[2] = Murloc
      • Set VariableSet Integers_CreepCount[2] = 45
      • Set VariableSet Strings_CreepValueRecommend[2] = 350
      • Set VariableSet Integers_LevelCompletedGold[2] = 12
      • -------- --------
      • -------- Level 3 --------
      • Set VariableSet UnitTypes_Creep[3] = Scorpion [Level 3]
      • Set VariableSet Strings_CreepName[3] = Scorpion
      • Set VariableSet Integers_CreepCount[3] = 40
      • Set VariableSet Strings_CreepValueRecommend[3] = 500
      • Set VariableSet Integers_LevelCompletedGold[3] = 13
  • Level Begins
    • Events
      • Time - Timer_LevelStart expires
    • Conditions
    • Actions
      • Player Group - Pick every player in PlayerGroup_WestTeam and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) controller) Equal to User
              • ((Picked player) slot status) Equal to Is playing
            • Then - Actions
              • Unit - Create Integers_CreepCount[(Integer_CurrentLevel + 1)] UnitTypes_Creep[(Integer_CurrentLevel + 1)] for Player 22 (Snow) at Points_CreepSpawn[(Player number of (Picked player))] facing Default building facing degrees
              • Unit Group - Add (Last created unit) to UnitGroup_Creep
              • Set VariableSet UDexUnits[(Player number of (Owner of (Last created unit)))] = (Last created unit)
            • Else - Actions
      • Player Group - Pick every player in PlayerGroup_EastTeam and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) controller) Equal to User
              • ((Picked player) slot status) Equal to Is playing
            • Then - Actions
              • Unit - Create Integers_CreepCount[(Integer_CurrentLevel + 1)] UnitTypes_Creep[(Integer_CurrentLevel + 1)] for Player 21 (Coal) at Points_CreepSpawn[(Player number of (Picked player))] facing Default building facing degrees
              • Unit Group - Add (Last created unit) to UnitGroup_Creep
              • Set VariableSet UDexUnits[(Player number of (Owner of (Last created unit)))] = (Last created unit)
            • Else - Actions
  • Tower to Fighter
    • Events
    • Conditions
    • Actions
      • Trigger - Run Fighters Value <gen> (ignoring conditions)
      • -------- --------
      • Unit Group - Pick every unit in UnitGroup_Towers and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) construction progress to 100%
          • Unit - Set (Picked unit) upgrade progress to 100%
          • -------- --------
          • Unit - Hide (Picked unit)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Picked unit)) is an ally of Player 19 (Mint).) Equal to True
            • Then - Actions
              • Set VariableSet Player_Temp = Player 19 (Mint)
            • Else - Actions
              • Set VariableSet Player_Temp = Player 20 (Lavender)
          • -------- --------
          • For each (Integer A) from 1 to Integer_Towers, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to UnitTypes_Towers[(Integer A)]
                • Then - Actions
                  • Set VariableSet Point_Temp = (Position of (Picked unit))
                  • Unit - Create 1 UnitTypes_TowersUnit[(Integer A)] for Player_Temp at Point_Temp facing Default building facing degrees
                  • Unit - Change color of (Last created unit) to (Color of (Owner of (Picked unit)))
                  • Unit - Reset ability cooldowns for (Last created unit).
                  • Unit Group - Add (Last created unit) to UnitGroup_Fighter
                  • Custom script: call RemoveLocation(udg_Point_Temp)
                • Else - Actions
      • Custom script: call DestroyGroup(udg_UnitGroup_Towers)
  • Creep Dies
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • ((Dying unit) is in UnitGroup_Creep.) Equal to True
              • ((Dying unit) is in UnitGroup_Summon.) Equal to True
        • Then - Actions
          • Player - Add (Custom value of UDexUnits[(Player number of (Owner of (Dying unit)))]) to (Owner of UDexUnits[(Player number of (Owner of (Killing unit)))]).Current gold
          • -------- --------
          • Floating Text - Create floating text that reads (String((Custom value of (Dying unit)))) above (Dying unit) with Z offset 0.00, using font size 10.00, color (0.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
          • Floating Text - Change the lifespan of (Last created floating text) to 1.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,632
You should read up on how Bribe's Unit Indexer works because you're not using it correctly. You never have to assign any of the UDex variables yourself, the system uses these variables behind the scenes. A brief summary of how Unit Indexing works: The Unit Indexer assigns a unique Custom Value to each of your units when the game starts and whenever a new unit is created. This means that no two units will ever share the same Custom Value. Think of it like numbering your units. Why is this useful? It's useful because it allows us to use a unit's Custom Value as a unique [Index] in any of our Variable arrays. Remember, no two units share the same Custom Value so they'll always use different [Indexes] in the Array.

For example, let's keep track of each building's original owner using a Player array:
  • Events
    • Unit - A unit finishes construction
  • Conditions
  • Actions
    • Set VariableSet OriginalOwner[Custom value of (Constructed structure)] = (Owner of (Constructed structure))

Now whenever a Creep Dies we can easily get the original Owner of our (Killing unit) by referencing the OriginalOwner variable:
  • Creep Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • Level of GivesBounty for (Dying unit) Equal to 1
    • Actions
      • Player - Add X to OriginalOwner[Custom value of (Killing unit)] Current gold
GivesBounty is a hidden passive ability that you would Add to units that are meant to give bounty when killed (Creeps/Summons). This is A LOT more efficient than checking if a Unit is inside of a Unit Group. I find this to be a good way of creating your own Classifications and marking units.

Regarding the Gold Bounty stuff, there's easier ways of getting a unit's bounty, remember that we have access to many of a unit's Integer fields:
  • Actions
    • Player - Add (Unit: (Dying unit)'s Integer Field: Gold Bounty Awarded - Base ('ubba')) to OriginalOwner[Custom value of (Killing unit)] Current gold
So in the Object Editor you can set the creep's Gold Bounty Awarded - Base to whatever value you want it to be worth.

If for whatever reason you can't or don't want to use that method, Unit Indexing is a valid option. Although, I'd recommend a Hashtable method over it.


For the sake of knowledge here's how you would do this using the Unit Indexer - I'm NOT recommending that you do this!
When your Creeps enter the map you would assign them their Gold Bounty using the Unit Indexing method:
  • Events
    • Unit - A unit enters playable map area
  • Conditions
    • Level of GivesBounty for (Triggering unit) Equal to 1
  • Actions
    • Set VariableSet Creep = (Triggering unit)
    • For each (CreepLoop) from 1 to CreepTotal, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of Creep) Equal to UnitTypes_Creep[CreepLoop]
          • Then - Actions
            • Set VariableSet CreepBounty[Custom value of Creep] = CreepBountyRewarded[CreepLoop]
          • Else - Actions
CreepBountyRewarded[] would be Set to how much Gold a creep is worth in your Setup Creep Types trigger. CreepTotal would be Set to how many Creeps you have in the Setup Creep Types trigger. CreepBounty[] is an Integer array that tracks how much Gold a specific creep is worth and takes advantage of the Unit Indexing method. CreepLoop is an Integer that we use instead of IntegerA/IntegerB, it's wise to use your own variables in For Loops.

Now you can get how much bounty a (Dying) creep is worth by referencing it's CreepBounty:
  • Actions
    • Player - Add CreepBounty[Custom value of (Dying unit)] to OriginalOwner[Custom value of (Killing unit)] Current gold
 
Last edited:
Level 6
Joined
Jul 12, 2021
Messages
95
For example: I built a tower in a round, then when a round starts, it becomes a unit so that it can move and kill objects, but I gave the owner to my ally...

There's a very simple way to do this, but it takes some work. I'll describe it, though I think there must be a more efficient way.

Here is your trigger Tower to Fighter:

  • Tower to Fighter
    • Events
    • Conditions
    • Actions
      • Trigger - Run Fighters Value <gen> (ignoring conditions)
      • -------- --------
      • Unit Group - Pick every unit in UnitGroup_Towers and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) construction progress to 100%
          • Unit - Set (Picked unit) upgrade progress to 100%
          • -------- --------
          • Unit - Hide (Picked unit)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Picked unit)) is an ally of Player 19 (Mint).) Equal to True
            • Then - Actions
              • Set VariableSet Player_Temp = Player 19 (Mint)
            • Else - Actions
              • Set VariableSet Player_Temp = Player 20 (Lavender)
          • -------- --------
          • For each (Integer A) from 1 to Integer_Towers, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to UnitTypes_Towers[(Integer A)]
                • Then - Actions
                  • Set VariableSet Point_Temp = (Position of (Picked unit))
                  • Unit - Create 1 UnitTypes_TowersUnit[(Integer A)] for Player_Temp at Point_Temp facing Default building facing degrees
                  • Unit - Change color of (Last created unit) to (Color of (Owner of (Picked unit)))
                  • Unit - Reset ability cooldowns for (Last created unit).
                  • Unit Group - Add (Last created unit) to UnitGroup_Fighter
                  • Custom script: call RemoveLocation(udg_Point_Temp)
                • Else - Actions
      • Custom script: call DestroyGroup(udg_UnitGroup_Towers)

We will modify the trigger so that it picks every unit that is a structure that belongs to a specific player, instead of picking every unit in the map that is a structure. You will have to do one trigger per player.

  • Tower to Fighter Player 1
    • Events
    • Conditions
    • Actions
      • Trigger - Run Fighters Value <gen> (ignoring conditions)
      • -------- --------
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red) matching (((Picked unit) is A structure) Equal to True).) and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) construction progress to 100%
          • Unit - Set (Picked unit) upgrade progress to 100%
          • -------- --------
          • Unit - Hide (Picked unit)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Picked unit)) is an ally of Player 19 (Mint).) Equal to True
            • Then - Actions
              • Set VariableSet Player_Temp = Player 19 (Mint)
            • Else - Actions
              • Set VariableSet Player_Temp = Player 20 (Lavender)
          • -------- --------
          • For each (Integer A) from 1 to Integer_Towers, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to UnitTypes_Towers[(Integer A)]
                • Then - Actions
                  • Set VariableSet Point_Temp = (Position of (Picked unit))
                  • Unit - Create 1 UnitTypes_TowersUnit[(Integer A)] for Player_Temp at Point_Temp facing Default building facing degrees
                  • Unit - Change color of (Last created unit) to (Color of (Owner of (Picked unit)))
                  • Set VariableSet OriginalOwner[(Custom value of (Last created unit))] = Player 1 (Red)
                  • Unit - Reset ability cooldowns for (Last created unit).
                  • Unit Group - Add (Last created unit) to UnitGroup_Fighter
                  • Custom script: call RemoveLocation(udg_Point_Temp)
                • Else - Actions
      • Custom script: call DestroyGroup(udg_UnitGroup_Towers)
UnitGroup_Towers is no longer used.

Now that we have linked the new unit with the original owner we award the gold:
  • GoldBounty
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Killing unit)) Equal to OriginalOwner[(Custom value of (Killing unit))]
    • Actions
      • Set VariableSet GoldBounty = ((Unit: (Dying unit)'s Integer Field: Gold Bounty Awarded - Base ('ubba')) + ((Unit: (Dying unit)'s Integer Field: Gold Bounty Awarded - Number of Dice ('ubdi')) x (Unit: (Dying unit)'s Integer Field: Gold Bounty Awarded - Sides per Die ('ubsi'))))
      • Player - Add GoldBounty to OriginalOwner[(Custom value of (Killing unit))].Current gold
      • Floating Text - Create floating text that reads (+ + (String(GoldBounty))) at (Position of (Dying unit)) with Z offset 0.00, using font size 10.00, color (((255.00 / 255.00) x 100.00)%, ((219.00 / 255.00) x 100.00)%, 0.00%), and 0.00% transparency
      • Set VariableSet FloatingTextGoldBounty[(Custom value of (Dying unit))] = (Last created floating text)
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
      • Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
      • For each (Integer A) from 1 to 24, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Killing unit)) Equal to (Player((Integer A)))
            • Then - Actions
              • Floating Text - Hide (Last created floating text) for (All players matching ((Owner of (Killing unit)) Not equal to (Player((Integer A)))).)
            • Else - Actions
      • Wait 5.00 seconds
      • Floating Text - Destroy FloatingTextGoldBounty[(Custom value of (Dying unit))]

You can also award the gold without using the unit's integer field, like Uncle said:
  • Player - Add X to OriginalOwner[Custom value of (Killing unit)] Current gold

Question:
What do you do with the group UnitGroup_Fighter?


2022/03/01 EDIT: I found a method that requires much less work:
We modify the trigger Tower to Fighter. This trigger will correctly assign every new unit to its respective player.
  • Tower to Fighter for all players
    • Events
    • Conditions
    • Actions
      • Unit Group - Pick every unit in UnitGroup_Towers and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) construction progress to 100%
          • Unit - Set (Picked unit) upgrade progress to 100%
          • -------- --------
          • Unit - Hide (Picked unit)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Picked unit)) is an ally of Player 19 (Mint).) Equal to True
            • Then - Actions
              • Set VariableSet Player_Temp = Player 19 (Mint)
            • Else - Actions
              • Set VariableSet Player_Temp = Player 20 (Lavender)
          • -------- --------
          • For each (Integer A) from 1 to Integer_Towers, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to UnitTypes_Towers[(Integer A)]
                • Then - Actions
                  • Set VariableSet Point_Temp = (Position of (Picked unit))
                  • Unit - Create 1 UnitTypes_TowersUnit[(Integer A)] for Player_Temp at Point_Temp facing Default building facing degrees
                  • For each (Integer A) from 1 to 24, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Player number of (Owner of (Picked unit))) Equal to (Integer A)
                        • Then - Actions
                          • Set VariableSet OriginalOwner[(Custom value of (Last created unit))] = (Player((Integer A)))
                        • Else - Actions
                  • Unit - Change color of (Last created unit) to (Color of (Owner of (Picked unit)))
                  • Unit - Reset ability cooldowns for (Last created unit).
                  • Unit Group - Add (Last created unit) to UnitGroup_Fighter
                  • Custom script: call RemoveLocation(udg_Point_Temp)
                  • Custom script: call DestroyGroup(GetLastCreatedGroup())
                • Else - Actions
      • Custom script: call DestroyGroup(udg_UnitGroup_Towers)

Map attached with triggers:
Tower to Figther for all players
Gold Bounty trigger.



2022/03/02 EDIT: I modified the button "Triggers".
Changes done: It is not necessary to use the variable "Players" so I deleted that part. Trigger "Tower to Fighter for all players" updated.
Also I'm updating the attached map so that it doesn't use that variable.



2022/03/03 EDIT: Realized that floating texts and units groups were leaking. Added functions to prevent this. This post and the attached map were updated.
 

Attachments

  • HiveworkshopBountyFromUnitsThatDontBelongYouD.w3m
    19.3 KB · Views: 10
Last edited:
Level 10
Joined
Jun 20, 2017
Messages
337
Sorry for the late reply,
GivesBounty is a hidden passive ability
Question; Which passive ability is good?
I find this to be a good way of creating your own Classifications and marking units.
I did not know that, thank you.
What do you do with the group UnitGroup_Fighter?
I have some special rounds and an ability to use, so I needed that group for those thing!

Thank you guys so much, once again.
 
Last edited:
Status
Not open for further replies.
Top