HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Help] Dynamite Sliding Trigger

06-24-2010, 07:43 AM#1
Ikx_1
Hello! My problem was before that the trigger is heavy, but no more! Now the problem is that the dynamites exploses right away! Why? Is there any suggestions?

Here's my sliding trigger:
Trigger:
TNT Move
Collapse Events
Time - Every 0.03 seconds of game time
Collapse Conditions
EndBossRunning Equal to True
Collapse Actions
Set BalnazzarSkillGroup = (Units of type Dynamite)
Collapse Unit Group - Pick every unit in BalnazzarSkillGroup and do (Actions)
Collapse Loop - Actions
Set Points[1] = (Position of (Picked unit))
Set TNTFacing = (Facing of (Picked unit))
Set Points[2] = (Points[1] offset by 10.00 towards TNTFacing degrees)
Unit - Move (Picked unit) instantly to Points[2]
Collapse Destructible - Pick every destructible within 90.00 of Points[2] and do (Actions)
Collapse Loop - Actions
Destructible - Kill (Picked destructible)
Set UnitGroup = (Units within 90.00 of Points[2] matching ((((Owner of (Matching unit)) controller) Equal to User) and (((Matching unit) is in BalnazzarSkillGroup) Not equal to True)))
Unit Group - Pick every unit in UnitGroup and do (Unit - Kill (Picked unit))
Custom script: call RemoveLocation ( udg_Points[1] )
Custom script: call RemoveLocation ( udg_Points[2] )
Custom script: call DestroyGroup ( udg_BalnazzarSkillGroup )

