1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Issue with conditionals.

Discussion in 'Triggers & Scripts' started by Rugarus, May 18, 2019.

  1. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    724
    Resources:
    1
    Maps:
    1
    Resources:
    1
    If I remove that, it gives me an error saying Missing endblock.

    Code (vJASS):

    if plrVictim == Player(2) and plrVictim != GetOwningPlayer(attacker) then
            set vX = GetUnitX(victim)
            set vY = GetUnitY(victim)

            if RectContainsCoords(gg_rct_Base01a, vX, vY) or RectContainsCoords(gg_rct_Base01b, vX, vY) or RectContainsCoords(gg_rct_Base01c, vX, vY) then
                set grp = CreateGroup()
                call GroupEnumUnitsOfPlayer(grp, plrVictim, function FlagInRegion)
           
     


    These 2 would require the endif.

    And I'm trying to check if those regions contain the flag. Do I need to create multiple functions to check for each base, to return the boolean?
     
  2. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,473
    Resources:
    47
    Models:
    20
    Icons:
    20
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    47
    Ah, right, I forgot about the first if statement. The indentation is a bit confusing.
    I checked again, I think this must be it, you're missing a call keyword:
    Code (vJASS):

                if FirstOfGroup(grp) != null then
                DisplayTextToForce( attacker, "This base is claimed!" ) // <-- add "call" at the front
                    call PauseUnit(attacker, true)
                    call IssueImmediateOrder(attacker, "stop")
                    call PauseUnit(attacker, false)
                else
             
                endif
     


    For the first function, change it to this:

    Code (vJASS):

    function FlagInRegion takes nothing returns boolean
        local unit flag = GetFilterUnit()
        local real fX
        local real fY
        local boolean r = GetUnitTypeId(flag) == 'hFlg' and GetUnitState(flag, UNIT_STATE_LIFE) > 0
        local boolean base1
        local boolean base2
        local boolean base3
        local boolean base4

     

        if r then
            set fX = GetUnitX(flag)
            set fY = GetUnitY(flag)
            set base1 = RectContainsCoords(gg_rct_Base01a, fX, fY) or RectContainsCoords(gg_rct_Base01b, fX, fY) or RectContainsCoords(gg_rct_Base01c, fX, fY)
            set base2 = RectContainsCoords(gg_rct_Base02a, fX, fY) or RectContainsCoords(gg_rct_Base02b, fX, fY) or RectContainsCoords(gg_rct_Base02c, fX, fY) or RectContainsCoords(gg_rct_Base02d, fX, fY) or RectContainsCoords(gg_rct_Base02e, fX, fY)
            set base3 = RectContainsCoords(gg_rct_Base03a, fX, fY) or RectContainsCoords(gg_rct_Base03b, fX, fY)
            set base4 = RectContainsCoords(gg_rct_Base04a, fX, fY) or RectContainsCoords(gg_rct_Base04b, fX, fY) or RectContainsCoords(gg_rct_Base04c, fX, fY)
     
            set r = base1 or base2 or base3 or base4 // change "or" to "and" depending on your needs


    endif
     set flag = null
        return r

    endfunction


    or better yet:

    Code (vJASS):

    function FlagInRegion takes nothing returns boolean
        local unit flag = GetFilterUnit()
        local real fX
        local real fY
        local boolean r = GetUnitTypeId(flag) == 'hFlg' and GetUnitState(flag, UNIT_STATE_LIFE) > 0

     

        if r then
            set fX = GetUnitX(flag)
            set fY = GetUnitY(flag)
            set r = RectContainsCoords(gg_rct_Base01a, fX, fY) or RectContainsCoords(gg_rct_Base01b, fX, fY) or RectContainsCoords(gg_rct_Base01c, fX, fY)
       
            // remove the "not" keywords if ALL bases must contain the flag
            if not r then
               set r = RectContainsCoords(gg_rct_Base02a, fX, fY) or RectContainsCoords(gg_rct_Base02b, fX, fY) or RectContainsCoords(gg_rct_Base02c, fX, fY) or RectContainsCoords(gg_rct_Base02d, fX, fY) or RectContainsCoords(gg_rct_Base02e, fX, fY)

                if not r then
                    set r = RectContainsCoords(gg_rct_Base03a, fX, fY) or RectContainsCoords(gg_rct_Base03b, fX, fY)

                    if not r then
                       set r = RectContainsCoords(gg_rct_Base04a, fX, fY) or RectContainsCoords(gg_rct_Base04b, fX, fY) or RectContainsCoords(gg_rct_Base04c, fX, fY)
                    endif
                endif
            endif


    endif
     set flag = null
        return r

    endfunction
     
    Last edited: May 29, 2019
  3. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    724
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Yep that was the issue, and alright I'll do that thanks for the help!
     
  4. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,473
    Resources:
    47
    Models:
    20
    Icons:
    20
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    47
    No problem :)

    Actually, this is probably a better way to write it (functionally pretty much the same but easier on the eyes):
    Code (vJASS):

            set r = RectContainsCoords(gg_rct_Base01a, fX, fY) or RectContainsCoords(gg_rct_Base01b, fX, fY) or RectContainsCoords(gg_rct_Base01c, fX, fY)
            set r = r or RectContainsCoords(gg_rct_Base02a, fX, fY) or RectContainsCoords(gg_rct_Base02b, fX, fY) or RectContainsCoords(gg_rct_Base02c, fX, fY) or RectContainsCoords(gg_rct_Base02d, fX, fY) or RectContainsCoords(gg_rct_Base02e, fX, fY)
            set r = r or RectContainsCoords(gg_rct_Base03a, fX, fY) or RectContainsCoords(gg_rct_Base03b, fX, fY)
            set r = r or RectContainsCoords(gg_rct_Base04a, fX, fY) or RectContainsCoords(gg_rct_Base04b, fX, fY) or RectContainsCoords(gg_rct_Base04c, fX, fY)
     
     
  5. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    724
    Resources:
    1
    Maps:
    1
    Resources:
    1

    So I just tested it, it's all running but basically if the triggering unit is inside one of the base regions and the flag is not it will say "Base is claimed"
    I guess the Flaginregion function isn't working properly.
     
  6. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,473
    Resources:
    47
    Models:
    20
    Icons:
    20
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    47
    Ah right, so I'm guessing you want it to return true only if the flag is in the same base as the triggering unit? In that case you will have to have to write a separate FlagInRegion function for each base.

    Code (vJASS):

    function FlagInBase1 takes nothing returns boolean
        local unit flag = GetFilterUnit()
        local real fX
        local real fY
        local boolean r = GetUnitTypeId(flag) == 'hFlg' and GetUnitState(flag, UNIT_STATE_LIFE) > 0

     

        if r then
            set fX = GetUnitX(flag)
            set fY = GetUnitY(flag)
            set r = RectContainsCoords(gg_rct_Base01a, fX, fY) or RectContainsCoords(gg_rct_Base01b, fX, fY) or RectContainsCoords(gg_rct_Base01c, fX, fY)
        endif

        set flag = null
        return r

    endfunction

    function FlagInBase2 takes nothing returns boolean
        local unit flag = GetFilterUnit()
        local real fX
        local real fY
        local boolean r = GetUnitTypeId(flag) == 'hFlg' and GetUnitState(flag, UNIT_STATE_LIFE) > 0

     

        if r then
            set fX = GetUnitX(flag)
            set fY = GetUnitY(flag)
            set r = RectContainsCoords(gg_rct_Base02a, fX, fY) or RectContainsCoords(gg_rct_Base02b, fX, fY) or RectContainsCoords(gg_rct_Base02c, fX, fY) or RectContainsCoords(gg_rct_Base02d, fX, fY) or RectContainsCoords(gg_rct_Base02e, fX, fY)
        endif

        set flag = null
        return r

    endfunction
     

    etc.