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

Need help about refferring a unit

Status
Not open for further replies.
Level 3
Joined
Jan 3, 2010
Messages
46
If it's based off of a unit being trained, try using:

  • Events
    • Unit - A unit is trained
    • Conditions
    • Actions
      • If/ then/else, multiple functions
        • If - Conditions
          • (Unit-type of (Trained Unit)) is Equal to Footman
        • Then - Actions
          • Your actions here
        • Else - Actions
          • Do Nothing
 
Level 11
Joined
Aug 1, 2009
Messages
714
If it's based off of a unit being trained, try using:

  • Events
    • Unit - A unit is trained
    • Conditions
    • Actions
      • If/ then/else, multiple functions
        • If - Conditions
          • (Unit-type of (Trained Unit)) is Equal to Footman
        • Then - Actions
          • Your actions here
        • Else - Actions
          • Do Nothing

I have tried that but it won't work
Is there any Jass thing about with it?
I need it since I am using 6 custom resources (triggered)
 
Level 11
Joined
Aug 1, 2009
Messages
714
  • Ancient Worker
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Ancient Worker
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Player_Resources_Food[(Player number of (Owner of (Researching unit)))] Less than or equal to 49
        • Then - Actions
          • Custom script: call IssueImmediateOrderById( GetTriggerUnit( ), 0xD0008 )
          • Set PG = (Player group((Owner of (Researching unit))))
          • Cinematic - Clear the screen of text messages for PG
          • Game - Display to PG for 5.00 seconds the text: ...
          • Custom script: call DestroyForce (udg_PG)
        • Else - Actions
          • Set Player_Resources_Food[(Player number of (Owner of (Researching unit)))] = (Player_Resources_Food[(Player number of (Owner of (Researching unit)))] - 50)
here it is
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
I think you can, if I understood you correctly. Here's the system:


  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Hash = (Last created hashtable)
  • Untitled Trigger 018
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(footman))
    • Actions
      • Custom script: set udg_i1 = GetHandleId(GetTriggerUnit() )
      • Countdown Timer - Start Timer as a One-shot timer that will expire in 0.00 seconds
      • Unit Group - Add (Triggering unit) to StopGroup
      • Custom script: call SaveInteger( udg_Hash , udg_i1, StringHash("units") , LoadInteger( udg_Hash , udg_i1 , StringHash("units") ) + 1 )
  • Cancel
    • Events
      • Time - Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in StopGroup and do (Actions)
        • Loop - Actions
          • Set u1 = (Picked unit)
          • Custom script: set udg_i1 = GetHandleId( udg_u1 )
          • Custom script: set udg_i2 = LoadInteger( udg_Hash , udg_i1 , StringHash("units") )
          • For each (Integer loopA) from 1 to i2, do (Actions)
            • Loop - Actions
              • Custom script: call IssueImmediateOrderById( udg_u1 , 0xD0008 )
          • Unit Group - Remove u1 from StopGroup
          • Custom script: call FlushChildHashtable( udg_Hash, udg_i1 )
  • Orders Copy 2
    • Events
      • Unit - A unit Is issued an order with no target
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg("["+GetUnitName(GetTriggerUnit())+"] issued order [|cffFFFF00"+I2S(GetIssuedOrderId())+"|r] (|cffFF8040"+OrderId2String(GetIssuedOrderId())+"|r)")
      • Game - Display to (All players) the text: (String((Issued order)))


You catch the order of training a unit and order the unit to cancel the training.

But why so "complex" system? You could just use wait of 0.00 seconds, but it's not quick enough. With that, you still see the training begin for a brief moment. A timer of 0.00 expiration time is nearly instant. The save/load integer is done because without it, you can train those units if you click the train button frantically.

The last trigger is there so you can check the order strings for different units, write them down and then use them.
 

Attachments

  • Cancel_Training.w3x
    19.8 KB · Views: 52
Well apparently, this works too:
  • Melee Initialization
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(Footman))
    • Actions
      • Unit - Pause (Triggering unit)
      • Unit - Unpause (Triggering unit)
What you can't do is cancelling the training of a specific unit, when there are many units in the queue. For example, you train Sorceress - Priest - Spell Breaker - Sorceress - Spell Breaker. If you want to cancel the Priest's training, then, there is no way to do that.
 
I don't fully understand what you want, but if you want to cancel unit training you can do this way http://www.thehelper.net/forums/showthread.php?t=88301 But you probably already know that. This just forces the player to press the cancel button (red circle with line), so you can repeatedly force it to cancel multiple units. But to find a type you must keep track of which unit types are training at the moment, preferably using hashtables with handles.

And a unit which hasn't been trained yet, has no reference yet, it comes to life only when trained, until then it's just a process in the training building.
 
Level 11
Joined
Aug 1, 2009
Messages
714
Ok then...Looks like I gotta find a new alternative way here.
Hahaha. Thanks guys. +rep for some help.

Edit: Found a new alternate way. Hahaha. It's been hard to be wise here.
  • Ancient Worker
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Ancient Worker
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Player_Resources_Food[(Player number of (Owner of (Trained unit)))] Less than or equal to 49
        • Then - Actions
          • Unit - Remove (Trained unit) from the game
          • Set PG = (Player group((Owner of (Trained unit))))
          • Cinematic - Clear the screen of text messages for PG
          • Game - Display to PG for 5.00 seconds the text: ...
          • Custom script: call DestroyForce (udg_PG)
        • Else - Actions
          • Set Player_Resources_Food[(Player number of (Owner of (Trained unit)))] = (Player_Resources_Food[(Player number of (Owner of (Trained unit)))] - 50)
Found something leaky?
 
Level 11
Joined
Aug 1, 2009
Messages
714
Yes, but the unit will have to finish training, before the error message appears on the screen, which is way too awkward.

Anyway, nothing leaky ;)

Thanks for the check. Yah that is awkward.
But I hate it cause it needs to finish training. ~_~.
BTW. Thanks for the help.

(Force me to find an alternate way.)
Oh well, back to make Civilization Battles.
 
Status
Not open for further replies.
Top