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

vJASS spell issue

Status
Not open for further replies.
I made a spell (Time Bend) for my map (new upcoming hero ^^)

There are a few issues with the code though (The knockback struct won't
function properly)

Here's the code:

JASS:
scope TimeBend initializer Init
    globals
        private constant integer ABIL_CODE = 'A045'
        private constant integer MSH = 'A082'
        private constant integer SLOW = 'A083'
        private integer int
    endglobals
    
    private struct KB
        unit cst
        unit kb
        real r
        real v
        real ang
        real md
        timer tmr
        timer lp
        
        static method endkb takes nothing returns nothing
            local thistype this = GetTimerData(GetExpiredTimer())
            call destroy()
            call ReleaseTimer(tmr)
            call ReleaseTimer(lp)
        endmethod
        
        static method move takes nothing returns nothing
            local thistype this = GetTimerData(GetExpiredTimer())
            call SetUnitX(kb,GetUnitX(kb)+v*Cos(bj_DEGTORAD*ang))
            call SetUnitY(kb,GetUnitY(kb)+v*Sin(bj_DEGTORAD*ang))
        endmethod
        
        static method create takes unit u, unit cs returns KB
            local KB this = KB.allocate()
            
            set this.kb = u
            set this.cst = cs
            set this.ang = bj_RADTODEG * Atan2(GetUnitY(this.kb) - GetUnitY(this.cst), GetUnitX(this.kb) - GetUnitX(this.cst))
            set this.md = 300.00
            set this.v = 9.00
            set this.tmr = NewTimer()
            set this.lp = NewTimer()
            
            call TimerStart(this.tmr, 2.00, false, function KB.endkb)
            call SetTimerData(this.tmr,this)
            call TimerStart(this.lp, 0.03, true, function KB.move)
            call SetTimerData(this.lp,this)
            
            return this
        endmethod
        
        method onDestroy takes nothing returns nothing
            set cst = null
            set kb = null
        endmethod
    endstruct
    
    private struct Data
        unit cs
        group g
        integer lvl
        player p
        
        static method filtr takes nothing returns boolean
            local thistype this = int
            return IsPlayerEnemy(p, GetOwningPlayer(GetFilterUnit()))
        endmethod
        
        static method create takes unit u returns Data
            local Data this = Data.allocate()
            
            set this.cs = u
            set this.p = GetTriggerPlayer()
            set this.g = CreateGroup()
            set this.lvl = GetUnitAbilityLevel(this.cs, ABIL_CODE)
            
            set int = this
            call GroupEnumUnitsInRange(this.g,GetUnitX(this.cs),GetUnitY(this.cs),999999.00, function Data.filtr)
            
            return this
        endmethod
        
        static method slow takes nothing returns nothing
            call UnitAddAbility(GetEnumUnit(), SLOW)
        endmethod
        
        static method gc takes nothing returns nothing
            call UnitRemoveAbility(GetEnumUnit(), SLOW)
        endmethod
        
        static method end takes nothing returns nothing
            local thistype this = GetTimerData(GetExpiredTimer())
            call ForGroup(g, function Data.gc)
            call UnitRemoveAbility(cs, MSH)
            call DestroyGroup(g)
            call destroy()
        endmethod
        
        method onDestroy takes nothing returns nothing
            set cs = null
            set p = null
        endmethod
    endstruct
    
    private function Knockem takes nothing returns nothing
        local KB k = KB.create(GetEnumUnit(), GetTriggerUnit())
    endfunction
    
    private function Enumf takes nothing returns boolean
        return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)==false and GetWidgetLife(GetFilterUnit()) > 0.405
    endfunction
    
    private function KnockbackE takes nothing returns nothing
        local group g = CreateGroup()
        local unit u = GetTriggerUnit()
        call GroupEnumUnitsInRange(g, GetUnitX(u), GetUnitY(u), 200.00, function Enumf)
        call ForGroup(g, function Knockem)
    endfunction
    
    private function Act takes nothing returns nothing
        local Data d = Data.create(GetTriggerUnit())
        local timer t = NewTimer()
        local timer tm = NewTimer()
        
        call UnitAddAbility(d.cs, MSH)
        call ForGroup(d.g, function Data.slow)
        
        call TimerStart(t, 5.00, false, function Data.end)
        call SetTimerData(t,d)
        
        call TimerStart(t, 0.03, true, function KnockbackE)
    endfunction
    
    private function Cond takes nothing returns boolean
        return GetSpellAbilityId()==ABIL_CODE
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function Cond))
        call TriggerAddAction(t, function Act)
    endfunction
endscope

What happens is that I get a movespeed bonus for 5 seconds and all units
get slowed, and whenever I walk up to a unit, it's knocked back (I know this
can hit the op limit pretty fast, but I'll work something out ;p)

The only thing that happens when I cast the spell is ... NOTHING .. except
the speed bonus :p

I think the problem is with the KB struct.

Anyone who can help, will be properly credited :)
 
Level 11
Joined
May 31, 2008
Messages
698
i dont really know vjass, i kinda know jass, but
call ForGroup(g, function Knockem)
that calls the Knockem function, but where does it actually call the function that moves the unit?
Also, you have 2 of "static method create" isnt each function supposed to have a different name? idk if its different for vjass :p

Edit:
oh i see,
local KB k = KB.create(GetEnumUnit(), GetTriggerUnit())
That calls the function that moves the unit, right?
But maybe its calling the second one thats named "create" instead of the first
maybe because the second create function overwrites the first?

Also, you can probably remove the conversion from radians to degrees and then back to radians :p
 
Moved from World Editor Help Zone.

It took me 11 days to figure that out xD
I was looking for this thread for days =P
Anyways, Thanks for the help Troll-Brain ^^
+rep

i dont really know vjass, i kinda know jass, but
call ForGroup(g, function Knockem)
that calls the Knockem function, but where does it actually call the function that moves the unit?
Also, you have 2 of "static method create" isnt each function supposed to have a different name? idk if its different for vjass :p

Edit:
oh i see,
local KB k = KB.create(GetEnumUnit(), GetTriggerUnit())
That calls the function that moves the unit, right?
But maybe its calling the second one thats named "create" instead of the first
maybe because the second create function overwrites the first?

Also, you can probably remove the conversion from radians to degrees and then back to radians :p

When I call KB.create, I'm creating an instance of the knockback.
It's like creating a knockback that'll just run given a caster and a target :)

Also, I can have functions with the same in this case since they're both in different structs.
After JassHelper processes the code, it'll rename the functions :)
 
Status
Not open for further replies.
Top