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

[JASS] What's wrong with it?

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
I read some tutorials about vJASS and i decidet to make something on my own.
Its supposed to be a knockback spell ( still don't know if does it work ).

When i cast the spell, nothing happens. Like its a normal spell.

Here's my script :
JASS:
scope Ability initializer InitTrig_Spell
    
globals
    unit target
    //Spell target
    real x
    //Target's x
    real y
    //Target's y
    real tx
    //Max distance x
    real ty
    //Max distance y
    
    constant integer spell = 'A000'
    //Spell Id
    constant string sfx = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl"
    //Spell effect
endglobals

private function Damage takes integer level returns real //Damage dealt
    return 50.00 + level * 25.00
endfunction

private function MaxDistance takes nothing returns real //Total distance traveled
    return 500.00
endfunction

private function Time takes nothing returns real //Travel time
    return 1.00
endfunction

private function Period takes nothing returns real //Time between unim movment
    return 0.04
endfunction

private function DistanceIncrease takes nothing returns real //Distance the unit is moved every period
    return MaxDistance() / ( Time() / Period() ) 
endfunction

//===========================================================================

private function Trig_Spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == spell
endfunction

private function Move takes nothing returns nothing
    if x>tx then
        set x = x - DistanceIncrease()
      else 
      set x = x + DistanceIncrease()
    endif
    if y>ty then
        set y = y - DistanceIncrease()
      else
      set y = y + DistanceIncrease()
    endif
    call SetUnitPosition( target, x, y )
    call DestroyEffect( AddSpecialEffectTarget( sfx, target, "origin" ) )
endfunction

private function Trig_Spell_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local location loc = PolarProjectionBJ( GetUnitLoc( target ), MaxDistance(), GetUnitFacing( GetTriggerUnit() ) )
    set target = GetSpellTargetUnit()
    call SetUnitPathing( target, false )
    call UnitDamageTarget( GetTriggerUnit(), target, Damage( GetUnitAbilityLevel( GetTriggerUnit(), spell )), true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
    set x = GetUnitX(target)
    set y = GetUnitY(target)
    set tx = GetLocationX( loc )
    set ty = GetLocationY( loc )
    call RemoveLocation( loc )
    set loc = null
    call TimerStart( t, Period(), true, function Move )
    call TriggerSleepAction( Time() )
    call SetUnitPathing( target, true )
    call DestroyTimer( t )
    set t = null
endfunction

//===========================================================================
function InitTrig_Spell takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_Spell_Conditions ) )
    call TriggerAddAction( t, function Trig_Spell_Actions )
endfunction

endscope

Can someone help me? And pls tell me would it even do anything if the it worked.
Thx
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
This is your script, optimized.
But it is not MUI,,
Also, why it did nothing is because you tried to set a position of Target (GetUnitLoc(target)

before you set the target to something.

If you want me to help you with making it MUI, just tell so,,

JASS:
scope Spell initializer Init
globals
    real x
    real y
    real tx
    real ty
    unit target
    private constant integer spell = 'A000'
    private constant string sfx = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl"
    real Times = 0
    real Sine
    real Cosine
    timer t = NewTimer()
endglobals
private function Damage takes integer level returns real //Damage dealt
    return 50.00 + level * 25.00
endfunction
private function MaxDistance takes nothing returns real //Total distance traveled
    return 500.00
endfunction
private function Time takes nothing returns real //Travel time
    return 1.00
endfunction
private function Period takes nothing returns real //Time between unim movment
    return 0.04
endfunction
private function DistanceIncrease takes nothing returns real //Distance the unit is moved every period
    return MaxDistance() / ( Time() / Period() )
endfunction
//===========================================================================
private function Trig_Spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == spell
endfunction
private function Move takes nothing returns nothing
    if x > tx then
        set x = x - DistanceIncrease()*Cosine
    else
        set x = x + DistanceIncrease()*Cosine
    endif
    if y > ty then
        set y = y - DistanceIncrease()*Sine
    else
        set y = y + DistanceIncrease()*Sine
    endif
 
    call SetUnitX(target,x)
    call SetUnitX(target,y)
    call DestroyEffect(AddSpecialEffectTarget(sfx, target, "origin" ) )
    set Times = Times + Period()
    if Times >= Time() then
        call ReleaseTimer(t)
    endif
endfunction
private function Actions takes nothing returns nothing
    local real tx
    local real ty
    set t = NewTimer()
    set target = GetSpellTargetUnit()
    set tx = GetUnitX(target) + MaxDistance() * Cos(GetUnitFacing(target)*bj_DEGTORAD))
    set ty = GetUnitY(target) + MaxDistance() * Sin(GetUnitFacing(target)*bj_DEGTORAD))
    set x = GetUnitX(target)
    set y = GetUnitY(target)
    set Cosine = Cos(Atan2(tx-x,ty-y))
    set Sine = Sin(Atan2(tx-x,ty-y))
    call SetUnitPathing(target,false)
    call UnitDamageTarget(GetTriggerUnit(), target, Damage( GetUnitAbilityLevel( GetTriggerUnit(), spell )), true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
    set Times = 0.
    call TimerStart(t,Period(),true,function Move)
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 Trig_Spell_Conditions ) )    
    call TriggerAddAction( t, function Trig_Spell_Actions )
endfunction
endscope

BTW: NewTimer() and ReleaseTimer() are functions of TimerUtils. It is safer to use Timerutils than to create and destroy it every time.
 
Last edited:
Level 11
Joined
Apr 6, 2008
Messages
760
Question why dont you use a struct? it will be MUI then :p

And this made me lol

JASS:
private function MaxDistance takes nothing returns real //Total distance traveled
    return 500.00
endfunction

private function Time takes nothing returns real //Travel time
    return 1.00
endfunction

private function Period takes nothing returns real //Time between unim movment
    return 0.04
endfunction

private function DistanceIncrease takes nothing returns real //Distance the unit is moved every period
    return MaxDistance() / ( Time() / Period() )
endfunction

Since the take nothing and are not constants

do this instead

JASS:
globals
    private constant real Time = 1.
    private constant real Period = 0.04
    private constant real MaxDistance = 500
    private constant real DistanceIncrease = MaxDistance / ( Time / Period )
endglobals
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
I told him that if he wanted me to help him with making it MUI, he could say it,, And of course i would use a struct when doing that! =P

Also, i only optimized the code that actually did something,, probably not the best thing to do, but if i would change the whole code to something entirely different, i was affraid he wouldnt understand, so i kept his 'template' and just optimized a bit,,
 
Status
Not open for further replies.
Top