• 🏆 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] Help using vJass and XE 0.5 to create a spell

Status
Not open for further replies.
Level 4
Joined
Sep 24, 2004
Messages
49
I'm working a spell for my map called "Annihilate", it fires a beam of energy through the target point. It charges the beam for "Charge Duration". My current problem is, when I try to call the method "Create" from structure "SE" (call SE.Create(u, l)) it does not run.
Another question I have is "How I would cause a method inside a structure to be used with a periodic timer?"
JASS:
//=========================================================
//Spell - Annihilate
//Spell Id - 'A01F'
//Spell Effect - Charge for 0.5 Sec
//               Fire a laser beam for 0.25 Sec
//               Extends to edge of map
//               Deals 20*Level + 1.5 Int Damage
//               128 AoE around beam
//=========================================================
scope Annihilate initializer Aint
    //Globals
    globals
        private boolean type1 = true
        private boolean type2 = false
    endglobals
    private function Ticker takes nothing returns nothing
        if type1 == true then
            set type1 = false
            set type2 = true
        elseif type2 == true then
            set type1 = true
            set type2 = false
        endif
    endfunction
    //Spell
    private function spellIdMatch takes nothing returns boolean
        return (GetSpellAbilityId()=='A01F')
    endfunction
    private function SpellId takes nothing returns integer
        return 'A01F'
    endfunction
    //Constants
    private function Interval takes nothing returns real
        return 0.04
    endfunction
    private function ChargeDuration takes nothing returns real
        return 0.50
    endfunction
    private function BeamDuration takes nothing returns real
        return 0.25
    endfunction
    private function BeamDamage takes integer int, integer lvl returns real
        return int * 1.5 + lvl * 20
    endfunction
    //Effect Structure
    private struct SpellEffect
        integer int //Caster's Intelligence
        integer lvl //Spell Level
        real ang //Casting Angle
        unit o //Owner
        location l //Target Location
        timer t //Casting Timer
        integer i = 0 //Tics passed
        xefx Ex //Effect
        method End takes nothing returns nothing
            call this.Ex.destroy()
            call RemoveLocation(this.l)
            set this.o = null
            call PauseUnit(this.o, false)
            call ReleaseTimer(this.t)
        endmethod
        method FireLaser takes nothing returns nothing
            call DisplayTextToForce(GetPlayersAll(), "IMMAFIRINMAHLASER")
            call this.End()
        endmethod
        method ChargePulse takes nothing returns boolean
            set this.i = this.i + 1
            set this.Ex.scale = 1.0 + this.i*0.1
            if this.i >= ChargeDuration() / Interval() then
                call PauseTimer(this.t)
                call this.FireLaser()
                return false
            endif
            return true
        endmethod
        method Charge takes nothing returns nothing
            local real x = GetUnitX(this.o) + Cos(this.ang) * 25
            local real y = GetUnitY(this.o) + Sin(this.ang) * 25
            local boolean t1 = type1
            local boolean t2 = type2
            set this.Ex = xefx.create(x,y,this.ang)
            set this.Ex.owner = GetOwningPlayer(this.o)
            set this.Ex.scale = 1.0
            set this.Ex.fxpath= "Abilities\\Spells\\Orc\\LightningBolt\\LightningBoltMissile.mdl"
            call PauseUnit(this.o, true)
            loop
            exitwhen this.ChargePulse() == false
                loop
                exitwhen t1 != type1 and t2 != type2
                endloop
                set t1 = type1
                set t2 = type2
            endloop
        endmethod
        method Create takes unit o, location l returns nothing
            local location loc = GetUnitLoc(o)
            local real x1 = GetLocationX(loc) 
            local real x2 = GetLocationX(l) 
            local real y1 = GetLocationY(loc)
            local real y2 = GetLocationY(l)
            call DisplayTextToForce(GetPlayersAll(), "Chargin2")
            set this.t=NewTimer()
            set this.int = GetHeroInt(o, true)
            set this.lvl = GetUnitAbilityLevel(o, SpellId())
            set this.o = o
            set this.l = l
            set this.ang = Atan2(y2 - y1, x2 - x1)
            call DisplayTextToForce(GetPlayersAll(), "Chargin3")
            call this.Charge()
            //call TimerStart(FTime, Period(), true, method ChargePulse())
            call DisplayTextToForce(GetPlayersAll(), "Chargin4")
            call TimerStart(this.t, Interval(), true, function Ticker)
            //Clean Up
            call DisplayTextToForce(GetPlayersAll(), "Chargin5")
            call RemoveLocation(loc)
            call RemoveLocation(l)
            set o = null
        endmethod
    endstruct
    //Effect
    private function onSpellCast takes nothing returns nothing
        local location l = GetSpellTargetLoc()
        local unit u = GetTriggerUnit()
        local SpellEffect SE
        call DisplayTextToForce(GetPlayersAll(), "Chargin'")
        call SE.Create(u, l)
        
        //Clean Up
        call RemoveLocation(l)
        set u = null
    endfunction
    //Initializer
    private function Aint takes nothing returns nothing
        //Locals
        local trigger t=CreateTrigger()
        //Create Trigger
        call TriggerAddCondition(t, Condition( function spellIdMatch) )
        call TriggerAddAction(t,    function onSpellCast)
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        //Void Leaks
        set t=null
    endfunction
