[JASS] Base System - Force Building to Cancel

Status
Not open for further replies.
Level 4
Joined
Mar 20, 2014
Messages
67
Hi All,

I'm working on creating a basing system (I can post it here after I've polished it) and I'm trying to make it like Vampirism Fire's. However after a base is claimed I want to cancel when they try to build in another base. I've tried ordering the constructing unit to "cancel" I've tried the OrderId of that same order (851976), and I've tried this method below
Code:
if(GetLocalPlayer() == Player(pNum)) {
                        DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "You have already claimed Base "+I2S(i)+". To remove your claim destroy all buildings in that base.");
                        ClearSelection();
                        SelectUnit(GetConstructingStructure(), true);
                        ForceUICancel();
                    }

Does anyone know why it doesn't work at all or have any other methods? It clears the selection and selects the unit for me, but it never seems to cancel regardless of what I build

Thanks
- Zach
 
Level 13
Joined
May 10, 2009
Messages
868
As far as I know, unfortunately, you can't cancel a construction as soon as its event EVENT_PLAYER_UNIT_CONSTRUCT_START fires. You need, at least, a 0. timer in order to be able to cancel a structure.

JASS:
function ForceCancelCB takes nothing returns nothing
    local unit fog = null
    loop
        set fog = FirstOfGroup(FC_Group)
        exitwhen fog == null
        call GroupRemoveUnit(FC_Group, fog)
        call IssueImmediateOrderById(fog, 851976)
    endloop
endfunction

function Trig_ForceCancel_Actions takes nothing returns nothing
    call GroupAddUnit(FC_Group, GetConstructingStructure())
    call TimerStart(FC_Timer, .0, false, function ForceCancelCB)
endfunction
 
If you're using build button you can catch build order and interrupt it. I used ForGroup, but maybe BloodSoul's FoG is better? Its up to you what yo use.
JASS:
globals
    constant integer            BASE_ID = 'h000' //your base id
    group                           cancelGroup=CreateGroup()
    timer                           cancelTimer=CreateTimer()
endglobals
native GetPlayerUnitTypeCount takes player p, integer unitid returns integer
function CancelEnum takes nothing returns nothing
    call IssueImmediateOrder(GetEnumUnit(), "stop")
    call GroupRemoveUnit(cancelGroup, GetEnumUnit())
endfunction
function Cancel takes nothing returns nothing
    call ForGroup(cancelGroup, function CancelEnum)
endfunction
function Trig_build_Conditions takes nothing returns boolean
    if GetIssuedOrderId()==BASE_ID and GetPlayerUnitTypeCount(GetOwningPlayer(GetOrderedUnit()), BASE_ID)>0 then
        call GroupAddUnit(cancelGroup, GetOrderedUnit())
        call TimerStart(cancelTimer, 0.00, false, function Cancel)
    endif
    return false
endfunction
//===========================================================================
function InitTrig_build takes nothing returns nothing
    set gg_trg_build = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_build, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddCondition( gg_trg_build, Condition( function Trig_build_Conditions ) )
endfunction
 
Level 4
Joined
Mar 20, 2014
Messages
67
I tried both of your suggestions, I used a .01 timer to cancel it and it still does not get cancelled, thoughts? Did I do something wrong? (Note the struct I made is only to pass data to the timer, and it only has the player's number as well as the unit constructing stored in it)

Code:
if(GetLocalPlayer() == Player(pNum)) {
    DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "You have already claimed Base "+I2S(i)+". To remove your claim destroy all buildings in that base.");
    p = pData.create();
    p.constructedUnit = GetConstructingStructure();
    p.pNum = pNum;
    t = GameTimer.new(function (GameTimer t) {
        pData p = t.data();
        if(GetLocalPlayer() == Player(p.pNum)) {
            ClearSelection();
            SelectUnit(p.constructedUnit, true);
            ForceUICancel();
        }
        p.destroy();
        t.deleteLater();
    }).start(.01);
    t.setData(p);
}
 
Status
Not open for further replies.
Top