• 🏆 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] Need help doing a spell in JASS

Status
Not open for further replies.
Level 6
Joined
Mar 27, 2009
Messages
195
hey dudes,

i tried to do a spell in jass, but failed. could anyone do it for me? (+rep of course)

  • PB
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
      • (Ability being cast) equal to PB
    • Actions
      • Set PB_loc = (Position of (Casting unit))
      • Set PB_caster = (Casting unit)
      • Unitgroup - Pick every unit in (Units within 600.00 of PB_loc matching (((Matching unit) belongs to an enemy of (Owner of PB_caster)) Gleich True)) and do (Actions)
        • Loop - Actions
          • Set PB_targetloc = (Position of (Picked unit))
          • Lightning - Create a XY lightning effect from source PB_loc to target PB_targetloc
          • Custom script: call RemoveLocation(udg_PB_targetloc)
          • Set num2 = (num2 + 1)
          • Set spez2[num2] = (Last created lightning effect)
      • Wait 2.00 seconds
      • Unitgroup - Pick every unit in (Units within 600.00 of PB_loc matching (((Matching unit) belongs to an enemy of (Owner of PB_caster)) Gleich True)) and do (Actions)
        • Loop - Actions
          • Unit - Cause PB_caster to damage (Picked unit), dealing ((Real((Level of PB for PB_caster))) x 80.00) damage of attack type Chaos and damage type Normal
      • Custom script: call RemoveLocation(udg_PB_loc)
      • For each (Integer A) from 1 to num2, do (Actions)
        • Schleifen - Aktionen
          • Lightning - Destroy spez2[(Integer A)]
      • Set num2 = 0
thanks.
 
Last edited:
Level 11
Joined
Apr 6, 2008
Messages
760
Whiped something together fast for you :)

JASS:
scope Spell

// By Ciebron
// Requiers Jass Newgen Pack and TimerUtlis by Vextorian ([url]http://www.wc3c.net/showthread.php?t=101322[/url])

globals
    // Rawcode of the spell
    private constant integer SPELL_ID = 'A003'
    
    //Maximum number of targets (duh)
    private constant integer Max_Targets = 50
    
    //How long time it will take before the units get damaged
    private constant real Delay_Time = 2.
    
    //How often it will move the lightning
    private constant real Interval = 0.05
    
    //Aoe of the spell
    private constant real Aoe = 600.
    
    //How high the lightning will be in the air (UnitFlyHeight+this)
    private constant real Lightning_Z = 50.
    
    // Which lightning effect
    private constant string Lightning_Type = "CLPB"
    
    //Which special effect that will be created on the unit when it take damage
    private constant string SFX = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl"
    
    //Where on the unit the special effect will be created on the unit
    private constant string ATTACH_POINT = "origin"
endglobals
    
private function Damage takes integer lvl returns real
    return lvl*80.
endfunction    

//Setup Ends

globals
    private integer Struct
    private filterfunc FilterFunc
endglobals

private struct Data

unit Caster
unit array Victims [Max_Targets]

lightning array Lightning [Max_Targets]

real Damage
real ElapsedTime

integer Count

player Play