endscope
Thank you.
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
    private function onSpellCast takes nothing returns nothing
        local location l = GetSpellTargetLoc()
        local unit u = GetTriggerUnit()

        call DisplayTextToForce(GetPlayersAll(), "Chargin'")
        call SpellEffect.create(u, l)

        //Clean Up
        call RemoveLocation(l)
        set u = null
    endfunction

this should work, you use the structs name :)
 
Level 4
Joined
Sep 24, 2004
Messages
49
I got it to get further into the code. You were close - but not quite.
JASS:
static method Create takes unit o, location l returns SpellEffect
            local location loc = GetUnitLoc(o)
            local SpellEffect SE = SpellEffect.allocate()
            local real x1 = GetLocationX(loc) 
            local real x2 = GetLocationX(l) 
            local real y1 = GetLocationY(loc)
            local real y2 = GetLocationY(l)
            call DisplayTextToForce(GetPlayersAll(), "Chargin2")
            //set SE.t=NewTimer()
            set SE.int = GetHeroInt(o, true)
            set SE.lvl = GetUnitAbilityLevel(o, SpellId())
            set SE.o = o
            set SE.l = l
            set SE.ang = Atan2(y2 - y1, x2 - x1)
            call DisplayTextToForce(GetPlayersAll(), "Chargin3")
            call TimerStart(SE.t, Interval(), true, function Ticker)
            call DisplayTextToForce(GetPlayersAll(), "Chargin4")
            call SE.Charge()
            //call TimerStart(FTime, Period(), true, function Floater.Execute)
            //Clean Up
            call DisplayTextToForce(GetPlayersAll(), "Chargin5")
            call RemoveLocation(loc)
            call RemoveLocation(l)
            set o = null
            return SE
        endmethod
JASS:
private function onSpellCast takes nothing returns nothing
        local location l = GetSpellTargetLoc()
        local SpellEffect SE
        local unit u = GetTriggerUnit()

        call DisplayTextToForce(GetPlayersAll(), "Chargin'")
        set SE = SpellEffect.Create(u, l)

        //Clean Up
        call RemoveLocation(l)
        set u = null
    endfunction

Now my code stops at
JASS:
            loop
            exitwhen this.ChargePulse() == false
                loop
                exitwhen t1 != type1 and t2 != type2
                endloop
                set t1 = type1
                set t2 = type2
            endloop
where type1 and type 2 change with the timer.

Which was a stupid idea to begin with, but I'm not sure how to make this all work. Anyone willing to help? :3

I can't seem to get methods to work with a timer, nor have functions inside of a structure. Is making a struct array the only way to do this?
 
Status
Not open for further replies.
Top