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

[Solved] Trigger lagging the map

Status
Not open for further replies.
Level 3
Joined
Jan 4, 2010
Messages
14
Hi, I'm the editor of Wintermaul One Revamped, and I'm trying to implement a function that prevents a tower from ksing a creep on another lane.

Some towers have 3000 range and they can attack another player's lane.

Therefore I have this trigger to solve that.

[move red] is the region which covers the entire of red's lane
11tmuxt.jpg

Basically-
Event: Unit is attacked
Condition: If attacked unit is not in the same lane as attacking unit
Action: Stop attacking unit

The JASS version:
JASS:
function Trig_Attack_other_lane_Func005C takes nothing returns boolean
    if ( ( GetLocationX(GetUnitLoc(GetAttackedUnitBJ())) < GetRectMinX(gg_rct_move_red) ) ) then
        return true
    endif
    if ( ( GetLocationX(GetUnitLoc(GetAttackedUnitBJ())) > GetRectMaxX(gg_rct_move_red) ) ) then
        return true
    endif
    if ( ( GetLocationY(GetUnitLoc(GetAttackedUnitBJ())) < GetRectMinY(gg_rct_move_red) ) ) then
        return true
    endif
    if ( ( GetLocationY(GetUnitLoc(GetAttackedUnitBJ())) > GetRectMaxY(gg_rct_move_red) ) ) then
        return true
    endif
    return false
endfunction

function Trig_Attack_other_lane_Conditions takes nothing returns boolean
    if ( not ( GetLocationX(GetUnitLoc(GetAttacker())) >= GetRectMinX(gg_rct_move_red) ) ) then
        return false
    endif
    if ( not ( GetLocationX(GetUnitLoc(GetAttacker())) <= GetRectMaxX(gg_rct_move_red) ) ) then
        return false
    endif
    if ( not ( GetLocationY(GetUnitLoc(GetAttacker())) >= GetRectMinY(gg_rct_move_red) ) ) then
        return false
    endif
    if ( not ( GetLocationY(GetUnitLoc(GetAttacker())) <= GetRectMaxY(gg_rct_move_red) ) ) then
        return false
    endif
    if ( not Trig_Attack_other_lane_Func005C() ) then
        return false
    endif
    return true
endfunction

function Trig_Attack_other_lane_Actions takes nothing returns nothing
    call IssueImmediateOrderBJ( GetAttacker(), "stop" )
endfunction

//===========================================================================
function InitTrig_Attack_other_lane takes nothing returns nothing
    set gg_trg_Attack_other_lane = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Attack_other_lane, Player(11), EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Attack_other_lane, Condition( function Trig_Attack_other_lane_Conditions ) )
    call TriggerAddAction( gg_trg_Attack_other_lane, function Trig_Attack_other_lane_Actions )
endfunction

This is only one of the 9 copies of this trigger that I have (the other copies are for other lanes).

My problem is that as the game progresses, the map gets laggier, fps drops. I did numerous tests and found that this trigger is the problem (removing it solves the fps drop). Every level, the FPS will drop, from 50-60 at lvl 1, to 40-50 at lvl 2 and so on, until it gets unbearable.

I would appreciate if you could explain to me in GUI terms, or tell me what I should do because I dont understand too much of JASS.

Thanks :)
 
Use this:

JASS:
function AttackOtherLane takes nothing returns boolean
    local unit attacker = GetAttacker()
    local unit attacked = GetTriggerUnit()
    
    local real attackerX = GetUnitX(attacker)
    local real attackerY = GetUnitY(attacker)
    
    local real attackedX = GetUnitX(attacked)
    local real attackedY = GetUnitY(attacked)
    
    local real maxX = GetRectMaxX(gg_rct_move_red)
    local real maxY = GetRectMaxY(gg_rct_move_red)
    local real minX = GetRectMinX(gg_rct_move_red)
    local real minY = GetRectMinY(gg_rct_move_red)
    
    if (attackerX >= minX and attackerX <= maxX and attackerY >= minY and attackerY <= maxY) and (attackedX > maxX or attackedX < minX or attackedY > maxY or attackedY < minY) then
        call IssueImmediateOrderById(attacker, 851972)
    endif
    
    set attacker = null
    set attacked = null
    
    return false
endfunction

function InitTrig_Attack_other_lane takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(t, Player(11), EVENT_PLAYER_UNIT_ATTACKED, null)
    call TriggerAddCondition(t, Condition(function AttackOtherLane))
    set t = null
endfunction
 
Status
Not open for further replies.
Top