And in JASS:
Collapse JASS:
function Trig_TNT_Move_JASS_Conditions takes nothing returns boolean
    if ( not ( udg_EndBossRunning == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_TNT_Move_JASS_Func003A takes nothing returns nothing
    set udg_Points[1] = GetUnitLoc(GetEnumUnit())
    set udg_TNTFacing = GetUnitFacing(GetEnumUnit())
    set udg_Points[2] = PolarProjectionBJ(udg_Points[1], 10.00, udg_TNTFacing)
    call SetUnitPositionLoc( GetEnumUnit(), udg_Points[2] )
endfunction

function Trig_TNT_Move_JASS_Func004A takes nothing returns nothing
    call KillDestructable( GetEnumDestructable() )
endfunction

function Trig_TNT_Move_JASS_Func005002003001 takes nothing returns boolean
    return ( GetPlayerController(GetOwningPlayer(GetFilterUnit())) == MAP_CONTROL_USER )
endfunction

function Trig_TNT_Move_JASS_Func005002003002 takes nothing returns boolean
    return ( IsUnitInGroup(GetFilterUnit(), udg_BalnazzarSkillGroup) != true )
endfunction

function Trig_TNT_Move_JASS_Func005002003 takes nothing returns boolean
    return GetBooleanAnd( Trig_TNT_Move_JASS_Func005002003001(), Trig_TNT_Move_JASS_Func005002003002() )
endfunction

function Trig_TNT_Move_JASS_Func006002 takes nothing returns nothing
    call KillUnit( GetEnumUnit() )
endfunction

function Trig_TNT_Move_JASS_Actions takes nothing returns nothing
    set udg_BalnazzarSkillGroup = GetUnitsOfTypeIdAll('n00H')
    call ForGroupBJ( udg_BalnazzarSkillGroup, function Trig_TNT_Move_JASS_Func003A )
    call EnumDestructablesInCircleBJ( 90.00, udg_Points[2], function Trig_TNT_Move_JASS_Func004A )
    set udg_UnitGroup = GetUnitsInRangeOfLocMatching(90.00, udg_Points[2], Condition(function Trig_TNT_Move_JASS_Func005002003))
    call ForGroupBJ( udg_UnitGroup, function Trig_TNT_Move_JASS_Func006002 )
    call RemoveLocation ( udg_Points[1] )
    call RemoveLocation ( udg_Points[2] )
    call DestroyGroup ( udg_BalnazzarSkillGroup )
endfunction

//===========================================================================
function InitTrig_TNT_Move_JASS takes nothing returns nothing
    set gg_trg_TNT_Move_JASS = CreateTrigger(  )
    call DisableTrigger( gg_trg_TNT_Move_JASS )
    call TriggerRegisterTimerEventPeriodic( gg_trg_TNT_Move_JASS, 0.03 )
    call TriggerAddCondition( gg_trg_TNT_Move_JASS, Condition( function Trig_TNT_Move_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_TNT_Move_JASS, function Trig_TNT_Move_JASS_Actions )
endfunction


You can create my trigger completely in different way. Thanks anyway.
Please in GUI, but you can create it in JASS...

REALLY THANKS!

Thanks specially to D3zmagos for help!
06-24-2010, 05:45 PM#2
Bribe
If you want it done in GUI, you gotta post the map. Not many people are crazy enough to dabble their way through re-creating your entire setup.

Or, if you want it done properly (in JASS), you gotta convert those triggers to Custom Script and post the rawcode they give you. Not many people would type that stuff out in JASS.
06-24-2010, 05:51 PM#3
Anitarf
First optimization you could do would be increasing the timer interval to 0.02 seconds; it is virtually indistinguishable from 0.01, some people don't even mind if you go as far as 0.05 but the movement seems definitely choppy to me at that point.

Furthermore, you leak groups and locations like crazy, you should clean those up after you are done with them. Better still would be to not use them in the first place.

Take a look at the sample of the TimedLoop resource, it could easily be adapted to do exactly what you want to do.
06-25-2010, 02:09 AM#4
Ikx_1
Thanks really much about your help! :D I really want this trigger to work, sorry about the leaks, I didn't check this completely :D

EDIT: Post edited!
That still doesn't make that the trigger work right! Now the Dynamites will explore right away! Why? Is there any fixes?
06-25-2010, 01:49 PM#5
Anitarf
You should destroy groups and locations in the same loop where you create them, otherwise the trigger will create a bunch of them and only destroy the last one. Furthermore, BJ functions like EnumDestructablesInCircleBJ leak handle references so even with "proper" GUI code, you can not avoid leaks. Try using this vJass code instead:

Collapse JASS:
library Dynamite initializer Init requires TimedLoop

    globals
        private constant real SPEED = 500.0
        private constant integer DYNAMITE_ID = 'n00H'
        private constant real RADIUS = 90.0
    endglobals

    struct Dynamite
        static group g = CreateGroup()
        static rect r = Rect(-RADIUS,-RADIUS,RADIUS,RADIUS)
        static real x
        static real y
        unit u

        private static method unitEnum takes nothing returns boolean
            local unit f=GetFilterUnit()
            if GetPlayerController(GetOwningPlayer(f))==MAP_CONTROL_USER and GetUnitTypeId(f)!=DYNAMITE_ID then
                call KillUnit(f)
            endif
            return false
        endmethod
        private static method destFilter takes nothing returns boolean
            local real dx=GetDestructableX(GetFilterDestructable())-.x
            local real dy=GetDestructableY(GetFilterDestructable())-.y
            if dx*dx+dy*dy<=RADIUS*RADIUS then
                call KillDestructable(GetFilterDestructable())
            endif
            return false
        endmethod
        private method onTimedLoop takes nothing returns boolean
            set .x = GetUnitX(.u)
            set .y = GetUnitY(.u)
            call SetUnitX(.u, .x + SPEED*TimedLoop_PERIOD*Cos(GetUnitFacing(.u)*bj_DEGTORAD) )
            call SetUnitY(.u, .y + SPEED*TimedLoop_PERIOD*Sin(GetUnitFacing(.u)*bj_DEGTORAD) )
            call GroupEnumUnitsInRange(g, .x,.y, RADIUS, Condition(function Dynamite.unitEnum))
            call MoveRectTo(.r, .x,.y)
            call EnumDestructablesInRect(r, Condition(function Dynamite.destFilter), null)
            return IsUnitType(.u, UNIT_TYPE_DEAD)==TimedLoop_STOP
        endmethod

        implement TimedLoop

        static method create takes unit u returns Dynamite
            local Dynamite this= Dynamite.allocate()
            set .u = u
            call .startTimedLoop()
            return this
        endmethod
    endstruct



    private function UnitEntersMap takes nothing returns nothing
        if GetUnitTypeId(GetTriggerUnit())==DYNAMITE_ID then
            call Dynamite.create(GetTriggerUnit())
        endif
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local region r = CreateRegion()
        call RegionAddRect(r, bj_mapInitialPlayableArea)
        call TriggerRegisterEnterRegion(t, r, null)
        call TriggerAddAction( t, function UnitEntersMap )
    endfunction

endlibrary

Requires TimedLoop and BoundSentinel.