• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Massive lag and then disconnect

Status
Not open for further replies.
Level 5
Joined
Feb 21, 2009
Messages
136
Hello, I recently started playing my old map again and wanted to update ( I wasn't mapping for a long time) and I thought of something and tried to make it in GUI but It proved to be difficult, so I tried JASS. In single player it works perfectly, but I tried this online and it caused a huge lag and then everyone disconnected. ( I am super noob in JASS ) So how could I fix this? and what is wrong with it??

JASS:
function Trig_Mod_Actions takes nothing returns nothing
  local fogmodifier fog
    call CreateFogModifierRadiusLocBJ( true, udg_GapPlayer, FOG_OF_WAR_MASKED, udg_Point[1], 1200.00 )
    set fog = GetLastCreatedFogModifier()
    call TriggerSleepAction( 0.04 )
    call DestroyFogModifier( fog )
endfunction

//===========================================================================
function InitTrig_Mod takes nothing returns nothing
    set gg_trg_Mod = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Mod, function Trig_Mod_Actions )
endfunction

This trigger is called after point[1] is being set at the location I want it and GapPlayer is set too, this code is called every 0.01 s (0.03s causes bugs with black mask).
 
Level 1
Joined
Dec 19, 2010
Messages
1
Alexxxxxxxxxxxx

i love you <3
& miss you
i wish i can help you with this code but i cant lol......
So... LOVELY PEOPLE OUT THERE !!!
HELP HIM EDIT THIS CODE PLEASE TYTY :)
ps: i wanna have --- with u LOLolOLolOLoLolOL
fill it in urself <3
&&
:ogre_icwydt::ogre_hurrhurr::ogre_rage::ogre_love::ogre_kawaii::ogre_frown::ogre_haosis::ogre_datass:
ps: blank=cake DUH :) redvelvet..
& THIS POST ISNT IRRELEVANT :) it's to promote others to help him mmhmm
 
