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

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
Sorry don't have it on this computer >.<
I'll post it when I get to my own computer. Probably tomorrow.

About the code, i don't know why the unit wasn't moving. I tried adding a special effect at X and Y (every time the timer ends i move the unit to X and Y ). The effect DID move, while the unit didn't. I don't know why.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Here is a template.
-
Important Note: this script originally is not mine, Element of Water gave it to me at my early learning for vJASS, so if you decided to rep, rep him

JASS:
scope SpellTemplate initializer Init
    private keyword Data
 
    globals
        private constant real TIMER_INTERVAL = 0.03
        private constant real DIST = 32 // value of the distance cut every timer interval high value means high speed
        private constant integer ABIL_ID = 'A000' //change this to the rawcode of your spell
        private constant integer UNIT_ID = 'e000' // rawcode of the dummy (Missile) unit
        //Other constant globals here...
        private Data array data
        private integer index = 0
        private timer tim
        // Other changable globals here...
    endglobals
 
    private function Execute takes nothing returns nothing
        local integer i = 0
        local Data d
        local location missilePoint
        local location stepPoint
        // Other local variables here...
        loop
            exitwhen i >= index
            set d = data[i]
            set missilePoint = GetUnitLoc(d.missile)
                if DistanceBetweenPoints(missilePoint, d.CastPoint) < DIST * 0.5 then
                    call d.destroy()
                    call CreateNova(d.caster,GetLocationX(d.CastPoint),GetLocationY(d.CastPoint))
                else
                    set stepPoint = PolarProjectionBJ(missilePoint, DIST, AngleBetweenPoints(missilePoint, d.CastPoint))
                    call SetUnitPositionLoc(d.missile, stepPoint)
                    call RemoveLocation(stepPoint)
                endif
            call RemoveLocation(missilePoint)
            set i = i + 1
        endloop
        //Any leak cleaning code here...
    endfunction
 
    private struct Data
        //Declare struct members here...
        unit caster
        unit missile
        integer ID
        location CastPoint
 
        static method create takes unit caster, location target returns Data //make sure you change this based on what data you need
            local Data d = Data.allocate()
            local real face
            //Other create code here...
            set data[index] = d
            set d.ID = index
            set d.CastPoint = target
            set d.caster = caster
            set face = AngleBetweenPoints(GetUnitLoc(d.caster),d.CastPoint)
            set d.missile = CreateUnit(GetOwningPlayer(d.caster), UNIT_ID, GetUnitX(d.caster), GetUnitY(d.caster), face)
            call SetUnitPosition(d.missile, GetUnitX(d.caster), GetUnitY(d.caster))
            if index == 0 then
                call TimerStart(tim, TIMER_INTERVAL, true, function Execute)
            endif
            set index = index + 1
            return d
        endmethod
 
        method onDestroy takes nothing returns nothing
            set index = index-1
            set data[this.ID] = data[index]
            set data[this.ID].ID = this.ID
            if index==0 then
                call PauseTimer(tim)
            endif
            //Other destroy code here (such as leak cleaning, removing units etc)...
            call KillUnit(this.missile)
        endmethod
 
    endstruct
 
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == ABIL_ID
    endfunction
 
    private function Actions takes nothing returns nothing
        call Data.create(GetTriggerUnit(), GetSpellTargetLoc()) //make sure you change this based on what data your spell needs
    endfunction
 
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
        call TriggerAddAction(t, function Actions)
        call TriggerAddCondition(t, Condition(function Conditions))
        set tim = CreateTimer()
        //Other initializations things here...
 
            //Preload the dummy units to reduce lagg on first cast
    call RemoveUnit(CreateUnit(Player(12),'e000',0.,0.,0.))
    call RemoveUnit(CreateUnit(Player(12),'e001',0.,0.,0.))
    endfunction
 
endscope


However, this is not the original script he gave me; it has some modification I made during my learning.
 
Level 8
Joined
Jul 28, 2008
Messages
211
Anyway, I'll post my knockback. It doesn't work either. I've made knockback spells before this one, and some of them worked. Can someone tell me why doesn't this one work?

JASS:
scope Knockback initializer Init

globals
    timer Tim
endglobals


struct Knockback
    unit u
    unit t
    real angle
    real cos
    real sin
    
    static Knockback array Index
    static integer Total
    
    static method Loop takes nothing returns nothing
        local Knockback dat 
        local real x
        local real y
        local integer i = 0
        loop
            exitwhen i > dat.Total
            set dat = dat.Index[i]

            set x = GetUnitX(dat.t) + 5 * dat.cos
            set y = GetUnitY(dat.t) + 5 * dat.sin
            call SetUnitX(dat.t, x)
            call SetUnitY(dat.t, y)
            call dat.destroy()
            set dat.Total = dat.Total - 1
            set dat.Index[i] = dat.Index[dat.Total]
            set i = i - 1
            set i = i + 1
        endloop
        if dat.Total == 0 then
            call PauseTimer(Tim)
        endif
    endmethod
    
    static method Start takes unit u, unit t returns nothing
        local Knockback dat = Knockback.allocate()
        set dat.u = u
        set dat.angle = bj_RADTODEG * Atan2(GetUnitX(u) - GetUnitY(t), GetUnitX(u) - GetUnitX(t))
        set dat.cos = Cos(dat.angle)
        set dat.sin = Sin(dat.angle)
        if dat.Total == 0 then
            call TimerStart(Tim, 0.035, true, function Knockback.Loop)
        endif
        set dat.Index[dat.Total] = dat
        set dat.Total = dat.Total + 1
    endmethod
endstruct

function KnockbackUnit takes unit caster, unit target returns nothing
    call Knockback.Start(caster, target)
endfunction

private function Init takes nothing returns nothing
endfunction

endscope
 
Status
Not open for further replies.
Top