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

Need help with "Unit trading"

Level 12
Joined
Oct 28, 2019
Messages
479
HI ! I'm trying to develop a way to recruit units, I did it in the form of a "mercenary camp". But I'm open to suggestions. For example, I'll explain. On my map I only have 380 gold, and I can recruit 3 types of units, Footman (20 gold), Archer (30 gold) or Dwarf (60 gold) but there is a catch... the maximum of each unit... For example I can recruit a maximum of 16 footman, or a maximum of 6 archers or a maximum of 2 dwarves. (So the mercenary camp has only 16 Footmans to hire and the spawn is maximum). I made a trigger but it's bugging, if I click too Very fast, the units don't go to the proper positions, and I'm confused how to solve this. When the unit is hired, it goes to a specific position on map. Every unit is unique and has his own variable.

  • randomcolourWarriorBridge1
    • Events
      • Unit - A unit enters Tavern <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Warrior
    • Actions
      • Unit - Move (Entering unit) instantly to (Center of WarriorBridge1 <gen>), facing 100.00 degrees
      • Unit - Change ownership of (Entering unit) to Neutral Passive and Retain color
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on randomcolourWarriorBridge2 <gen>
      • Set VariableSet UnitWarrior5 = (Entering unit)
      • Unit Group - Add (Entering unit) to LigthGroup
  • randomcolourWarriorBridge2
    • Events
      • Unit - A unit enters Tavern <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Warrior
    • Actions
      • Unit - Move (Entering unit) instantly to (Center of WarriorBridge2 <gen>), facing 100.00 degrees
      • Unit - Change ownership of (Entering unit) to Neutral Passive and Retain color
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on randomcolourWarrior1 <gen>
      • Set VariableSet UnitWarrior6 = (Entering unit)
      • Unit Group - Add (Entering unit) to LigthGroup
 
Level 12
Joined
Oct 28, 2019
Messages
479
Its buggin man, plz help me. If I remove the wait 0.00 or 0.01 seconds the nexts triggers dont fire... help.... i need do this

  • randomcolourDwarfTown1
    • Events
      • Unit - A unit owned by Player 1 (Red) Sells a unit
    • Conditions
      • (Unit-type of (Sold unit)) Equal to Dwarf
    • Actions
      • Unit - Move (Sold unit) instantly to (Center of DwarfTown1 <gen>), facing 80.00 degrees
      • Unit - Change ownership of (Sold unit) to Neutral Passive and Retain color
      • Set VariableSet UnitDwarf1 = (Sold unit)
      • Hero - Create Satchel Charge and give it to UnitDwarf1
      • Unit Group - Add (Sold unit) to LigthGroup
      • Trigger - Turn off (This trigger)
      • Wait 0.00 seconds
      • Trigger - Turn on randomcolourDwarfTown2 <gen>
 
Level 12
Joined
May 7, 2008
Messages
334
Instead of Selling Units you could potentially Sell Items and create the desired unit immediately after purchasing the Dummy Item.

Also for defining how many units you want to limit (for example 16 Footman) you can create an Integer variable Footman_Count and then simply calculate whenever that unit is created.

Im not on the computer at the moment but I can make a small test map for you tomorrow if you'd like.

As for your current trigger, using Waits is never a good idea in multiplayer maps.
 