Level 5
Joined
Feb 21, 2009
Messages
136
Other trigger which is in GUI that runs the JASS:
  • GAP test Copy 2
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (GapUnit[(Integer A)] is alive) Equal to True
            • Then - Actions
              • Set Point[1] = (Position of GapUnit[(Integer A)])
              • Set Tforce = (All enemies of (Owner of GapUnit[(Integer A)]))
              • Player Group - Pick every player in (All enemies of (Owner of GapUnit[(Integer A)])) and do (Actions)
                • Loop - Actions
                  • Set Temp_Group = (Units within 1400.00 of Point[1])
                  • Unit Group - Pick every unit in Temp_Group and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of (Picked unit)) Equal to (Picked player)
                        • Then - Actions
                          • Set Gap[Gapindex] = False
                        • Else - Actions
                  • Custom script: call DestroyGroup (udg_Temp_Group)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Gap[Gapindex] Equal to True
                    • Then - Actions
                      • Set GapPlayer = (Picked player)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • BlackMaskOn Equal to True
                        • Then - Actions
                          • Trigger - Run Mod <gen> (ignoring conditions)
                        • Else - Actions
                          • Trigger - Run Mod2 <gen> (ignoring conditions)
                    • Else - Actions
                  • Set Gap[Gapindex] = True
                  • Set Gapindex = (Gapindex + 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Gapindex Greater than 144
                    • Then - Actions
                      • Set Gapindex = 0
                    • Else - Actions
              • Custom script: call DestroyForce( udg_Tforce )
              • Custom script: call RemoveLocation (udg_Point[1])
            • Else - Actions
(Mod2 is the same as Mod1 but with FOGGED instead of MASKED)


tigger before I used JASS which didn't really lag at first but then leaked visibility modifiers:
  • GAP test
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • For each (Integer B) from 1 to 144, do (Actions)
        • Loop - Actions
          • Visibility - Destroy VisibilityGAP[(Integer B)]
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (GapUnit[(Integer A)] is alive) Equal to True
            • Then - Actions
              • Set Point[1] = (Position of GapUnit[(Integer A)])
              • Player Group - Pick every player in (All enemies of (Owner of GapUnit[(Integer A)])) and do (Actions)
                • Loop - Actions
                  • Set Temp_Group = (Units within 1400.00 of Point[1])
                  • Unit Group - Pick every unit in Temp_Group and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Owner of (Picked unit)) Equal to (Picked player)
                        • Then - Actions
                          • Set Gap[Gapindex] = False
                        • Else - Actions
                  • Custom script: call DestroyGroup (udg_Temp_Group)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Gap[Gapindex] Equal to True
                    • Then - Actions
                      • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from Point[1] to a radius of 1200.00
                      • Set VisibilityGAP[Gapindex] = (Last created visibility modifier)
                    • Else - Actions
                  • Set Gap[Gapindex] = True
                  • Set Gapindex = (Gapindex + 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Gapindex Greater than 144
                    • Then - Actions
                      • Set Gapindex = 0
                    • Else - Actions
              • Custom script: call RemoveLocation (udg_Point[1])
            • Else - Actions
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
The low frame rate is probably caused because the algerthim is too unefficent to use with more than 1 player.

The split is probably caused due to the low frame rate and computers failing to keep in time properly.

Lets look at what you do...
Every 0.01 seconds... (100 times a second).

Go from 1 to 144 and destroy something (14400 destructions a second)

From 1 - 12 if gap unit is alive do the below (12000 itterations maximum per second)...
For all enemies (6-11 itterations depending on teams which becomes somehwere between 72000 and 132000 itterations per second).
Pick all units and do something 72000 to 132000 times a second (new objects each time).
Create a complex fog modifier 72000 to 132000 times a second.

And you wonder why it lags with more than 1 player (as those numbers are much much much much much much much smaller when there is only 1 player ingame and 1 gap unit?

In multiplayer you are leaking upwards of 200000 handle indexes per second. I am suprized the game does not crash...

The only solution is to rewrite the whole thing, using a more efficent algerthim, lower itteration, and with no leaks what so ever. Logically this must be in JASS as GUI leaks handle indexes due to a bug in the locals (handles are not nulled at the end of BJ functions).
 
Level 5
Joined
Feb 21, 2009
Messages
136
When a unit is trained and it's type is equal to Gap Generator, then GapUnit[Player num] = trained gap generator (every player can have only 1 Gap Generator)
I have this trigger already.

Now, I want to make a Black Mask (or fog of war if BlackMaskOn is equal to False) over the GapUnit in a 1200 radius for every enemy player of owner of GapUnit that does not have a unit inside a 1400 radius of the GapUnit.

So lets say that if I have a unit inside a 1400 radius of an enemy GapUnit, then I wont get masked, but if I don't have that unit then I will get masked.

The GapUnit is able to move so the Masks should move with him, also if you have vision over the area you should still get masked. for example, if you have vision over the whole map and there is an enemy GapUnit you will still get a mask in a 1200 radius over the enemy GapUnit.

I hope I was a little clear and its not too hard ;p
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Done. (Just replace all footmen with your Gap Generator in triggers)
Also note that it's only MPI,works for 1 unit per player. If you want,i can edit so it works for multiple units for each player.
According to this though
(every player can have only 1 Gap Generator)
It only has to be MPI.
 

Attachments

  • Gaps.w3x
    18.2 KB · Views: 47
Level 5
Joined
Feb 21, 2009
Messages
136
Thanks but if the trigger runs every 0.20s, the mask will not be applied if you have vision over the area, try to set the knights night vision to 1800 and test it, then set the trigger to 0.01 and try it again, youll see what i mean.

There is also a bug, if blue and teal have a gap unit close to eachother red will not get masked.

other bug: if the GapModifiers array runs from 1 to 12 there can only be 12 masks, while we will need a mask for every player times every enemy unit, 12 * 11 = 132 masks at the same time, I believe.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
I'll see about fixing those bugs.
other bug: if the GapModifiers array runs from 1 to 12 there can only be 12 masks, while we will need a mask for every player times every enemy unit, 12 * 11 = 132 masks at the same time, I believe.
About this,if every player has only 1 Gap generator,it shouldn't bug. A mask covers an area for a player,not for a unit o_O
When creating mask,i picked every player that is enemy of owner of Gap Generator,so it should work.

EDIT: If you set the trigger loop interval to 0.01,it works fine.

EDIT:
There is also a bug, if blue and teal have a gap unit close to eachother red will not get masked.
Oh,i see the problem,ill fix it.
 
Level 5
Joined
Feb 21, 2009
Messages
136
I'll see about fixing those bugs.

About this,if every player has only 1 Gap generator,it shouldn't bug. A mask covers an area for a player,not for a unit o_O

EDIT: If you set the trigger loop interval to 0.01,it works fine.

11 enemy Gap Units (because u have one), every player (12) will need one mask per gap unit, so 11*12 masks?

lets say blue has a gap unit, red teal purple yellow ect will all need their own Mask for that one unit, and then we have 11 units

Or is there something Im not seeing here?
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
11 enemy Gap Units (because u have one), every player (12) will need one mask per gap unit, so 11*12 masks?

lets say blue has a gap unit, red teal purple yellow ect will all need their own Mask for that one unit, and then we have 11 units

Or is there something Im not seeing here?

That is why i use
  • Player Group - Pick every player in (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True)) and do (Actions)
    • Loop - Actions
      • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
      • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
which creates a mask for every player that is enemy of owner of Gap Generator.
 
Level 5
Joined
Feb 21, 2009
Messages
136
That is why i use
  • Player Group - Pick every player in (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True)) and do (Actions)
    • Loop - Actions
      • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
      • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
