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

How can i use mana as a new resource?

Status
Not open for further replies.
Level 3
Joined
Dec 2, 2018
Messages
11
My barracks have 100 mana and i need my footman to cost 50 mana to be trained

I did this before using research but i dont know how to make it using training units

Helpme pls

  • test1
    • Events
      • Unit - A unit Begins research
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Main Build (New)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Triggering unit)) Greater than or equal to 100.00
          • (Owner of (Triggering unit)) Equal to Player 1,2,3,4...
        • Then - Actions
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) - 100.00)
        • Else - Actions
          • Unit - Change ownership of Main Build (New) 0011 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Main Build (New) 0011 <gen> to Player 1,2,3,4, and Retain color
 
Level 12
Joined
Mar 13, 2020
Messages
421
My barracks have 100 mana and i need my footman to cost 50 mana to be trained

I did this before using research but i dont know how to make it using training units

Helpme pls

  • test1
    • Events
      • Unit - A unit Begins research
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Main Build (New)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Triggering unit)) Greater than or equal to 100.00
          • (Owner of (Triggering unit)) Equal to Player 1,2,3,4...
        • Then - Actions
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) - 100.00)
        • Else - Actions
          • Unit - Change ownership of Main Build (New) 0011 <gen> to Neutral Passive and Retain color
          • Unit - Change ownership of Main Build (New) 0011 <gen> to Player 1,2,3,4, and Retain color

the Same like you did..

only Change Event to Unit Starts Training or something like that it’s called

and Conditon

Unit type Equal to Footman

and like your mana cost only 50

i mean if this works for your Research.. it works too for Trained Units so you can Copy this trigger and just change a few Lines...
Maybe it’s not the best way to do it but if it’s working why not...
 
  • Training
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Barracks
      • (Trained unit-type) Equal to Footman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Triggering unit)) Greater than or equal to 50.00
        • Then - Actions
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) - 50.00)
        • Else - Actions
          • Custom script: call IssueImmediateOrderById(GetTriggerUnit(), 851976)
 
Level 3
Joined
Dec 2, 2018
Messages
11
Ok that works but only to the first unit that you train, what about if you train 5 footman? it only cost for the first you trained

there is a way to unavaliable the unit only for that building if it have less than 50 mana?
 

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,391
A neat trick you can do is hide the buttons for your trained units using the X:0,Y:-11 trick, then give your Barracks a bunch of abilities that mimic these trained units.

When the Barracks casts one of these abilities, you order the Barracks to train the associated unit.

I attached a system with a working example of this. There's a bit of configuration to get it working but it's quite simple and efficient once you get the hang of it. If you use it, read the README file in the Trigger Editor, it should explain everything.

Here's how you would add a Barracks to the system that can train 3 different units.
  • TM Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- /// BARRACKS SETUP \\\ --------
      • -------- Training Structure + How Many Units It Can Train: --------
      • Set VariableSet TM_UnitType[0] = Barracks
      • Set VariableSet TM_Trained_Total = 3
      • -------- - - - - - - - - - - - - - - --------
      • -------- Unit's Trained: --------
      • Set VariableSet TM_UnitType[1] = Footman
      • Set VariableSet TM_UnitType[2] = Rifleman
      • Set VariableSet TM_UnitType[3] = Knight
      • -------- - - - - - - - - - - - - - - --------
      • -------- Structure Abilities for Training Units: --------
      • Set VariableSet TM_Ability[1] = Train Footman (Ability)
      • Set VariableSet TM_Ability[2] = Train Rifleman (Ability)
      • Set VariableSet TM_Ability[3] = Train Knight (Ability)
      • -------- - - - - - - - - - - - - - - --------
      • -------- Last Step, Add this Data to the Hashtable: --------
      • Trigger - Run TM Add To System <gen> (ignoring conditions)
  • TM Add To System
    • Events
    • Conditions
    • Actions
      • For each (Integer TM_Loop) from 1 to TM_Trained_Total, do (Actions)
        • Loop - Actions
          • -------- Save the Train Mana Costs at the Unit-Type Id of our Trained Units --------
          • Custom script: set udg_TM_Integer = udg_TM_UnitType[udg_TM_Loop]
          • Hashtable - Save (Mana cost of TM_Ability[TM_Loop], Level 0.) as 0 of TM_Integer in TM_Hashtable.
          • -------- - - - - - - - - - - - - - - --------
          • -------- Save the Train Abilities at the Unit-Type Id of our Structure --------
          • Custom script: set udg_TM_Integer = udg_TM_UnitType[0]
          • Custom script: set udg_TM_Integer2 = udg_TM_Ability[udg_TM_Loop]
          • Hashtable - Save TM_Integer2 as TM_Loop of TM_Integer in TM_Hashtable.
          • -------- - - - - - - - - - - - - - - --------
          • -------- Save the Total number of Trained Units (Needed for disabling the abilities in a future Loop) --------
          • Hashtable - Save TM_Trained_Total as 0 of TM_Integer in TM_Hashtable.
  • TM Train Unit
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Barracks
    • Actions
      • Set VariableSet TM_String = (Tooltip (Auto-Casting Activated) of (Ability being cast) for level 0)
      • Custom script: call IssueTrainOrderByIdBJ( GetTriggerUnit(), S2A(udg_TM_String) )
      • -------- - - - - - - - - - - - - - - --------
      • -------- This enables the use of our Train Abilities for our Building at all times. This bypasses the normal mechanics of Warcraft 3 (can't cast while training) --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load 0 of (Key (Triggering unit).) from TM_Hashtable.) Equal to False
        • Then - Actions
          • Hashtable - Save True as 0 of (Key (Triggering unit).) in TM_Hashtable.
          • -------- - - - - - - - - - - - - - - --------
          • Set VariableSet TM_UnitType[0] = (Unit-type of (Triggering unit))
          • Custom script: set udg_TM_Integer = udg_TM_UnitType[0]
          • For each (Integer TM_Loop) from 1 to (Load 0 of TM_Integer from TM_Hashtable.), do (Actions)
            • Loop - Actions
              • Custom script: set udg_TM_Ability[0] = LoadInteger(udg_TM_Hashtable, udg_TM_Integer, udg_TM_Loop)
              • Unit - For (Triggering unit), Ability TM_Ability[0], Disable ability: False, Hide UI: False
        • Else - Actions
  • TM Cancel Training
    • Events
      • Unit - A unit Cancels training a unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Barracks
    • Actions
      • Custom script: set udg_TM_Integer = GetTrainedUnitType()
      • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + (Real((Load 0 of TM_Integer from TM_Hashtable.))))
