• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Making random unit from a unit group cast a spell

Status
Not open for further replies.
Level 10
Joined
Nov 23, 2006
Messages
592
Hello,

so I am using a squad system. The way it works is that when you select any unit from a squad, a squad leader is automatically selected. There is always only one type of unit in a squad.
When an order is issued to leader it is also given to all units in squad.

The problem comes with using abilities. The way I want it to work is:
1) A player selects a squad
2) squad leader is automaticaly selected (this is handled in different trigger)
3) player uses ability of squad leader (all the other units in squad are same type, therefore they also posses the ability)
4) the trigger stops squad leader from casting the ability and picks random unit from his squad to cast the ability

the first issue is that it is not working
the second issue is that I don't want a unit which has the ability on cooldown to be chosen, I have no idea how to do that

The trigger:

  • Events
    • Unit - A unit Is issued an order targeting an object
  • Conditions
    • (Issued order) Equal to (Order(heal))
    • (Custom value of (Ordered unit)) Not equal to 0
  • Actions
    • Set Target = (Target unit of issued order)
    • Set Unit = (Ordered unit)
    • Set Num = (Custom value of Unit)
    • Unit - Pause Unit
    • Unit - Unpause Unit
    • Unit Group - Pick every unit in (Random 1 units from Squad[Num]) and do (Unit - Order (Picked unit) to Human Priest - Heal Target)
Any help would be appreciated
Thanks in advance
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
the second issue is that I don't want a unit which has the ability on cooldown to be chosen, I have no idea how to do that
This requires an ability cooldown tracking system since it is not directly possible to look at ability cooldown state.

If issuing an order to cast an ability in cooldown returns false (requires JASS for this functionality) then that could be used to detect units that have already cast and try again with another unit.
 
Level 13
Joined
Oct 12, 2016
Messages
769
So, for the squad, this only selects one unit?

I do know when selecting multiple units of the same type with abilities, some abilities only cast once from a random unit in the group (Firebolt, for example).
 
Level 10
Joined
Nov 23, 2006
Messages
592
This requires an ability cooldown tracking system since it is not directly possible to look at ability cooldown state.

If issuing an order to cast an ability in cooldown returns false (requires JASS for this functionality) then that could be used to detect units that have already cast and try again with another unit.

Well that sucks, was hoping I could steer clear of JASS considering I know squat about it


So, for the squad, this only selects one unit?

I do know when selecting multiple units of the same type with abilities, some abilities only cast once from a random unit in the group (Firebolt, for example).

Yeah only one unit is selected


Anyway, any idea why the current version is not working guys? It manages to stop the unit but the pick random unit and do order does nothing
 
It's actually not needed to check cooldown/mana. When giving the order with jass one can get the success of such order.
IssueTargetOrder unit whichUnit, string order, widget targetWidget boolean

Example of such usage:

This demo will order one paladin to use holy light on an hurt unit when pressing esc, the paladin group has to be filled with units having holy light enabled.
  • spell on esc
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set Casted = False
      • Custom script: set bj_wantDestroyGroup =true
      • Set Target = (Random unit from (Units in (Playable map area) matching ((Life of (Matching unit)) Less than (Max life of (Matching unit)))))
      • Unit Group - Pick every unit in Paladins and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Casted Equal to False
            • Then - Actions
              • Set Caster = (Picked unit)
              • Custom script: set udg_Casted = IssueTargetOrder(udg_Caster, "holybolt", udg_Target)
              • -------- once succesful further members won't be ordered, bad side is that one unit will cast the spells most times. --------
            • Else - Actions
Anyway, any idea why the current version is not working guys? It manages to stop the unit but the pick random unit and do order does nothing
Does this group[index] exist? World Editor auto creates group-objects of an group-Array only upto the size defined in the variable editor, if you placed there an 1 only group [0]/[1] exists, further ones have to be hand created.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
It's actually not needed to check cooldown/mana. When giving the order with jass one can get the success of such order.
At some stage people reported that trigger issued orders bypassed cooldown and resource requirements to cast, so they could cast abilities still on cooldown. This might have been patched eventually, I am unsure.
 
Level 10
Joined
Nov 23, 2006
Messages
592
Well, the trigger i posted works on my test map.
Here is it.

This is excatly how I would like it to behave. Thank you! However I am still having trouble with making it work.

