1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  4. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  5. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  6. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  7. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  8. 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:
    695
    Resources:
    0
    Resources:
    0
    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

    Joined:
    Nov 2, 2004
    Messages:
    715
    Resources:
    25
    Models:
    3
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    25
    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:
    695
    Resources:
    0
    Resources:
    0
    Yep that was the issue, and alright I'll do that thanks for the help!
     
  4. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    715
    Resources:
    25
    Models:
    3
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    25
    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:
    695
    Resources:
    0
    Resources:
    0

    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

    Joined:
    Nov 2, 2004
    Messages:
    715
    Resources:
    25
    Models:
    3
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    25
    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.