HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

constructing unit if conditions not matched cancel construction

02-07-2008, 10:58 AM#1
ILikeShiri.
I have a trigger that when a unit starts construction of a windmill that it must just keep constructing it and deduct some values from variables but if they variable values arent high enough it should cancel the construction and remove the structure. Ingame, (the variables are high enough and it deducts them(i see that in multiboard) but when it starts building the unit dissapears its unselectable or anything but i put the builder in a unit groupt with ctrl+1 but if i select it it looks like its still constructing but in an inexisting building. Someone please help me, this is my trigger:

Collapse JASS:
function Trig_windmill_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetConstructingStructure()) == 'h002' ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func002C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(0) ) ) then
        return false
    endif
    if ( not ( udg_lumber[1] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[1] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[1] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[1] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[1] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func003C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(1) ) ) then
        return false
    endif
    if ( not ( udg_lumber[2] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[2] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[2] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[2] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[2] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func004C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(2) ) ) then
        return false
    endif
    if ( not ( udg_lumber[3] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[3] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[3] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[3] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[3] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func005C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(3) ) ) then
        return false
    endif
    if ( not ( udg_lumber[4] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[4] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[4] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[4] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[4] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func006C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(4) ) ) then
        return false
    endif
    if ( not ( udg_lumber[5] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[5] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[5] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[5] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[5] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func007C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(5) ) ) then
        return false
    endif
    if ( not ( udg_lumber[6] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[6] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[6] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[6] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[6] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func008C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(6) ) ) then
        return false
    endif
    if ( not ( udg_lumber[7] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[7] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[7] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[7] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[7] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func009C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(7) ) ) then
        return false
    endif
    if ( not ( udg_lumber[8] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[8] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[8] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[8] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[8] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func010C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(8) ) ) then
        return false
    endif
    if ( not ( udg_lumber[9] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[9] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[9] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[9] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[9] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func011C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(9) ) ) then
        return false
    endif
    if ( not ( udg_lumber[10] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[10] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[10] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[10] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[10] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func012C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(10) ) ) then
        return false
    endif
    if ( not ( udg_lumber[11] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[11] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[11] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[11] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[11] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Func013C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetConstructingStructure()) == Player(11) ) ) then
        return false
    endif
    if ( not ( udg_lumber[12] >= 60 ) ) then
        return false
    endif
    if ( not ( udg_stone[12] >= 40 ) ) then
        return false
    endif
    if ( not ( udg_iron[12] >= 30 ) ) then
        return false
    endif
    if ( not ( udg_clay[12] >= 20 ) ) then
        return false
    endif
    if ( not ( udg_food[12] >= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_windmill_Actions takes nothing returns nothing
    if ( Trig_windmill_Func002C() ) then
        set udg_lumber[1] = ( udg_lumber[1] - 60 )
        set udg_stone[1] = ( udg_stone[1] - 40 )
        set udg_iron[1] = ( udg_iron[1] - 30 )
        set udg_clay[1] = ( udg_clay[1] - 20 )
        set udg_food[1] = ( udg_food[1] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func003C() ) then
        set udg_lumber[2] = ( udg_lumber[2] - 60 )
        set udg_stone[2] = ( udg_stone[2] - 40 )
        set udg_iron[2] = ( udg_iron[2] - 30 )
        set udg_clay[2] = ( udg_clay[2] - 20 )
        set udg_food[2] = ( udg_food[2] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func004C() ) then
        set udg_lumber[3] = ( udg_lumber[3] - 60 )
        set udg_stone[3] = ( udg_stone[3] - 40 )
        set udg_iron[3] = ( udg_iron[3] - 30 )
        set udg_clay[3] = ( udg_clay[3] - 20 )
        set udg_food[3] = ( udg_food[3] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func005C() ) then
        set udg_lumber[4] = ( udg_lumber[4] - 60 )
        set udg_stone[4] = ( udg_stone[4] - 40 )
        set udg_iron[4] = ( udg_iron[4] - 30 )
        set udg_clay[4] = ( udg_clay[4] - 20 )
        set udg_food[4] = ( udg_food[4] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func006C() ) then
        set udg_lumber[5] = ( udg_lumber[5] - 60 )
        set udg_stone[5] = ( udg_stone[5] - 40 )
        set udg_iron[5] = ( udg_iron[5] - 30 )
        set udg_clay[5] = ( udg_clay[5] - 20 )
        set udg_food[5] = ( udg_food[5] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func007C() ) then
        set udg_lumber[6] = ( udg_lumber[6] - 60 )
        set udg_stone[6] = ( udg_stone[6] - 40 )
        set udg_iron[6] = ( udg_iron[6] - 30 )
        set udg_clay[6] = ( udg_clay[6] - 20 )
        set udg_food[6] = ( udg_food[6] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func008C() ) then
        set udg_lumber[7] = ( udg_lumber[7] - 60 )
        set udg_stone[7] = ( udg_stone[7] - 40 )
        set udg_iron[7] = ( udg_iron[7] - 30 )
        set udg_clay[7] = ( udg_clay[7] - 20 )
        set udg_food[7] = ( udg_food[7] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func009C() ) then
        set udg_lumber[8] = ( udg_lumber[8] - 60 )
        set udg_stone[8] = ( udg_stone[8] - 40 )
        set udg_iron[8] = ( udg_iron[8] - 30 )
        set udg_clay[8] = ( udg_clay[8] - 20 )
        set udg_food[8] = ( udg_food[8] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func010C() ) then
        set udg_lumber[9] = ( udg_lumber[9] - 60 )
        set udg_stone[9] = ( udg_stone[9] - 40 )
        set udg_iron[9] = ( udg_iron[9] - 30 )
        set udg_clay[9] = ( udg_clay[9] - 20 )
        set udg_food[9] = ( udg_food[9] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func011C() ) then
        set udg_lumber[10] = ( udg_lumber[10] - 60 )
        set udg_stone[10] = ( udg_stone[10] - 40 )
        set udg_iron[10] = ( udg_iron[10] - 30 )
        set udg_clay[10] = ( udg_clay[10] - 20 )
        set udg_food[10] = ( udg_food[10] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func012C() ) then
        set udg_lumber[11] = ( udg_lumber[11] - 60 )
        set udg_stone[11] = ( udg_stone[11] - 40 )
        set udg_iron[11] = ( udg_iron[11] - 30 )
        set udg_clay[11] = ( udg_clay[11] - 20 )
        set udg_food[11] = ( udg_food[11] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
    if ( Trig_windmill_Func013C() ) then
        set udg_lumber[12] = ( udg_lumber[12] - 60 )
        set udg_stone[12] = ( udg_stone[12] - 40 )
        set udg_iron[12] = ( udg_iron[12] - 30 )
        set udg_clay[12] = ( udg_clay[12] - 20 )
        set udg_food[12] = ( udg_food[12] - 0 )
    else
        call RemoveUnit( GetConstructingStructure() )
    endif
endfunction

//===========================================================================
function InitTrig_windmill takes nothing returns nothing
    set gg_trg_windmill = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_windmill, EVENT_PLAYER_UNIT_CONSTRUCT_START )
    call TriggerAddCondition( gg_trg_windmill, Condition( function Trig_windmill_Conditions ) )
    call TriggerAddAction( gg_trg_windmill, function Trig_windmill_Actions )
endfunction

Its converted GUI since it's for my roc map and I had to convert it to jass, so I know its weird coding like if (not (.... but that's not the problem.
Thanks in advance!
02-07-2008, 01:34 PM#2
Themerion
Before anybody will check for the real problem, you will have to do like this:

Trigger:
Untitled Trigger 001
Events
Conditions
Collapse Actions
Set integer_variable = (Player number of (Owner of (Constructing structure)))
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
lumber[integer_variable] Greater than 60
food[integer_variable] Greater than 40
Then - Actions
Else - Actions

Integer - Player - Player Number

The important thing here is that you just have 1 place to debug instead of 12. Your code/trigger will be understandable; and you'll cut the trigger size by 92%

EDIT:
Oh, and if Player Number doesn't exist for RoC, just skip to the next post :)
02-07-2008, 01:45 PM#3
Themerion
By the way, your problem is that the conditions look like:

Trigger:
Collapse If - Conditions
(Owner of (Constructing structure)) Equal to Player 1 (Red)
Then - Actions
Collapse Else - Actions
Unit - Remove (Constructing structure) from the game
Collapse If - Conditions
(Owner of (Constructing structure)) Equal to Player 2 (Blue)
Then - Actions
Collapse Else - Actions
Unit - Remove (Constructing structure) from the game

Do you see the problem? No matter which player you are, the unit will be removed.

Let's say you are Player 1. Then the first IF will be true. The second one will be false, because you are not Player 2 and the structure will be removed.
02-07-2008, 04:59 PM#4
ILikeShiri.
I see the problem, I made my trigger like this now so its less debugging

Collapse JASS:
function Trig_windmill_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetConstructingStructure()) == 'h002'
endfunction
function Trig_windmill_Actions takes nothing returns nothing
    local integer i = GetPlayerId(GetOwningPlayer(GetConstructingStructure())) + 1
    if udg_lumber[i] >= 60 and udg_stone[i] >= 40 and udg_iron[i] >= 30 and udg_clay[i] >= 20 and udg_food[i] >= 0 then
        set udg_lumber[i] = udg_lumber[i] - 60
        set udg_stone[i] = udg_stone[i] - 40
        set udg_iron[i] = udg_iron[i] - 30
        set udg_clay[i] = udg_clay[i] - 20
        set udg_food[i] = udg_food[i] - 0
    else
        call TriggerSleepAction(0)
        call KillUnit(GetConstructingStructure())
    endif
endfunction
//===========================================================================
function InitTrig_windmill takes nothing returns nothing
    set gg_trg_windmill = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_windmill, Condition( function Trig_windmill_Conditions))
    call TriggerAddAction( gg_trg_windmill, function Trig_windmill_Actions )
endfunction

The unit doesn't dissapear now but when it's build it doesn't change the variables value and when the variables aren't high enough it still builds it and does not kill the structure. But do you have any idea to fix that problem?
02-07-2008, 07:52 PM#5
Themerion
Woah, much better. Well done!

Collapse JASS:
//function InitTrig_windmill takes nothing returns nothing
//    set gg_trg_windmill = CreateTrigger(  )
//    call TriggerAddCondition( gg_trg_windmill, Condition( function Trig_windmill_Conditions))
//    call TriggerAddAction( gg_trg_windmill, function Trig_windmill_Actions )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_windmill, EVENT_PLAYER_UNIT_CONSTRUCT_START )
//endfunction

I think you forgot the event :)
02-09-2008, 10:59 AM#6
ILikeShiri.
How could I forget that?:P Thanks! gonna try if it works now but I think it will.

Edit: It works!!!! Thank you so much