I have changed the trigger as follows:

  • Events
    • Unit - A unit Is issued an order targeting an object
  • Conditions
    • (Custom value of (Ordered unit)) Not equal to 0
    • (Issued order) Equal to (Order(magicleash))
  • Actions
    • Set Target = (Target unit of issued order)
    • Set Unit = (Ordered unit)
    • Set Order = (String((Issued order)))
    • Set Num = (Custom value of Unit)
    • Unit - Pause Unit
    • Unit - Unpause Unit
    • Set Casted = False
    • Unit Group - Pick every unit in Squad[Num] and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Casted Equal to False
          • Then - Actions
            • Set Caster = (Picked unit)
            • Custom script: set udg_Casted = IssueTargetOrder(udg_Caster, udg_Order, udg_Target)
            • -------- once succesfull further units won't be ordered, bad side is that one will cast the spells most times. --------
          • Else - Actions
the units pauses but nothing happens after.

As for your question, I am pretty sure the Squad[Num] exists as this trigger works and it is getting the group the same way:
  • Events
    • Unit - A unit Is issued an order targeting an object
  • Conditions
    • (Custom value of (Ordered unit)) Not equal to 0
    • (Issued order) Not equal to (Order(magicleash))
  • Actions
    • Set Num = (Custom value of (Ordered unit))
    • -------- Num is an integer, set to the value of the squad we are dealing with. --------
    • Set Order = (String((Issued order)))
    • -------- Order is a string, used to hold the order we will give to the squad later. --------
    • Trigger - Turn off (This trigger)
    • -------- This is to ensure there can be no infinite loop. --------
    • Custom script: call GroupTargetOrder( udg_Squad[udg_Num], udg_Order, GetOrderTargetUnit() )
    • -------- This custom text orders the squad to do the order specified earlier on the same object as the ordered unit. --------
    • Trigger - Turn on (This trigger)
    • -------- Turns the movement triggers back on. --------
    • Set Order = <Empty String>
    • Set Num = 0
    • -------- Resets the variables used to prevent errors. --------
 
Level 10
Joined
Nov 23, 2006
Messages
592
Yeah I have the same trigger for no target order with variable Order. I tried to change the name of the variable in spell trigger to CastOrder, but it still does not work. I probably need to find another way to stop squad leader from casting without using Pause/unpause.

EDIT: So I have finally managed to fix it! What finally made it work is the Ordered unit is summoned equals to false condition. This is because in the squad system, all units in squad except the squad leader have the classification summoned.

  • Events
    • Unit - A unit Is issued an order targeting an object
  • Conditions
    • ((Ordered unit) is Summoned) Equal to False
    • (Custom value of (Ordered unit)) Not equal to 0
    • (Issued order) Equal to (Order(magicleash))
  • Actions
    • Set Target = (Target unit of issued order)
    • Set Unit = (Ordered unit)
    • Set CastOrder = (String((Issued order)))
    • Set Num = (Custom value of Unit)
    • Unit - Add StopOrder to Unit
    • Unit - Order Unit to Night Elf Mountain Giant - Taunt
  • -------- I have given base order TAUNT to the channel ability --------
    • Set Casted = False
    • Unit Group - Pick every unit in Squad[Num] and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Casted Equal to False
          • Then - Actions
            • Set Caster = (Picked unit)
            • Custom script: set udg_Casted = IssueTargetOrder(udg_Caster, udg_CastOrder, udg_Target)
            • -------- once succesfull further units won't be ordered, bad side is that one will cast the spells most times. --------
          • Else - Actions
  • Events
    • Unit - A unit Is issued an order with no target
  • Conditions
    • (Issued order) Not equal to (Order(channel))
    • (Custom value of (Ordered unit)) Not equal to 0
  • Actions
    • Set Num = (Custom value of (Ordered unit))
    • -------- Num is an integer, set to the value of the squad we are dealing with. --------
    • Set Order = (String((Issued order)))
    • -------- Order is a string, used to hold the order we will give to the squad later. --------
    • Trigger - Turn off (This trigger)
    • -------- This is to ensure there can be no infinite loop. --------
    • Custom script: call GroupImmediateOrder( udg_Squad[udg_Num], udg_Order )
    • -------- This custom text orders the squad to do the order specified earlier. --------
    • Trigger - Turn on (This trigger)
    • -------- Turns the movement triggers back on. --------
    • Set Order = <Empty String>
    • Set Num = 0
    • -------- Resets the variables used to prevent errors. --------
 
Last edited:
Status
Not open for further replies.
Top