- Joined
- Jun 27, 2010
- Messages
- 2,763
This might be a silly question, but what's the correct way to detect if a peasant is ordered to build ANY building and order him to stop?
function BuildActions takes nothing returns nothing
set udg_i = 0
set udg_t = GetTriggeringTrigger()
loop
exitwhen udg_i>11
if udg_t == udg_BuildTrigger[udg_i] then
call DisplayTimedTextToPlayer(Player(udg_i), 0, 0, 60, "You cannot build")
call ForceUICancelBJ( Player(udg_i) )
return
endif
set udg_i = udg_i + 1
endloop
endfunction
function InitTrig_Prevent_Build takes nothing returns nothing
local integer i = 0
loop
exitwhen i>11
set udg_BuildTrigger[i] = CreateTrigger()
call TriggerAddAction(udg_BuildTrigger[i], function BuildActions)
if GetLocalPlayer() == Player(i) then
call TriggerRegisterGameEvent(udg_BuildTrigger[i], EVENT_GAME_BUILD_SUBMENU)
endif
set i = i + 1
endloop
endfunction
function CancelBuild takes nothing returns nothing
if IsUnitSelected(GetEnumUnit(), Player(udg_i)) == true and UnitHasBuffBJ(GetEnumUnit(), 'BUfa') == true then //'BUfa' = Frost Armor Buff
call ForceUICancelBJ( Player(udg_i) )
call DisplayTimedTextToPlayer(Player(udg_i), 0, 0, 60, "This worker cannot build")
else
endif
endfunction
function BuildActions takes nothing returns nothing
set udg_i = 0
set udg_t = GetTriggeringTrigger()
loop
exitwhen udg_i>11
if udg_t == udg_BuildTrigger[udg_i] then
set bj_wantDestroyGroup = true
call ForGroupBJ( GetUnitsOfPlayerAndTypeId(Player(udg_i), 'hpea'), function CancelBuild) //'hpea' = Peasant
return
endif
set udg_i = udg_i + 1
endloop
endfunction
function InitTrig_Prevent_Build takes nothing returns nothing
local integer i = 0
loop
exitwhen i>11
set udg_BuildTrigger[i] = CreateTrigger()
call TriggerAddAction(udg_BuildTrigger[i], function BuildActions)
if GetLocalPlayer() == Player(i) then
call TriggerRegisterGameEvent(udg_BuildTrigger[i], EVENT_GAME_BUILD_SUBMENU)
endif
set i = i + 1
endloop
endfunction
The peasant gets issued a point target order of the building's unit type (4 character raw data value). This can be detected like any point target order and also cancelled like any point target order. Cancelling the order requires that the unit be pause cycled as the event fires before the actual order is issued so issuing "stop" or other approaches would require being done in a separate trigger thread to occur in the correct order.This might be a silly question, but what's the correct way to detect if a peasant is ordered to build ANY building and order him to stop?
uhhh @Warseeker , also my Engineer unit can build buildings. My mistake. You now made it to check the peasant instead of any unit that can buildJASS:function CancelBuild takes nothing returns nothing if IsUnitSelected(GetEnumUnit(), Player(udg_i)) == true and UnitHasBuffBJ(GetEnumUnit(), 'BUfa') == true then //'BUfa' = Frost Armor Buff call ForceUICancelBJ( Player(udg_i) ) call DisplayTimedTextToPlayer(Player(udg_i), 0, 0, 60, "This worker cannot build") else endif endfunction function BuildActions takes nothing returns nothing set udg_i = 0 set udg_t = GetTriggeringTrigger() loop exitwhen udg_i>11 if udg_t == udg_BuildTrigger[udg_i] then set bj_wantDestroyGroup = true call ForGroupBJ( GetUnitsOfPlayerAndTypeId(Player(udg_i), 'hpea'), function CancelBuild) //'hpea' = Peasant return endif set udg_i = udg_i + 1 endloop endfunction function InitTrig_Prevent_Build takes nothing returns nothing local integer i = 0 loop exitwhen i>11 set udg_BuildTrigger[i] = CreateTrigger() call TriggerAddAction(udg_BuildTrigger[i], function BuildActions) if GetLocalPlayer() == Player(i) then call TriggerRegisterGameEvent(udg_BuildTrigger[i], EVENT_GAME_BUILD_SUBMENU) endif set i = i + 1 endloop endfunction