• 🏆 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!

[Crash] my Tower is causing lag

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2010
Messages
230
so i have a tower, shoots every 0.2s

each shot i do GetRandomInt(1,100)==54

if true
call CreateNUnitsAtLoc(1,'h00N',Player(9),GetRectCenter(gg_rct_Spawn),bj_UNIT_FACING)
call IssueTargetOrder(GetLastCreatedUnit(),"unholyfrenzy",GetAttacker())
call TriggerSleepAction(1.00)
call RemoveUnit(GetLastCreatedUnit())

else

call DoNothing()

so lets say i have 24 of these tower shooting nonstop for 1 min. Does it really have to lag? is there a solution? the dummy units cast a damage over time spell based on unholy frenzy that lasts for 10s and deals 30 dmg per sec.

24*5*60 = 7200 shots fired only = 72 dummy units created in a matter of 1 min

so why does it lag.. i dont get it. not to mention they get removed after 1 second
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
That is because you are not removing units correctly.Lets assume you have 2 towers A and B.

Tower A attacks and gets frenzied.A dummy unit is created for tower A(Dummy 1).
After a small amount of time (between 0-1 second, lets say 0.50) Tower B attacks and gets frenzied.Another dummy unit(Dummy 2) is created for Tower B.
At 1. second you are trying to remove the dummy unit which used frenzy on Tower A but since you are trying to remove last created unit in game, you are only removing Dummy 2 and Dummy 1 remains in game.

So lets say you have 24 of these towers, so many dummy units will be remain in game.

To prevent this instead of remove unit, use apply timed life which will clean your unit itself.

if true
call CreateNUnitsAtLoc(1,'h00N',Player(9),GetRectCenter(gg_rct_Spawn),bj_UNIT_FACING)
call IssueTargetOrder(GetLastCreatedUnit(),"unholyfrenzy",GetAttacker())
call UnitApplyTimedLife(GetLastCreatedUnit(), 'BTLF', 0.50)
else
call DoNothing()

There are more optimizations can be made(such as only using 1 dummy unit for all towers) but this should fix your lag problem already.
 
Level 6
Joined
Nov 24, 2012
Messages
218
WC3 can handle it, I have done something very similar but with bloodlust (yes, I had a tower speed up enemies on attack lol), like Ceday said the reason is that your dummy units aren't properly removed due to trigger overlapping.
Now you know a better way to remove dummy units :), applying timed life is the way to go.

Also note in future whenever you use a Wait function anything that comes after is at risk of being overlapped just like this example.
So when there comes a time when you must use the Wait, any variable like "GetLastCreatedUnit()" used afterwards I recommend putting in a variable array like settings it to a variable called Unit[A].
Then set A=A+1 after using the variable, so the next time it loops around the next unit is Unit[A+1] = different variable = safe!
Eventually you have to 0 this so I guess when it gets high enough set it back to 0 or whatever, I don't really know.
Something like that, I explain very bad lol, but that's the basics of MUI but do definitely look up MUI ( Multi-Unit Instanceability ).
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Waits make triggers not MUI.
I do think that this is MUI and works good enough.
JASS:
function TowerHit takes nothing returns nothing
    local unit dummy
    if (GetRandomInt(1,100)==54) then
        set dummy = CreateUnitAtLoc(GetTriggerPlayer(), 'h00N', GetRectCenter(gg_rct_Spawn), 0)
        call IssueTargetOrder(dummy,"unholyfrenzy",GetAttacker())
        call TriggerSleepAction(1.00)
        call RemoveUnit(dummy)
    endif
endfunction

I wouldn't use a sleep and remove at all except if you want to avoid Unit Dies event.
If you don't have to avoid it, use this instead:
JASS:
function TowerHit takes nothing returns nothing
    local unit dummy
    if (GetRandomInt(1,100)==54) then
        set dummy = CreateUnitAtLoc(GetTriggerPlayer(), 'h00N', GetRectCenter(gg_rct_Spawn), 0)
        call IssueTargetOrder(dummy,"unholyfrenzy",GetAttacker())
        call UnitApplyTimedLife(dummy, 'BTLF', 1)
    endif
endfunction

Should solve the problem.
I also changed the Player(9) to Triggering Player.
There are only a few reasons why you would need a specific player and if it should be Player(9) then just revert it again.
Just pointing something out to think about.
 
Level 4
Joined
Feb 28, 2014
Messages
70
I do think that this is MUI and works good enough.
JASS:
function TowerHit takes nothing returns nothing
    local unit dummy
    if (GetRandomInt(1,100)==54) then
        set dummy = CreateUnitAtLoc(GetTriggerPlayer(), 'h00N', GetRectCenter(gg_rct_Spawn), 0)
        call IssueTargetOrder(dummy,"unholyfrenzy",GetAttacker())
        call TriggerSleepAction(1.00)
        call RemoveUnit(dummy)
    endif
endfunction

I wouldn't use a sleep and remove at all except if you want to avoid Unit Dies event.
If you don't have to avoid it, use this instead:
JASS:
function TowerHit takes nothing returns nothing
    local unit dummy
    if (GetRandomInt(1,100)==54) then
        set dummy = CreateUnitAtLoc(GetTriggerPlayer(), 'h00N', GetRectCenter(gg_rct_Spawn), 0)
        call IssueTargetOrder(dummy,"unholyfrenzy",GetAttacker())
        call UnitApplyTimedLife(dummy, 'BTLF', 1)
    endif
endfunction

Should solve the problem.
I also changed the Player(9) to Triggering Player.
There are only a few reasons why you would need a specific player and if it should be Player(9) then just revert it again.
Just pointing something out to think about.

JASS:
local location p = GetRectCenter(gg_rct_Spawn)
// Actions
call RemoveLocation(p)
 
Level 6
Joined
Aug 12, 2010
Messages
230
the other stuff posted still causes lag. dummy unit creation does cause a lag lol.

the 1 dummy unit worked like magic.

random question: is 100k range gonna cover all kinds of map sizes? even corner to corner distance.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
512*128=65536

sqrt(2*65536²) ~= 92681.9

Well you can also move the dummy with SetUnitX/Y before casting, which may be important because of the cast window anyway (so the unit does not require time to turn around). Also you should ensure that the target is visible to the dummy.
 
(so the unit does not require time to turn around).
0 ms solves that.
Also you should ensure that the target is visible to the dummy.
UnitShareVision(unit, player, share) can be used (also revert after dummy order) since the order time is instant and will happen before vision is removed.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
100k
I once made an ability based of shockwave and made it global (over the whole map).
When I set the distance to 25k, it just made a random angle instead of where I aimed.
100k is like 3 or 4 times the total map size (corner to corner).
100k should do the trick ;)
 
Status
Not open for further replies.
Top