which creates a mask for every player that is enemy of owner of Gap Generator.

Yes that makes a mask for every player, but for only one unit?

Set GapModifiers[(Player number of (Owner of (Picked unit)))] has a max array size of 12?

EDIT: oh wait.. you destroy it within the unit group loop? why does the mask still appear then, if you destroy it at the same second you make it?

EDIT2:
  • Gap Loop
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Gaps and do (Actions)
        • Loop - Actions
          • Visibility - Destroy GapModifiers[(Player number of (Owner of (Picked unit)))]
          • Set GapLoc = (Position of (Picked unit))
          • Set TempGroup = (Units within 1400.00 of GapLoc matching (((Matching unit) belongs to an enemy of (Owner of (Picked unit))) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempGroup) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True)) and do (Actions)
                • Loop - Actions
                  • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
                  • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
            • Else - Actions
          • Custom script: call DestroyGroup(udg_TempGroup)
          • Custom script: call RemoveLocation(udg_GapLoc)

Unit 1, destroys mask 1. makes a mask for 2 - 12
Unit 2, destroys mask 2 makes a mask for 1, 3-12 leaking 3-12 from last loop
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
No. When a mask is created for a player,it masks an area no matter how many units are around.
Umm...do you mean as when players have multiple Gap Generators,they will generate 1 mask only?
Because
(every player can have only 1 Gap Generator)
you said this,every player can have only 1 Gap Generator. I can rework it so it works for multiple units for each player if you want,however.

EDIT: I destroy previous mask so the unit doesn't create multiple masks which would leak (afaik). I re-create the mask afterwards.
 
Level 5
Joined
Feb 21, 2009
Messages
136
  • Gap Loop
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Gaps and do (Actions)
        • Loop - Actions
          • Visibility - Destroy GapModifiers[(Player number of (Owner of (Picked unit)))]
          • Set GapLoc = (Position of (Picked unit))
          • Set TempGroup = (Units within 1400.00 of GapLoc matching (((Matching unit) belongs to an enemy of (Owner of (Picked unit))) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempGroup) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True)) and do (Actions)
                • Loop - Actions
                  • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
                  • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
            • Else - Actions
          • Custom script: call DestroyGroup(udg_TempGroup)
          • Custom script: call RemoveLocation(udg_GapLoc)
