function Trig_Cancel_Actions takes nothing returns nothing
local eventid e = GetTriggerEventId()
if e == EVENT_PLAYER_UNIT_ISSUED_ORDER then // This catches any queueing of units/researches
// Order ID 851976 is issued when you click cancel or press escape when something is queued.
// You only need to catch add to queue orders so skip that order ID.
// The reason why is because the cancel events will catch all user cancel interactions.
// And clicking on a queued icon isn't interpreted as an order.
if not (GetIssuedOrderId() == 851976) then
call DisplayTextToPlayer(user, 0, 0, GetUnitName(GetOrderedUnit()) + " is issued an order.")
call DisplayTextToPlayer(user, 0, 0, "Issued order is " + GetObjectName(GetIssuedOrderId()))
endif
// These cancel events will cancel requested queue where the user will press escape, click cancel or click on the queued icon.
elseif e == EVENT_PLAYER_UNIT_TRAIN_CANCEL then
call DisplayTextToPlayer(user, 0, 0, GetObjectName(GetTrainedUnitType()) + " cancelled.")
elseif e == EVENT_PLAYER_UNIT_RESEARCH_CANCEL then
call DisplayTextToPlayer(user, 0, 0, GetObjectName(GetResearched()) + " cancelled.")
elseif e == EVENT_PLAYER_UNIT_UPGRADE_CANCEL then
call DisplayTextToPlayer(user, 0, 0, "An upgrade is cancelled.")
// Luckily upgrades can only be qeueued as one, so not getting the cancelled upgrade is not a problem.
// You already got the upgrade with the issued order event.
endif
set e = null
endfunction
//===========================================================================
function InitTrig_Cancel takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t, user, EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
call TriggerRegisterPlayerUnitEvent(t, user, EVENT_PLAYER_UNIT_TRAIN_CANCEL, null)
call TriggerRegisterPlayerUnitEvent(t, user, EVENT_PLAYER_UNIT_RESEARCH_CANCEL, null)
call TriggerRegisterPlayerUnitEvent(t, user, EVENT_PLAYER_UNIT_UPGRADE_CANCEL, null)
call TriggerAddAction(t, function Trig_Cancel_Actions)
set t = null
endfunction