1. The long-awaited results for Concept Art Contest #11 have finally been released!
    Dismiss Notice
  2. Join Texturing Contest #30 now in a legendary battle of mythological creatures!
    Dismiss Notice
  3. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  4. Hivers united and created a bunch of 2v2 melee maps. Vote for the best in our Melee Mapping Contest #4 - Poll!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

Issue with conditionals.

Discussion in 'Triggers & Scripts' started by Rugarus, May 18, 2019 at 6:24 AM.

  1. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    624
    Resources:
    0
    Resources:
    0
    So the following checks if the triggering unit 'Attacked unit' is Player 2(Teal)
    Checks if the attacker is not equal to the triggering unit.

    It then checks if the unit type of the attacker is not equal to the listed unit types.

    Now all this works and runs, but the issue I'm having is the 'preventAttack' function.

    What I want this code to do is that if any of the 3 regions contain a 'Flag' unit or the 'TriggeringUnit' then prevent the attacking units attack.
    What happens right now is it only prevents the 'AttackingUnit's attack if the region the 'TriggeringUnit' is in also contains the 'Flag' unit. I need to prevent the attack if like said above ^ any of the 3 regions contain both the triggering unit and the flag. Doesn't need to be in the same region only that at least 1 of the regions contains the flag, and one of the regions contains the triggering unit. I'm not sure how to fix this, if you could help would be much appreciated. Thanks.


    Code (vJASS):

    function preventAttack takes nothing returns nothing
       
        if (( RectContainsUnit(gg_rct_Base01a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base01a, GetEnumUnit()) == true) or (RectContainsUnit(gg_rct_Base02a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base02a, GetEnumUnit()) == true) or (RectContainsUnit(gg_rct_Base03a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base03a, GetEnumUnit()) == true))then
            call DisplayTextToForce( GetPlayersAll(), "Stop" )
            call PauseUnitBJ( true, GetAttacker() )
            call IssueImmediateOrderBJ( GetAttacker(), "stop" )
            call PauseUnitBJ( false, GetAttacker() )
       else
        endif
    endfunction
     


    Entire code below:




    Code (vJASS):

    scope fixTeal initializer registerFix

    globals
    endglobals

    function preventAttack takes nothing returns nothing
       
        if (( RectContainsUnit(gg_rct_Base01a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base01a, GetEnumUnit()) == true) or (RectContainsUnit(gg_rct_Base02a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base02a, GetEnumUnit()) == true) or (RectContainsUnit(gg_rct_Base03a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base03a, GetEnumUnit()) == true))then
            call DisplayTextToForce( GetPlayersAll(), "Stop" )
            call PauseUnitBJ( true, GetAttacker() )
            call IssueImmediateOrderBJ( GetAttacker(), "stop" )
            call PauseUnitBJ( false, GetAttacker() )
       else
        endif
    endfunction

    function mainMain takes nothing returns nothing

     if (GetOwningPlayer(GetTriggerUnit()) == Player(2) and GetOwningPlayer(GetAttacker()) != GetOwningPlayer(GetTriggerUnit()) )  then
             
     if (GetUnitTypeId(GetAttacker()) != 'U007' and GetUnitTypeId(GetAttacker()) != 'U008' and GetUnitTypeId(GetAttacker()) != 'E002' and GetUnitTypeId(GetAttacker()) != 'E001' and GetUnitTypeId(GetAttacker()) != 'AVFV')  then
        call ForGroupBJ( GetUnitsOfPlayerAndTypeId(GetOwningPlayer(GetTriggerUnit()), 'hFlg'), function preventAttack )
       endif
        endif

    endfunction



    function registerFix takes nothing returns nothing
    local trigger TealFix = CreateListedTrigger()
        set TealFix = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( TealFix, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddAction( TealFix, function mainMain)
    endfunction

    endscope

     
     
  2. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    894
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    try this:
    Code (vJASS):

    globals
        boolean flagFound = false          
    endglobals

    function FindFlag takes nothing returns nothing
        if GetUnitTypeId(GetEnumUnit()) == 'hFlg' then
            set flagFound=true  
        endif
       
    //    if (( RectContainsUnit(gg_rct_Base01a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base01a, GetEnumUnit()) == true) or (RectContainsUnit(gg_rct_Base02a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base02a, GetEnumUnit()) == true) or (RectContainsUnit(gg_rct_Base03a, GetTriggerUnit()) == true and RectContainsUnit(gg_rct_Base03a, GetEnumUnit()) == true))then
      //      call DisplayTextToForce( GetPlayersAll(), "Stop" )
        //    call PauseUnitBJ( true, GetAttacker() )
          //  call IssueImmediateOrderBJ( GetAttacker(), "stop" )
            //call PauseUnitBJ( false, GetAttacker() )
    //   else
      //  endif
    endfunction

    function mainMain takes nothing returns nothing
        local unit u=GetTriggerUnit()
        local player p=GetOwningPlayer(u)
        local integer attId=GetUnitTypeId(GetAttacker()
        local group g=null
               
        if (p == Player(2) and GetOwningPlayer(GetAttacker()) != p ) then  
            if (attId != 'U007' and attId != 'U008' and attId != 'E002' and attId != 'E001' and attId != 'AVFV') then
                //check if attacked unit is in rect
                if RectContainsUnit(gg_rct_Base01a, u) or RectContainsUnit(gg_rct_Base02a, u) or RectContainsUnit(gg_rct_Base03a, u) then
                    // now only look for "flag" unit
                    set flagFound=false
                    set g = GetUnitsInRectOfPlayer(gg_rct_Base01a, p)
                    call ForGroup( GetUnitsInRectOfPlayer(GetPlayableMapRect(), p), function FindFlag )
                    set g = GetUnitsInRectOfPlayer(gg_rct_Base02a, p)
                    call ForGroup( GetUnitsInRectOfPlayer(GetPlayableMapRect(), p), function FindFlag )
                    set g = GetUnitsInRectOfPlayer(gg_rct_Base03a, p)
                    call ForGroup( GetUnitsInRectOfPlayer(GetPlayableMapRect(), p), function FindFlag )

                    if flagFound then
                        call DisplayTextToForce( GetPlayersAll(), "Stop" )
                        call PauseUnitBJ( true, GetAttacker() )
                        call IssueImmediateOrderBJ( GetAttacker(), "stop" )              
                    endif
                    call DestroyGroup(g)
                    set g=null
                   
                    //call ForGroupBJ( GetUnitsOfPlayerAndTypeId(GetOwningPlayer(u), 'hFlg'), function preventAttack )
                endif
           endif
        endif  
        set u=null
    endfunction



    function registerFix takes nothing returns nothing
    local trigger TealFix = CreateListedTrigger()
        set TealFix = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( TealFix, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddAction( TealFix, function mainMain)
    endfunction
     


    of course you can cut most of these BJ function later, and use trigger condition instead of action (in registerFix).
     
  3. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    624
    Resources:
    0
    Resources:
    0
    Appreciate the time rewriting it, but still doing the same thing I had. It wont let you attack the triggering unit in the region that contains both the triggering unit + flag but will allow you to kill the trig unit in any other region that doesn't contain the flag.
     
  4. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    624
    Resources:
    0
    Resources:
    0
    Anyone have a different approach to this to solve the issue? Thanks.