HI ! I'm trying to develop a way to recruit units, I did it in the form of a "mercenary camp". But I'm open to suggestions. For example, I'll explain. On my map I only have 380 gold, and I can recruit 3 types of units, Footman (20 gold), Archer (30 gold) or Dwarf (60 gold) but there is a catch... the maximum of each unit... For example I can recruit a maximum of 16 footman, or a maximum of 6 archers or a maximum of 2 dwarves. (So the mercenary camp has only 16 Footmans to hire and the spawn is maximum). I made a trigger but it's bugging, if I click too Very fast, the units don't go to the proper positions, and I'm confused how to solve this. When the unit is hired, it goes to a specific position on map. Every unit is unique and has his own variable.

  • randomcolourWarriorBridge1
    • Events
      • Unit - A unit enters Tavern <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Warrior
    • Actions
      • Unit - Move (Entering unit) instantly to (Center of WarriorBridge1 <gen>), facing 100.00 degrees
      • Unit - Change ownership of (Entering unit) to Neutral Passive and Retain color
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on randomcolourWarriorBridge2 <gen>
      • Set VariableSet UnitWarrior5 = (Entering unit)
      • Unit Group - Add (Entering unit) to LigthGroup
  • randomcolourWarriorBridge2
    • Events
      • Unit - A unit enters Tavern <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Warrior
    • Actions
      • Unit - Move (Entering unit) instantly to (Center of WarriorBridge2 <gen>), facing 100.00 degrees
      • Unit - Change ownership of (Entering unit) to Neutral Passive and Retain color
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on randomcolourWarrior1 <gen>
      • Set VariableSet UnitWarrior6 = (Entering unit)
      • Unit Group - Add (Entering unit) to LigthGroup


What is the difference between two triggers? I cannot seem to see any difference here.
 
Level 12
Joined
May 7, 2008
Messages
334
I've managed to assemble a pretty simple yet efective map for you.

The basic idea is to store Unit Types into variables as well as Gold cost so you can reference it later on.
I've also added to create units on XY point immediately rather than moving them after the buyout cause it's much more effective that way.

In the long run, it is much easier when you do it this way cause you will eventually always keep adding stuff.


Download the test map here:

If you're gonna copy the triggers, make sure you go to upper left corner in ''Preferences'' and select ''Automatically create unknown variables while pasting trigger data''.