I'm also using this system to convert an Integer to it's Rawcode form: [Snippet] Ascii

Note that I never clean up any unused data from the hashtable. I don't think it'll make much of a difference but it's not the best practice.

Long story short, you're hiding the standard Train Unit buttons from your Barracks (and any other Structures you'd like) and creating Ability "replacements" for them. These Abilities cost mana and are triggered to tell the Structure to Train the actual unit associated with the ability. I use a Hashtable to store all of this data and keep things organized and efficient.

Map requires latest patch.
I believe the system itself should require 1.31+. It uses BlzGetAbilityManaCost() and BlzUnitDisableAbility().
 

Attachments

  • Train With Mana Example.w3m
    27.1 KB · Views: 26
Last edited:
Level 3
Joined
Dec 2, 2018
Messages
11
I dont know how to do it so i give up and create a multiboard xD

All works ok but why the remove unit from the game doesnt work?

  • traintest
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Entering unit)) Equal to Soldier
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ResourceInt[100] Greater than or equal to 20
            • Then - Actions
              • Multiboard - Set the text for ResourceMB[1] item in column 1, row 1 to (String((ResourceInt[100] - 20)))
            • Else - Actions
              • Unit - Remove (Entering unit) from the game
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,391
Not sure what that trigger is trying to do exactly.

1) ResourceInt[100] seems random, what does this represent? The Index -> [the number in these brackets] is NOT the value of the Variable if that's what you're thinking. I recommend looking up how to use Arrays.
2) It looks like you never reduce ResourceInt[100], it'll keep it's original value even after a Soldier enters the map.
3) You display a reduced ResourceInt[100] in the Multiboard, but that doesn't actually reduce the Variable itself. You're just telling the game to display "X-20" in the Multiboard. If X never changes, than it will always display the same thing.

Anyway, what were you having trouble with?

I put a README file in the Trigger Editor of my map, if you click it you'll see step by step instructions on EVERYTHING that you need to do to get the system to work.

Object Editor instructions:
1) Find your Structure that Trains Units in the Object Editor (A Barracks for example).
2) Go through each of that structure's Trained Units in the Object Editor and set their Art - Button Positions to X: 0, Y: -11. You need to SHIFT-click the field in order to type in negative values.
3) Go to the Ability Editor and create a new ability for each Trained Unit. I recommend basing them off of the Abilities I already made. Then Add these new abilities to the Barracks.
4) Make sure these Abilities follow my instructions. They need a different Base Order Id from one another and you need to put the Trained Unit's Rawcode in the Tooltip - Turn Off. So if the Ability is meant to Train Footman, you put "hfoo" (without the quotation marks) in the Tooltip - Turn Off. Again, you can just follow the examples I already made.
5) You may also want to remove or keep the Gold/Lumber/Food costs from your Trained units depending on how your map works.

That should be everything you need to do in the Object Editor.

After that you go to the Trigger Editor in order to add your Structure to the system:

1) Following my Setup trigger, you set TM_UnitType[0] = Your Structure that trains units:
  • Set VariableSet TM_UnitType[0] = Barracks
2) You set TM_Trained_Total = How many units the Structure trains, in my example my Barracks trains a Footman, Rifleman, and Knight, so 3 units in total:
  • Set VariableSet TM_Trained_Total = 3
3) You then set TM_UnitType[1] to TM_UnitType[X] to be equal to your Trained Units. The first Trained Unit always starts at Index [1] and then you increase this by 1 for each new Unit.
  • Set VariableSet TM_UnitType[1] = Footman
  • Set VariableSet TM_UnitType[2] = Rifleman
  • Set VariableSet TM_UnitType[3] = Knight
4) You do the same thing as Step 3 but for the Abilities. Make sure the Units/Abilities Indexes match. See how TM_UnitType[1] is Footman and TM_Ability[1] is the Train Footman ability, they go together therefore they need to have the same Index [#].
  • Set VariableSet TM_Ability[1] = Train Footman (Ability)
  • Set VariableSet TM_Ability[2] = Train Rifleman (Ability)
  • Set VariableSet TM_Ability[3] = Train Knight (Ability)
5) Lastly you Run a trigger that my system uses in order to Add all of these variables to a Hashtable. There's nothing special you need to do here, just make sure this Action happens after you're done setting all of the Setup Variables for your Structure.
  • Trigger - Run TM Add To System <gen> (ignoring conditions)
When you want to add another Structure to the system you would follow these same exact instructions. So you would Copy & Paste all of the Actions above, and then adjust their values to use your new Structure/Units/Abilities.
 
Last edited:
Status
Not open for further replies.
Top