Selecting Units. No Selecting?

Beetlebomb

New Member
Reaction score
43
Hey guys, did a quick forum search, but couldn't find an answer to this problem.

I'm trying to make a unit be selected in the beginning of the game(A Hero(if that matters)), but for some strange reason it's not going through.


Here's my code--I'm sure there's a simple explanation to this:

JASS:
scope SetupGame initializer Setup

private function Remove_Them takes nothing returns nothing
    call RemoveUnit(GetEnumUnit())
endfunction

private function Activate_ManaBubble takes nothing returns nothing
    local real x = GetUnitX(GetEnumUnit())
    local real y = GetUnitY(GetEnumUnit())
    call IssueImmediateOrder( GetEnumUnit(), "manashieldon" )
    call SelectUnitForPlayerSingle(GetEnumUnit(), GetEnumPlayer()) //not working <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown    :(" loading="lazy" data-shortname=":(" />
    call SetCameraPosition(x, y)
endfunction

private function Actions takes nothing returns nothing
    local group g = CreateGroup()
    local integer i = 0
    call Cheat(&quot;iseedeadpeople&quot;)
    call SuspendTimeOfDay(true)
    loop
    exitwhen i == bj_MAX_PLAYER_SLOTS
        set g = GetUnitsOfPlayerAll(Player(i))
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_EMPTY then
        call ForGroup(g, function Remove_Them)
        else
        call ForGroup(g, function Activate_ManaBubble)
        endif
        call GroupClear(g)
        set g = null
        set i = i+1
    endloop
    call DestroyGroup(g)
endfunction

//===========================================================================
private function Setup takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventSingle(t, 0.00 )
    call TriggerAddAction(t, function Actions )
endfunction

endscope


And of course, +rep to the kind souls-- as usual ^^
 
Reaction score
456
Who is GetEnumPlayer there? Try GetOwningPlayer(GetEnumUnit()). And since you're using GetEnumUnit() 6 times, store it in variable.
 

Beetlebomb

New Member
Reaction score
43
wait, so you want me to move my GroupClear call to my Remove_Them function?

Doesn't that destroy the group after the the function runs once?

EDIT: I'm guessing there's an easier way to remove units in a group than what I'm doing.
 

emjlr3

Change can be a good thing
Reaction score
395
not really - and what they said above
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
You can enumerate units and do quite a bit of actions to them without adding them to the group at all, by simply doing the actions within the filter function.

JASS:
scope SetupGame initializer Setup

globals
        private group g = CreateGroup() // Global group, for easiness and simplicity!
endglobals

private function Check takes nothing returns boolean
    local unit u = GetFilterUnit()
    local player p = GetOwningPlayer(u)
    if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_EMPTY then
        call RemoveUnit(u)
    else
        call IssueImmediateOrder(u, &quot;manashieldon&quot;)
        if GetLocalPlayer() == p then
            call ClearSelection()
            call SelectUnit(u, true)
            call SetCameraPosition(GetUnitX(u), GetUnitY(u))
        endif
    endif
    set u = null
    set p = null
    return false // Simply, just don&#039;t add the units to the group! You&#039;ve already done whatever you need to them, so there is no need for nulling or other annoyances
endfunction


private function Actions takes nothing returns nothing
    call Cheat(&quot;iseedeadpeople&quot;)
    call SuspendTimeOfDay(true)
    call GroupEnumUnitsInRange(g, 0, 0, 999999., Filter( function Check)) // We will run the actions in the Check function.
endfunction

//===========================================================================
private function Setup takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.00, false)
    call TriggerAddAction(t, function Actions )
endfunction

endscope
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top