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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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