Checking to see which unit is selected

BlueMirage

Trust, but doubt.
Reaction score
39
I have a command that allows players to see some statistics of any unit. The stats that show up are correct, and removed from the function I'm showing a bit down below for easier reading. However, it sometimes displays the statistics of a unit that isn't selected, or it says that I have more than one unit selected or sometimes even no unit selected. Can someone understand why this happens?

JASS:
function Trig_Stats takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local group g = GetUnitsSelectedAll(p)
    local integer i = CountUnitsInGroup(g)
    local real r
    local unit u

    if i == 0 then
        call DisplayTimedTextToPlayer(p, 10., 0, 0, "No unit selected.")
    else
        set u = GroupPickRandomUnit(g)
        if IsUnitEnemy(u, p) == true and udg_Constant[13] == 1 then //One game mode doesn't allow checking stats on enemy units.
            call DisplayTimedTextToPlayer(p, 0, 0, 10., "Output omitted due to game mode.")
        elseif i > 1 then
            call DisplayTimedTextToPlayer(p, 0, 0, 10., "More than one unit selected.")
        elseif IsUnitType(u, UNIT_TYPE_HERO) != true then
            call DisplayTimedTextToPlayer(p, 0., 0., 10., "That unit is not a hero.")
        else
            set i = GetConvertedPlayerId(GetOwningPlayer(u))
            //calls for game messages are here.

        endif
        set u = null
    endif
endfunction

//===========================================================================
function InitTrig_Stats takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i
    loop
        call TriggerRegisterPlayerChatEvent(t, Player(i), "-stats", true )
        exitwhen i == 11
        set i = i + 1
    endloop
    call TriggerAddAction(t, function Trig_Stats )
endfunction
 

Tyman2007

Ya Rly >.
Reaction score
74
maybe you can simply try doing
[ljass]local group g = CreateGroup()[/ljass]
followed by
[ljass]call GroupEnumUnitsSelected(g, p, null)[/ljass]

that might help out.

above GroupEnumUnitsSelected, there's a function in the BJ called
[ljass]call SyncSelections()[/ljass]
I'm not quite sure what that does though..

Then again, I'm not too much of a fan of dealing with selecting units.
 

BlueMirage

Trust, but doubt.
Reaction score
39
I'll try that native. If it works, I'll +rep

It works perfectly. Thank you for your help.
 
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