Edit: wait i meant,
  • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
    • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
makes 11 Modifiers but only stores the last?
Example:

Gap unit is red

Playerloop 2, makes a mask for 2 and stores it in GapMods[1]

Playerloop 3, makes a mask for 3 and stores it in GapMods[1] before removing it leaking mask 2
 
Level 5
Joined
Feb 21, 2009
Messages
136
  • Gap Loop
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Gaps and do (Actions)
        • Loop - Actions
          • Visibility - Destroy GapModifiers[(Player number of (Owner of (Picked unit)))]
          • Set GapLoc = (Position of (Picked unit))
          • Set TempGroup = (Units within 1400.00 of GapLoc matching (((Matching unit) belongs to an enemy of (Owner of (Picked unit))) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempGroup) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True)) and do (Actions)
                • Loop - Actions
                  • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
                  • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
            • Else - Actions
          • Custom script: call DestroyGroup(udg_TempGroup)
          • Custom script: call RemoveLocation(udg_GapLoc)
Edit: wait i meant,
  • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
    • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
makes 11 Modifiers but only stores the last?
Example:

Gap unit is red

Playerloop 2, makes a mask for 2 and stores it in GapMods[1]

Playerloop 3, makes a mask for 3 and stores it in GapMods[1] before removing it leaking mask 2



EDIT 3: I think i found a fix, try this


  • Gap Loop
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Gaps and do (Actions)
        • Loop - Actions
          • Set GapLoc = (Position of (Picked unit))
          • Set TempGroup = (Units within 1400.00 of GapLoc matching (((Matching unit) belongs to an enemy of (Owner of (Picked unit))) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempGroup) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True)) and do (Actions)
                • Loop - Actions
                  • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
                  • Visibility - Destroy (Last created visibility modifier)
            • Else - Actions
          • Custom script: call DestroyGroup(udg_TempGroup)
          • Custom script: call RemoveLocation(udg_GapLoc)
If you destroy it after you make it and do it every 0.01 its still there :D

Should be MUI now too! Just that other bug, should fix if we put the IF THEN ELSE inside the playerloop



Edit : whoops didnt notice I was posting a new reply, sorry for double post
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Gap unit is red

Playerloop 2, makes a mask for 2 and stores it in GapMods[1]

Playerloop 3, makes a mask for 3 and stores it in GapMods[1] before removing it leaking mask 2

No,because the function:
  • Set GapModifiers[(Player number of (Owner of (Picked unit)))] = (Last created visibility modifier)
Sets the index to
  • (Player number of (Owner of (Picked unit)))
which means for Gap Generator owned by red player,index will be 1,for blue player,it will be 2. If it works your way,you can use it,of course :D

EDIT: Oh lol,i see what you mean D:
Do it your way then.

Gonna fix the bug with multiple generators now.
 
Level 5
Joined
Feb 21, 2009
Messages
136
  • Gap Loop
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Gaps and do (Actions)
        • Loop - Actions
          • Set GapLoc = (Position of (Picked unit))
          • Player Group - Pick every player in (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True)) and do (Actions)
            • Loop - Actions
              • Set TempGroup = (Units within 1400.00 of GapLoc matching (((Matching unit) belongs to an ally of (Picked player)) Equal to True))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in TempGroup) Equal to 0
                • Then - Actions
                  • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from GapLoc to a radius of 1200.00
                  • Visibility - Destroy (Last created visibility modifier)
                • Else - Actions
              • Custom script: call DestroyGroup(udg_TempGroup)
          • Custom script: call RemoveLocation(udg_GapLoc)
everything fixed, MUI too now

Can you confirm?
 
