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. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. 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.

[Trigger] Yet another question by me

Discussion in 'Triggers & Scripts' started by RollinDoubles, Aug 11, 2013.

  1. Arhowk

    Arhowk

    Joined:
    Aug 8, 2007
    Messages:
    2,752
    Resources:
    0
    Resources:
    0
    Oh sorry I haven't been on in a while because my internet is being trippy. Yeah I'll post it ASAP
     
  2. RollinDoubles

    RollinDoubles

    Joined:
    Feb 10, 2011
    Messages:
    187
    Resources:
    0
    Resources:
    0
    thanks man

    hey, i dont want to post a new thread atm, maybe u guys will see this. I was looking at GUI coding on wc3c and i seen a guy do like a custom script event type thing it was A unit enters a region is there a way to do this? or was he just editing the code in the tags he posted? here is what he posted
    • Events
      • A Unit enters a region
    • Conditions
    • Actions
      • For each integer A beteen 0 and <arraysize>, do actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Triggering Unit) is in Region[Integer A]
          • Then - Actions
            • (Your Actions Here)
          • Else - Actions
     
  3. Arhowk

    Arhowk

    Joined:
    Aug 8, 2007
    Messages:
    2,752
    Resources:
    0
    Resources:
    0
    You can just use (playable map area) if you needed to. This would run when the unit is created. If you need only specific regions, you can do

    • Trigger - Add (Any unit enters <Your Region>) to <Your Trigger>


    Is there a function for when a unit enters any region currently in memory? no.

    E/ for your trigger, do you care if the checking area is a square instead of a circle? it would make it alot faster
     
    Last edited: Sep 14, 2013
  4. RollinDoubles

    RollinDoubles

    Joined:
    Feb 10, 2011
    Messages:
    187
    Resources:
    0
    Resources:
    0
    I wasn't aware that you could check in a square radius, If you want to do that its fine with me, really you can do any modifications you need to. Ill be pretty interested to learn from it.
     
  5. Arhowk

    Arhowk

    Joined:
    Aug 8, 2007
    Messages:
    2,752
    Resources:
    0
    Resources:
    0
    Ok sorry its been a while and im lost so I can't remember lol. This seems to work without lag, havent tested leaks
     

    Attached Files:

    • BD.w3x
      File size:
      17.7 KB
      Views:
      14
  6. Rheiko

    Rheiko

    Joined:
    Aug 27, 2013
    Messages:
    2,948
    Resources:
    7
    Icons:
    2
    Spells:
    3
    Tutorials:
    2
    Resources:
    7
    you may post the triggers as well, so we can help finding those leaks too
     
  7. Arhowk

    Arhowk

    Joined:
    Aug 8, 2007
    Messages:
    2,752
    Resources:
    0
    Resources:
    0
    Please don't post in white... i purposely run on low graphics so the page loads faster and i have to highlight your text to see what it is.

    Code (vJASS):
    library BaseDefenders initializer onBDInit
        globals
            private real radius = 175
            private real checkRadius = 375
            private real period = 0.7
            private unit host
            private filterfunc checkFilter
        endglobals
       
        private function enumFilter takes nothing returns boolean
            return GetFilterUnit() != host and GetOwningPlayer(host) == GetOwningPlayer(GetFilterUnit())
        endfunction
       
        private function looper takes nothing returns nothing
            local unit u
            local item i
            local group g = CreateGroup()
            local group g2 = CreateGroup()
            call GroupAddGroup(udg_BD_Bases, g)
            loop  
                set host = FirstOfGroup(g)
                exitwhen host == null
                call GroupClear(g2)
                call GroupEnumUnitsInRange(g2, GetUnitX(host), GetUnitY(host), radius, checkFilter)
                if FirstOfGroup(g2) == null then
                    call GroupClear(g2)
                    call GroupEnumUnitsInRange(g2, GetUnitX(host), GetUnitY(host), checkRadius, checkFilter)
                    set u = FirstOfGroup(g2)
                    if u != null then
                        set i = CreateItem('hval', GetUnitX(host), GetUnitY(host))
                        call IssueImmediateOrder(u, "stop" )
                        call SetUnitX(u, GetItemX(i))
                        call SetUnitY(u, GetItemY(i))
                        call RemoveItem(i)
                    endif
                endif
                call GroupRemoveUnit(g,host)
            endloop
            set u = null
            set i = null
            call DestroyGroup(g)
            call DestroyGroup(g2)
            set g = null
            set g2 = null
        endfunction
        private function onBDInit takes nothing returns nothing
            set checkFilter = Filter(function enumFilter)
            call TimerStart(CreateTimer(), period, true, function looper)
        endfunction
    endlibrary


    E/ noticed that the GroupAddGroup can be changed to this

    Code (vJASS):


            set bj_groupAddGroupDest = g
            call ForGroup(udg_BD_Bases, function GroupAddGroupEnum)
     
     
  8. Rheiko

    Rheiko

    Joined:
    Aug 27, 2013
    Messages:
    2,948
    Resources:
    7
    Icons:
    2
    Spells:
    3
    Tutorials:
    2
    Resources:
    7
    no leaks, AFAIR
    and sorry about that, i don't know you use low graphics
     
  9. RollinDoubles

    RollinDoubles

    Joined:
    Feb 10, 2011
    Messages:
    187
    Resources:
    0
    Resources:
    0
    Ok, I just did some editing with my recently learned very basic knowledge of jass and it is working as intended. Units were able to get away before, So far no units have got away.

    Thankyou a ton arhawk, this kinda inspires me to really learn (v)jass

    Ok here is the code with all my edits
    1. changed radius to 150
    2. changed checkradius to 400
    3. changed the filter to filter structures instead of just the host building.
    4. added another filter to select units not owned by the current owner
    5. removed the use of the item
    6. (hopefully) made it so that if there is no units in the radius, another player can take the base over by moving into the checkradius, let me know if this is done correctly

    Code (vJASS):
    library BaseDefenders initializer onBDInit
        globals
            private real radius = 150
            private real checkRadius = 400
            private real period = 0.7
            private unit host
            private unit tower
            private filterfunc checkFilter
            private filterfunc checkFilterTwo
        endglobals
       
        private function enumFilter takes nothing returns boolean
            return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) !=true and GetOwningPlayer(host) == GetOwningPlayer(GetFilterUnit())
        endfunction
       
        private function enumFilterTwo takes nothing returns boolean
            return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) !=true and GetOwningPlayer(host) != GetOwningPlayer(GetFilterUnit())
        endfunction
       
        private function looper takes nothing returns nothing
            local unit u
            local item i
            local group g = CreateGroup()
            local group g2 = CreateGroup()
            local group g3 = CreateGroup()
            set bj_groupAddGroupDest = g
            call ForGroup(udg_BD_Bases, function GroupAddGroupEnum)
            set bj_groupAddGroupDest = g3
            call ForGroup(udg_BD_Bases, function GroupAddGroupEnum)
            loop  
                set host = FirstOfGroup(g)
                exitwhen host == null
                set tower = FirstOfGroup(g3)
                call GroupClear(g2)
                call GroupEnumUnitsInRange(g2, GetUnitX(host), GetUnitY(host), radius, checkFilter)
                if FirstOfGroup(g2) == null then
                    call GroupClear(g2)
                    call GroupEnumUnitsInRange(g2, GetUnitX(host), GetUnitY(host), checkRadius, checkFilter)
                    set u = FirstOfGroup(g2)
                    if u != null then
                        call SetUnitX(u, GetUnitX(host))
                        call SetUnitY(u, GetUnitY(host))
                        call IssueImmediateOrder (u, "stop")
                    else
                        call GroupClear(g2)
                        call GroupEnumUnitsInRange(g2, GetUnitX(host), GetUnitY(host), checkRadius, checkFilterTwo)
                        set u = FirstOfGroup(g2)
                        call SetUnitX(u, GetUnitX(host))
                        call SetUnitY(u, GetUnitY(host))
                        call IssueImmediateOrder (u, "stop")
                        call SetUnitOwner (host, GetOwningPlayer(u),true)
                        call SetUnitOwner (tower,GetOwningPlayer(u),true)
                    endif
                endif
                call GroupRemoveUnit(g,host)
                call GroupRemoveUnit(g3,tower)
            endloop
            set u = null
            set i = null
            call DestroyGroup(g)
            call DestroyGroup(g2)
            set g = null
            set g2 = null
        endfunction
        private function onBDInit takes nothing returns nothing
            set checkFilter = Filter(function enumFilter)
            set checkFilterTwo = Filter(function enumFilterTwo)
            call TimerStart(CreateTimer(), period, true, function looper)
        endfunction
    endlibrary


    Ok, so i found one last problem. It seems to stop working once there is a few dead units in the radius and checkradius. How would i make it check for alive units only, im pretty sure its this, because i made a trigger to remove dead units and it works. if i turn it off and let units decay it messes up.
     
    Last edited: Sep 19, 2013
  10. Arhowk

    Arhowk

    Joined:
    Aug 8, 2007
    Messages:
    2,752
    Resources:
    0
    Resources:
    0
    o_O im sorry that post never showed up on my notifications bar. Have you gotten it working? else i can fix it