Code not working correct.

Fleebop123

New Member
Reaction score
0
some reason my dummy units only spawn in one direction..
also can some one maybe make my code look better?
+rep

JASS:
scope Earthbind initializer init
    
    globals
        private constant integer abilID = 'A000'
        private constant integer dummyID = 'h001'
        private constant integer effectID = 'h000'
        private constant integer ensnareID = 'A001'
        private constant integer stunID = 'A002'
        private constant integer lifeID = 'BTLF'
    endglobals

    private function Conditions takes nothing returns boolean
        return ( GetSpellAbilityId() == abilID )
    endfunction
    
    private function PickUnit takes nothing returns boolean
        return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true ) and ( IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false )
    endfunction
    
    private function Immobile takes nothing returns nothing
        local unit e = GetEnumUnit()
        local unit d
        local real x = GetUnitX(e)
        local real y = GetUnitY(e)
        
        set d = CreateUnit( GetOwningPlayer(GetTriggerUnit()), dummyID, x, y, bj_UNIT_FACING )
        call UnitApplyTimedLife( d, lifeID, 2.00 )
        call UnitAddAbility( d, ensnareID )
        call SetUnitAbilityLevel( d, ensnareID, GetUnitAbilityLevel(GetTriggerUnit(), abilID) )
        call IssueTargetOrder( d, "ensnare", e )
        
        set e=null
        set d=null
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit e 
        local unit d
        local player p = GetOwningPlayer(u)
        local integer index
        local integer end
        local real t = 0.00
        local location up = GetUnitLoc(u)
        local location tp = GetSpellTargetLoc()

        set index = 1
        set end = ( R2I(DistanceBetweenPoints(tp, up)) / 20 )
        loop
            exitwhen index > end
            set t = ( t + 100.00 )
            if ( t < DistanceBetweenPoints(tp, up) ) then
                set e = CreateUnitAtLoc( p, effectID, OffsetLocation(up, t, AngleBetweenPoints(tp, up)), bj_UNIT_FACING )
                call ForGroupBJ( GetUnitsInRangeOfLocMatching(200.00, GetUnitLoc(e), Condition(function PickUnit)), function Immobile )
                call UnitApplyTimedLife( e, lifeID, 1.50 )
                call TriggerSleepAction( 0.01 )
            else
                call TriggerSleepAction( 1.00 )
                set d = CreateUnitAtLoc( p, dummyID, tp, bj_UNIT_FACING )
                call UnitAddAbility( d, stunID )
                call SetUnitAbilityLevel( d, stunID, GetUnitAbilityLevel( u, abilID) )
                call IssueImmediateOrder( d, "stomp" )
            return
            endif
            set index = index + 1
        endloop
        call RemoveLocation( up )
        call RemoveLocation( tp )
        
        set u=null
        set e=null
        set d=null
        set p=null
        set up=null
        set tp=null
    endfunction

    //===========================================================================
    private function init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        
        call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_CAST )
        call TriggerAddCondition( trig, Condition( function Conditions ) )
        call TriggerAddAction( trig, function Actions )
        
        set trig=null
    endfunction
    
endscope
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
You mean they face the same direction after spawning?

you can calculate the distance between the unit and the target point once

[lJASS]local real dbp = DistanceBetweenPoints(tp, up)[/lJASS]

and then use it in the loop, instead of calculating it every time the loop runs.

You can merge the PickUnit and Immobile functions.

JASS:
function MergedPickUnitAndImmobile takes nothing returns boolean
    local unit e = GetFilterUnit()
    local unit d
    local real x
    local real y

    // check PickUnit conditions
    if not (( IsUnitEnemy(e, GetOwningPlayer(GetTriggerUnit())) == true ) and ( IsUnitType(e, UNIT_TYPE_STRUCTURE) == false ))
        return false
    endif
    
    // else do Immobile actions

    set x = GetUnitX(e)
    set y = GetUnitY(e)

    set d = CreateUnit( GetOwningPlayer(GetTriggerUnit()), dummyID, x, y, bj_UNIT_FACING )
    call UnitApplyTimedLife( d, lifeID, 2.00 )
    call UnitAddAbility( d, ensnareID )
    call SetUnitAbilityLevel( d, ensnareID, GetUnitAbilityLevel(GetTriggerUnit(), abilID) )
    call IssueTargetOrder( d, "ensnare", e )
        
    set e=null
    set d=null

    return false
endfunction

function Actions
.
.
.
call GroupEnumUnitsInRangeOfLoc(your_global_dummy_group, GetUnitLoc(e), 200.0, Filter(function MergedPickUnitAndImmobile))
.
.
.


Speaking of merging you could also merge the Conditions and Acitons function in to 1 that returns boolean
call TriggerRegisterAnyUnitEventBJ(....)
call TriggerAddCondition(t, Condition(MergedFunction))

But if you do that you have to get rid of the dreaded waits you use in the loop and use timers instead etc.
Condition functions are "faster" said someone... : )

Edit:

You shouldn't create units for effects. Use real effects because they take less memory (I think...) than real units.
JASS:
globals
    private constant string YOUR_EFFECT_PATH = "some\\effect.mdl or whatever"
endglobals

.
.
.
call DestroyEffect(AddSpecialEffectLoc(YOUR_EFFECT_PATH, OffsetLocation(up, t, AngleBetweenPoints(tp, up))))
.
.
.
 

watermelon

New Member
Reaction score
2
If you're talking about dummy unit e, it's not really much of a surprise that they're all facing the same direction.
JASS:
set e = CreateUnitAtLoc( p, effectID, OffsetLocation(up, t, AngleBetweenPoints(tp, up)), bj_UNIT_FACING )

You used [ljass]bj_UNIT_FACING[/ljass] as the unit's facing angle.

Some tips about improving your code:
  • Avoid using locations except when you need[ljass]GetLocationZ[/ljass]
    In this code, locations don't need to be used at all. Use the coordinate equivalent, like [ljass]GetSpellTargetX[/ljass] and [ljass]GetSpellTargetY[/ljass] for [ljass]GetSpellTargetLoc[/ljass].
  • Avoid using BJ's unless they don't just call another function. I'm mainly talking about [ljass]ForGroupBJ[/ljass].
  • Your Immobile function could be like this:
    JASS:
    local unit e = GetEnumUnit()
    local real x = GetUnitX(e)
    local real y = GetUnitY(e)
    local unit d = CreateUnit( GetOwningPlayer(GetTriggerUnit()), dummyID, x, y, bj_UNIT_FACING )

    BTW, you can also use [ljass]GetTriggerPlayer()[/ljass] instead of [ljass]GetOwningPlayer(GetTriggerUnit())[/ljass]

@Sgqvur: You never null e if the unit fails the first return check. It doesn't even need to be like that; you could just do everything in the if-then-else if the unit passes the check instead of just returning false.
Also, Fleebop123 is using units for effects probably because he wants to change their direction or have some kind of passive ability.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top