Level 5
Joined
Feb 21, 2009
Messages
136
Its a lot better, but it still checks all units in a 1400 radius 11 * 12 * 100 = 13200 times per second at
  • Set Temp_Group = (Units within 1400.00 of Point[1] matching (((Matching unit) belongs to an ally of (Picked player)) Equal to True))
I need to replace it with some bool and check it every 1 second or something but how do I keep reference to the bool if there are up to 132 (or 144) different ones?


  • GAP
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in GAPUNITS and do (Actions)
        • Loop - Actions
          • Set Point[1] = (Position of (Picked unit))
          • Set Tforce = (All players matching (((Matching player) is an enemy of (Owner of (Picked unit))) Equal to True))
          • Player Group - Pick every player in Tforce and do (Actions)
            • Loop - Actions
              • Set Temp_Group = (Units within 1400.00 of Point[1] matching (((Matching unit) belongs to an ally of (Picked player)) Equal to True))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in Temp_Group) Equal to 0
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • BlackMaskOn Equal to True
                    • Then - Actions
                      • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Black mask from Point[1] to a radius of 1200.00
                    • Else - Actions
                      • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Fog of war from Point[1] to a radius of 1200.00
                  • Visibility - Destroy (Last created visibility modifier)
                • Else - Actions
              • Custom script: call DestroyGroup (udg_Temp_Group)
          • Custom script: call RemoveLocation (udg_Point[1])
          • Custom script: call DestroyForce( udg_Tforce )
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
EDIT: Finally works...lol
JASS:
function CountUnits takes nothing returns nothing
    set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction

function Gap_Loop takes nothing returns nothing
    local real x = GetUnitX(GetEnumUnit())
    local real y = GetUnitY(GetEnumUnit())
    local integer i = 0
    loop
        if udg_BlackMaskOn[GetPlayerId(GetOwningPlayer(GetEnumUnit())) * 12 + GetPlayerId(Player(i))] == true then
            set bj_lastCreatedFogModifier = CreateFogModifierRadius(Player(i),FOG_OF_WAR_MASKED,x,y,1200.0,true,false)
            call FogModifierStart(bj_lastCreatedFogModifier)
            call DestroyFogModifier(bj_lastCreatedFogModifier)
        endif
        set i = i + 1
        exitwhen i > 11
    endloop
endfunction

function Gap_Filter takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == Player(udg_Temp_Integer)
endfunction

function Gap_Loop2 takes nothing returns nothing
    local real x = GetUnitX(GetEnumUnit())
    local real y = GetUnitY(GetEnumUnit())
    local integer i = 0
    loop
        if IsPlayerEnemy(Player(i),GetOwningPlayer(GetEnumUnit())) then
            set udg_Temp_Integer = i
            call GroupEnumUnitsInRange(udg_Temp_Group,x,y,1400.0,Filter(function Gap_Filter))
            set bj_groupCountUnits = 0
            call ForGroup(udg_Temp_Group,function CountUnits)
            if bj_groupCountUnits == 0 then
                set udg_BlackMaskOn[GetPlayerId(GetOwningPlayer(GetEnumUnit())) * 12 + GetPlayerId(Player(i))] = true
            else
                set udg_BlackMaskOn[GetPlayerId(GetOwningPlayer(GetEnumUnit())) * 12 + GetPlayerId(Player(i))] = false
            endif
            call GroupClear(udg_Temp_Group)
        endif
        set i = i + 1
        exitwhen i > 11
    endloop
endfunction

function Gap_Loop_Init takes nothing returns boolean
    call ForGroup(udg_Gaps,function Gap_Loop)
    return false
endfunction

function Gap_Loop2_Init takes nothing returns boolean
    call ForGroup(udg_Gaps,function Gap_Loop2)
    return false
endfunction