timer Time

    static unit TempU
    static group TempG = CreateGroup()
    static real TempX
    static real TempY

    static method onInit takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        local integer index = 0
        
        loop
            call TriggerRegisterPlayerUnitEvent(Trig,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        
        call TriggerAddCondition(Trig,Condition(function thistype.OnCast))
        
        set FilterFunc = Filter(function thistype.Filt)
        
        set Trig = null
    endmethod
    
    static method OnCast takes nothing returns boolean
        local unit u
        
        if GetSpellAbilityId()==SPELL_ID then
            set u = GetTriggerUnit()
            call thistype.create(u)
            set u = null
        endif
        
        return false
    endmethod
    
    static method create takes unit u returns thistype
        local thistype Dat = thistype.allocate()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        
        set Dat.Caster = u
        set Dat.Damage = Damage(GetUnitAbilityLevel(Dat.Caster,SPELL_ID))
        set Dat.Count = 0
        set Dat.Play = GetOwningPlayer(Dat.Caster)
        set Dat.ElapsedTime = 0.
        set Dat.Time = NewTimer()
        
        set Struct = Dat
        call GroupEnumUnitsInRange(Dat.TempG,x,y,Aoe,FilterFunc)
        
        loop
            set Dat.TempU = FirstOfGroup(Dat.TempG)
            exitwhen Dat.Count >= Max_Targets or Dat.TempU == null
            call GroupRemoveUnit(Dat.TempG,Dat.TempU)
            set Dat.Lightning[Dat.Count] = AddLightningEx(Lightning_Type,true,x,y,GetUnitFlyHeight(Dat.Caster)+Lightning_Z,GetUnitX(Dat.TempU),GetUnitY(Dat.TempU),GetUnitFlyHeight(Dat.TempU)+Lightning_Z)
            set Dat.Victims[Dat.Count] = Dat.TempU
            set Dat.Count = Dat.Count + 1
        endloop
        
        call SetTimerData(Dat.Time,Dat)
        
        call TimerStart(Dat.Time,Interval,true,function thistype.Callback)
        
        return Dat
    endmethod
    
    static method Callback takes nothing returns nothing
        local timer Timer = GetExpiredTimer()
        local thistype Dat = GetTimerData(Timer)
        local integer index = 0
        
        set Dat.ElapsedTime = Dat.ElapsedTime + Interval
        
        if Dat.ElapsedTime >= Delay_Time then            
            loop
                exitwhen index >= Dat.Count
                if SFX != "" then
                    call DestroyEffect(AddSpecialEffectTarget(SFX,Dat.Victims[index],ATTACH_POINT))
                endif
                call DestroyLightning(Dat.Lightning[index])
                call UnitDamageTarget(Dat.Caster,Dat.Victims[index],Dat.Damage,false,false,null,null,null)
                set Dat.Victims[index] = null
                set Dat.Lightning[index] = null
                set index = index + 1
            endloop
            
            call ReleaseTimer(Dat.Time)
            call Dat.destroy()
            set Timer = null
        else
            set Dat.TempX = GetUnitX(Dat.Caster)
            set Dat.TempY = GetUnitY(Dat.Caster)
                
            loop
                exitwhen index >= Dat.Count
                call MoveLightningEx(Dat.Lightning[index],true,Dat.TempX,Dat.TempY,GetUnitFlyHeight(Dat.Caster)+Lightning_Z,GetUnitX(Dat.Victims[index]),GetUnitY(Dat.Victims[index]),GetUnitFlyHeight(Dat.Caster)+Lightning_Z)
                set index = index + 1
            endloop
        endif
    endmethod
    
    static method Filt takes nothing returns boolean
        local thistype Dat = Struct
        local unit f = GetFilterUnit()
        local boolean ok = GetWidgetLife(f) > 0.305 and IsUnitEnemy(f,Dat.Play)
        set f = null
        return ok
    endmethod
    
    method onDestroy takes nothing returns nothing
        set .Caster = null
    endmethod
endstruct

endscope
 
Level 8
Joined
Feb 15, 2009
Messages
463
he made the spell in vJass just to let u know if u want to use it you need JNGP also i think his solution is to complex for such a simple spell but also very performant so if you have JNGP go for that nice script else w8 for someone that makes a normal Jass trigger ( i have no time sry =D)

I would highly recommend JNGP u learn Jass much faster ,coz of the easier to read colored code
 
Level 8
Joined
Feb 15, 2009
Messages
463
nobody uses handle vars anymore but u dont need them here neither structs u need he just makes 2 group picks and damages them with some lightnings so why structs or handlevars should be used in this trigger? for that simple thing your trigger creates much to much handles and useless things
 
Status
Not open for further replies.
Top