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