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

[Trigger] adding ability to selected units via trigger

Status
Not open for further replies.
Level 5
Joined
May 27, 2007
Messages
144
Hi,
Well I would like to have a trigger which adds an ability to units when (condition) 2 units of same type or specific units are selected and when you disselect them the ability should be removed. The trigger is need for 6 players. Is this possible ?

Pls help
 
Level 5
Joined
May 27, 2007
Messages
144
EDIT: fixed 2 problems
Well your idea is good but i have still few problems
1st one is: When Im selecting 3 units the ability will be added
2nd one is: When I select unit A and 2 units B the ability will be added
3rd one is : When I select unit A and Unit C the ability will be added
It should only work when I select 2 units A or 1 unit A and 1 unit B

I tried to fix the problems here is my trigger:
  • AddAbility
    • Events
      • Player - Player 1 (Red) selects a unit
    • Conditions
    • Actions
      • Set CountGroup[1] = (Units currently selected by Player 1 (Red))
      • Set count = 0
      • For each (Integer A) from 1 to (Number of units in CountGroup[1]), do (Actions)
        • Schleifen - Aktionen
          • Set count = (count + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • count smaller than 2
        • Then - Actions
          • Skip remaining actions
        • Else - Actions
          • Do nothing
      • Set count = 0
      • Set CountedUnits[1] = (Units of type Worker)
      • For each (Integer A) from 1 to (Number of units in CountGroup[1]), do (Actions)
        • Schleifen - Actions
          • Set count = (count + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • count smaller than 2
          • count biger than 2
        • Then - Actions
        • Else - Actions
          • Unit Group - Pick every unit in CountGroup[1] and do (Actions)
            • Schleifen - Actions
              • Unit - Add Morph to (Picked unit)
      • Set count = 0
      • Set CountedUnits[1] = (Units of type Worker)
      • Set CountedUnits[2] = (Units of type Soldier)
      • For each (Integer A) from 1 to ((Number of units in CountedUnits[1]) + (Number of units in CountedUnits[2])), do (Actions)
        • Schleifen - Actions
          • Set count = (count + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Condtions
          • count biger than 2
          • count smaler than 2
        • Then - Actions
        • Else - Actions
          • Unit Group - Pick every unit in CountGroup[1] and do (Actions)
            • Schleifen - Actions
              • Unit - Add Morph to (Picked unit)
And the removing Trigger:
  • RemoveAbility
    • Events
      • Player - Player 1 (Red) diselect a unit
    • Conditions
    • Actions
      • Set CountGroup[1] = (Units currently selected by Player 1 (Red))
      • Set count = 0
      • For each (Integer A) from 1 to (Number of units in CountGroup[1]), do (Actions)
        • Schleifen - Actions
          • Set count = (count + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Condtidons
          • count biger than 1
        • Then - Actions
          • Set CountGroup[1] = (Units owned by Player 1 (Red) matching (((Matching unit) is selected by Player (Red)) Ungleich True))
        • Else - Actions
          • Set CountGroup[1] = (Units owned by Player 1 (Red))
      • Unit Group - Pick every unit in CountGroup[1] and do (Actions)
        • Schleifen - Actions
          • Unit - Remove Morph from (Picked unit)
Trigger v2
  • AddAbility
    • Events
      • Spieler - Player 1 (Red) selects a unit
    • Conditions
    • Actions
      • Set CountGroup[1] = (Units currently selected by Player 1 (Red))
      • Set CountG = 0
      • For each (Integer A) from 1 to (Number of units in CountGroup[1]), do (Actions)
        • Schleifen - Actions
          • Set CountG = (CountG + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CountG smaller or equal to 1
        • Then - Aktionen
          • Skip remaining actions
        • Else - Actions
          • Do nothing
      • Set CountedU = 0
      • Set CountedUnits[1] = (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Gleich Worker))
      • For each (Integer A) from 1 to (Number of units in CountedUnits[1]), do (Actions)
        • Schleifen - Actions
          • Set CountedU = (CountedU + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CountedU not equalt to 2
          • CountG biger than 2
        • Then - Actions
        • Else- Actions
          • Unit Group - Pick every unit in CountedUnits[1] and do (Actions)
            • Schleifen - Actions
              • Unit - Add Morph to (Picked unit)
      • Set CountedU = 0
      • Set CountedUnits[1] = (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Gleich Worker))
      • Set CountedUnits[2] = (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Gleich Soldier))
      • For each (Integer A) from 1 to ((Number of units in CountedUnits[1]) + (Number of units in CountedUnits[2])), do (Actions)
        • Schleifen - Actions
          • Set CountedU = (CountedU + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CountedU not equal to 2
          • CountG equal or biger than 3
        • Then - Actions
        • Else - Actions
          • Unit Group - Pick every unit in CountedUnits[2] and do (Actions)
            • Schleifen - Aktionen
              • Unit - Add Morph to (Picked unit)
          • Unit Group - Pick every unit in CountedUnits[1] and do (Actions)
            • Schleifen - Actions
              • Unit - Add Morph to (Picked unit)
Any ideas how to fix 3rd problem ?
And i know the spell is leaking :) Im not fixing it until i get final version
 
Last edited:
Level 5
Joined
May 27, 2007
Messages
144
I have it already look here
EDIT: fixed 2 problems
  • ...
    • Set CountedUnits[1] = (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Gleich Worker))
    • ...
    • Set CountedUnits[1] = (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Gleich Worker))
    • Set CountedUnits[2] = (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Gleich Soldier))
  • ...
 
Level 3
Joined
Aug 9, 2008
Messages
60
Made this code for ya.

JASS:
scope merge initializer init

globals
    private integer abilityid = 'Aens'
    private group g
endglobals

private function forgroup takes nothing returns nothing
    if GetUnitTypeId(GetEnumUnit()) == GetUnitTypeId(GetTriggerUnit()) then
        call UnitAddAbility(GetEnumUnit(), abilityid)
        call UnitAddAbility(GetTriggerUnit(), abilityid)
    endif
endfunction

private function select takes nothing returns boolean
    local group gr = CreateGroup()
    if IsUnitInGroup(GetTriggerUnit(), g) then
        return false
    endif
    set gr = g
    call GroupRemoveUnit(gr, GetTriggerUnit())
    call ForGroup(gr, function forgroup)
    call GroupAddUnit(g, GetTriggerUnit())
    call GroupClear(gr)
    call DestroyGroup(gr)
    set gr = null
    return false
endfunction

private function deselect takes nothing returns boolean
    call GroupRemoveUnit(g, GetTriggerUnit())
    call UnitRemoveAbility(GetTriggerUnit(), abilityid)
    return false
endfunction

private function init takes nothing returns nothing
    local trigger  t = CreateTrigger()
    local trigger tt = CreateTrigger()
    local integer  i = 0
    set g = CreateGroup()
    loop
        exitwhen i > 12
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
        call TriggerRegisterPlayerUnitEvent(tt, Player(i), EVENT_PLAYER_UNIT_DESELECTED, null)
        set i = i + 1
    endloop
    call TriggerAddCondition(t, Condition(function select))
    call TriggerAddCondition(tt, Condition(function deselect))
endfunction

endscope
 
Level 5
Joined
May 27, 2007
Messages
144
Do I have to change sth there? Like type unit name or spell id or sth.

I dont use jass so im nooby at it ^^ :D
 
Level 3
Joined
Aug 9, 2008
Messages
60
What you have to change is the global abilityid, because that's the ability that the code gives the units selected of multiple type.
 
Status
Not open for further replies.
Top