//===========================================================================
function InitTrig_Gap_Loop takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t,Condition(function Gap_Loop_Init))
    call TriggerRegisterTimerEvent(t,0.01,true)
    set t = CreateTrigger()
    call TriggerAddCondition(t,Condition(function Gap_Loop2_Init))
    call TriggerRegisterTimerEvent(t,0.50,true)    
    set t = null
endfunction

Just replace the Gap Loop trigger with this script.
Variables you will need: BlackMaskOn(boolean array),Gaps(unit group),Temp_Group(unit group),Temp_Integer(integer)

I've attached a test map.
 

Attachments

  • Gaps.w3x
    18.1 KB · Views: 55
Last edited:
Level 5
Joined
Feb 21, 2009
Messages
136
Sorry for the delay... don't worry about it!
I have 2 questions though,
-Should the black mask of allies' gap generators apply to you? no
-When an allied unit enters enemy's gap radius and reveals it,should it be revealed for you too or only for your ally? for me too
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Replace the JASS code with this one:
JASS:
function CountUnits takes nothing returns nothing
    set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction

function Gap_Loop takes nothing returns nothing
    local real x = GetUnitX(GetEnumUnit())
    local real y = GetUnitY(GetEnumUnit())
    local integer i = 0
    loop
        if udg_BlackMaskOn[GetPlayerId(GetOwningPlayer(GetEnumUnit())) * 12 + GetPlayerId(Player(i))] == true and IsPlayerEnemy(Player(i),GetOwningPlayer(GetEnumUnit())) then
            set bj_lastCreatedFogModifier = CreateFogModifierRadius(Player(i),FOG_OF_WAR_MASKED,x,y,1200.0,true,false)
            call FogModifierStart(bj_lastCreatedFogModifier)
            call DestroyFogModifier(bj_lastCreatedFogModifier)
        endif
        set i = i + 1
        exitwhen i > 11
    endloop
endfunction

function Gap_Filter takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == Player(udg_Temp_Integer) or IsPlayerAlly(GetOwningPlayer(GetFilterUnit()),Player(udg_Temp_Integer))
endfunction

function Gap_Loop2 takes nothing returns nothing
    local real x = GetUnitX(GetEnumUnit())
    local real y = GetUnitY(GetEnumUnit())
    local integer i = 0
    loop
        if IsPlayerEnemy(Player(i),GetOwningPlayer(GetEnumUnit())) then
            set udg_Temp_Integer = i
            call GroupEnumUnitsInRange(udg_Temp_Group,x,y,1400.0,Filter(function Gap_Filter))
            set bj_groupCountUnits = 0
            call ForGroup(udg_Temp_Group,function CountUnits)
            if bj_groupCountUnits == 0 then
                set udg_BlackMaskOn[GetPlayerId(GetOwningPlayer(GetEnumUnit())) * 12 + GetPlayerId(Player(i))] = true
            else
                set udg_BlackMaskOn[GetPlayerId(GetOwningPlayer(GetEnumUnit())) * 12 + GetPlayerId(Player(i))] = false
            endif
            call GroupClear(udg_Temp_Group)
        endif
        set i = i + 1
        exitwhen i > 11
    endloop
endfunction

function Gap_Loop_Init takes nothing returns boolean
    call ForGroup(udg_Gaps,function Gap_Loop)
    return false
endfunction

function Gap_Loop2_Init takes nothing returns boolean
    call ForGroup(udg_Gaps,function Gap_Loop2)
    return false
endfunction

//===========================================================================
function InitTrig_Gap_Loop takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t,Condition(function Gap_Loop_Init))
    call TriggerRegisterTimerEvent(t,0.01,true)
    set t = CreateTrigger()
    call TriggerAddCondition(t,Condition(function Gap_Loop2_Init))
    call TriggerRegisterTimerEvent(t,0.50,true)    
    set t = null
endfunction
And...i'm really sorry that i've delayed this much. The problem was so short,but i was just lazy D:

EDIT: Updated code. If you had already copied the code,copy this one instead.
 
Last edited:
Status
Not open for further replies.
Top