The triggers:

  • Init Unit Cost Value
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- --------
      • -------- Set up Gold cost for each Unit-Type --------
      • -------- --------
      • -------- [1] is Footman and it costs 20 Gold --------
      • Set VariableSet Unit_Value[1] = 20
      • -------- [2] is Archer and it costs 30 Gold --------
      • Set VariableSet Unit_Value[2] = 30
      • -------- [3] is Dwarf and it costs 60 Gold --------
      • Set VariableSet Unit_Value[3] = 60
      • -------- --------
      • -------- Set the Unit-Type here --------
      • -------- --------
      • Set VariableSet Unit_Type[1] = Footman
      • Set VariableSet Unit_Type[2] = Archer
      • Set VariableSet Unit_Type[3] = Rifleman
      • -------- --------
      • -------- Set the Unit Limit here --------
      • -------- --------
      • Set VariableSet Unit_Limit[1] = 16
      • Set VariableSet Unit_Limit[2] = 6
      • Set VariableSet Unit_Limit[3] = 2
  • Purchase Units
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Selling unit) Equal to Unit Shop 0000 <gen>
    • Actions
      • -------- Set Variables --------
      • Set VariableSet Temp_Player = (Owner of (Buying unit))
      • Set VariableSet Temp_Number = (Player number of Temp_Player)
      • -------- Set Spawn Point --------
      • Set VariableSet Spawn_Point = (Position of Peasant 0004 <gen>)
      • -------- --------
      • -------- Now we can purchase Units from the Shop --------
      • -------- --------
      • -------- Footman --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to Purchase Footman
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Footman_Count[Temp_Number] Less than Unit_Limit[1]
            • Then - Actions
              • -------- Create the Desired Unit cause we haven't reached the limit yet (it is set inside Init trigger) --------
              • Unit - Create 1 Unit_Type[1] for Temp_Player at Spawn_Point facing Default building facing degrees
              • Set VariableSet Sold_Unit = (Last created unit)
              • -------- --------
              • Hero - Create Claws of Attack +15 and give it to Sold_Unit
              • Unit Group - Add Sold_Unit to Unit_Group
              • -------- Add +1 to Unit count of this Type for this Player --------
              • Set VariableSet Footman_Count[Temp_Number] = (Footman_Count[Temp_Number] + 1)
              • Game - Display to (All players) the text: (Total Footman Units: + (|cffff0000 + (String(Footman_Count[Temp_Number]))))
              • -------- --------
            • Else - Actions
              • -------- Limit Reached, refund the Gold cost --------
              • Player - Add Unit_Value[1] to Temp_Player.Current gold
              • Game - Display to (All players) the text: (You've reached the limit of + (|cffff0000 + ((String(Unit_Limit[1])) + |r units!)))
              • -------- --------
        • Else - Actions
      • -------- --------
      • -------- Archer --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to Purchase Archer
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Archer_Count[Temp_Number] Less than Unit_Limit[2]
            • Then - Actions
              • -------- Create the Desired Unit cause we haven't reached the limit yet (it is set inside Init trigger) --------
              • Unit - Create 1 Unit_Type[2] for Temp_Player at Spawn_Point facing Default building facing degrees
              • Set VariableSet Sold_Unit = (Last created unit)
              • -------- --------
              • Hero - Create Gauntlets of Ogre Strength +3 and give it to Sold_Unit
              • Unit Group - Add Sold_Unit to Unit_Group
              • -------- Add +1 to Unit count of this Type for this Player --------
              • Set VariableSet Archer_Count[Temp_Number] = (Archer_Count[Temp_Number] + 1)
              • Game - Display to (All players) the text: (Total Archer Units: + (|cffffff00 + (String(Archer_Count[Temp_Number]))))
              • -------- --------
            • Else - Actions
              • -------- Limit Reached, refund the Gold cost --------
              • Player - Add Unit_Value[2] to Temp_Player.Current gold
              • Game - Display to (All players) the text: (You've reached the limit of + (|cffffff00 + ((String(Unit_Limit[2])) + |r units!)))
        • Else - Actions
      • -------- --------
      • -------- Dwarf --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to Purchase Dwarf
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Rifleman_Count[Temp_Number] Less than Unit_Limit[3]
            • Then - Actions
              • -------- Create the Desired Unit cause we haven't reached the limit yet (it is set inside Init trigger) --------
              • Unit - Create 1 Unit_Type[3] for Temp_Player at Spawn_Point facing Default building facing degrees
              • Set VariableSet Sold_Unit = (Last created unit)
              • Hero - Create Kelen's Dagger of Escape and give it to Sold_Unit
              • Unit Group - Add Sold_Unit to Unit_Group
              • -------- Add +1 to Unit count of this Type for this Player --------
              • Set VariableSet Rifleman_Count[Temp_Number] = (Rifleman_Count[Temp_Number] + 1)
              • -------- --------
              • Game - Display to (All players) the text: (Total Rifleman Units: + (|cff00ff00 + (String(Rifleman_Count[Temp_Number]))))
            • Else - Actions
              • -------- Limit Reached, refund the Gold cost --------
              • Player - Add Unit_Value[3] to Temp_Player.Current gold
              • Game - Display to (All players) the text: (You've reached the limit of + (|cff00ff00 + ((String(Unit_Limit[3])) + |r units!)))
              • -------- --------
        • Else - Actions
      • -------- --------
      • -------- Add a fancy Teleport effect to Last Created Unit (optional) --------
      • Special Effect - Create a special effect at Spawn_Point using Abilities\Spells\Human\MassTeleport\MassTeleportCaster.mdl
      • Special Effect - Destroy (Last created special effect)
      • -------- Remove Memory Leak --------
      • Custom script: call RemoveLocation(udg_Spawn_Point)
      • -------- --------
      • -------- Run your Dwarf Town trigger here --------
      • Trigger - Run Dwarf Town Stuff <gen> (ignoring conditions)
  • Unit Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to User
    • Actions
      • -------- --------
      • Set VariableSet Temp_Player = (Owner of (Triggering unit))
      • Set VariableSet Temp_Number = (Player number of Temp_Player)
      • -------- --------
      • -------- Check which Unit Type died and then reduce the Count value --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
        • Then - Actions
          • -------- --------
          • Set VariableSet Footman_Count[Temp_Number] = (Footman_Count[Temp_Number] - 1)
          • -------- --------
          • Game - Display to (All players) the text: (Total Footman Units: + (|cffff0000 + (String(Footman_Count[Temp_Number]))))
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Archer
            • Then - Actions
              • -------- --------
              • Set VariableSet Archer_Count[Temp_Number] = (Archer_Count[Temp_Number] - 1)
              • -------- --------
              • Game - Display to (All players) the text: (Total Archer Units: + (|cffffff00 + (String(Archer_Count[Temp_Number]))))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Triggering unit)) Equal to Rifleman
                • Then - Actions
                  • -------- --------
                  • Set VariableSet Rifleman_Count[Temp_Number] = (Rifleman_Count[Temp_Number] - 1)
                  • -------- --------
                  • Game - Display to (All players) the text: (Total Rifleman Units: + (|cff00ff00 + (String(Rifleman_Count[Temp_Number]))))
                • Else - Actions
  • Dwarf Town Stuff
    • Events
    • Conditions
    • Actions
      • -------- Do Your Stuff Here --------
 
Last edited:
Level 12
Joined
Oct 28, 2019
Messages
479
Instead of Selling Units you could potentially Sell Items and create the desired unit immediately after purchasing the Dummy Item.

Also for defining how many units you want to limit (for example 16 Footman) you can create an Integer variable Footman_Count and then simply calculate whenever that unit is created.

Im not on the computer at the moment but I can make a small test map for you tomorrow if you'd like.

As for your current trigger, using Waits is never a good idea in multiplayer maps.
I made here its ok, worked ty, but need a need unit with inventory to buy the itens right?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Its buggin man, plz help me. If I remove the wait 0.00 or 0.01 seconds the nexts triggers dont fire... help.... i need do this

  • randomcolourDwarfTown1
    • Events
      • Unit - A unit owned by Player 1 (Red) Sells a unit
    • Conditions
      • (Unit-type of (Sold unit)) Equal to Dwarf
    • Actions
      • Unit - Move (Sold unit) instantly to (Center of DwarfTown1 <gen>), facing 80.00 degrees
      • Unit - Change ownership of (Sold unit) to Neutral Passive and Retain color
      • Set VariableSet UnitDwarf1 = (Sold unit)
      • Hero - Create Satchel Charge and give it to UnitDwarf1
      • Unit Group - Add (Sold unit) to LigthGroup
      • Trigger - Turn off (This trigger)
      • Wait 0.00 seconds
      • Trigger - Turn on randomcolourDwarfTown2 <gen>
I think you guys are overthinking this a little.
  • randomcolourWarriorBridge1
    • Events
      • Unit - A unit enters Tavern <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Warrior
    • Actions
      • Set Variable Warrior_Count = Warrior_Count + 1
      • Set Variable Warrior_Unit[Warrior_Count] = (Entering unit)
      • Unit - Move Warrior_Unit[Warrior_Count] instantly to (Center of Warrior_Region[Warrior_Count]), facing Warrior_Angle[Warrior_Count] degrees
      • Unit - Change ownership ofWarrior_Unit[Count] to Neutral Passive and Retain color
      • Unit Group - Add Warrior_Unit[Count] to LigthGroup
Some Arrays go a long way. Also, I doubt you want to use "Enters Region" as your Event, instead "A unit Sells a unit" makes more sense.

Also, ideally you'd use a Point array variable instead of a Region so you can avoid the memory leak. Warrior_Region[] and Warrior_Angle[] would be setup beforehand in an Init trigger, similar to what Crusher is doing with his Arrays.
 
Top