• 🏆 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] Can someone help me?

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
Hi everyone!

I decided to start learning JASS! I already know some things, but now i wanna learn how to make a jump or knockback system. I tried downloading some, but they're all VERY long.

Can anyone post a short and simple jump or knockback system (no fancy things like acceleration or decceleration and effects just as short as possible)?

Thanks in advance!! :thumbs_up:
 
Level 18
Joined
Feb 28, 2009
Messages
1,970
Don`t double post. Use
edit.gif
button.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
I tried reading a few scripts to understand, but im too lazy to read the entire tutorial so i couldn't find out.

I am also learning vJASS. I started from 3 days ago, if you want learn to JASS you can't be lazy. I spend more than 10 hours on this forum to learn vJASS also you may need to read a part more than once to understand it properly. So what I want to say learning JASS can't be done and be lazy :wink: (No offense meant)
 

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,522
Here's the jump ability out of my map, which is currently using locations.

JASS:
scope leapOfFaith initializer i
    private struct dLeap
        integer steps
        location last
        unit caster
    endstruct
    
    globals
        private constant integer ciLeap='A058'      //Triggering abilitycode
        private constant integer iSteps=35          //Total number of repeated timer steps
        private constant integer offset=26          //Distance in game units a unit is offset by
        private constant integer reducer=2          //Ammount steps is reduced by each time
        private constant real zMultiplier=.5        //Multiplier for caster z height; larger is a taller arc
        private dLeap array leapDB
        private integer dbIndex=-1
        private timer time=CreateTimer()
    endglobals
    
    private function c takes nothing returns boolean
        return GetSpellAbilityId()==ciLeap
    endfunction
    
    private function p takes nothing returns nothing
        local integer index=0
        local dLeap tempDat
        local location lOffset
        local real z1
        local real z2
        local effect fx
        local integer iGrabbed=dbIndex
        loop
            exitwhen index>iGrabbed
            set tempDat=leapDB[index]
            set lOffset=PolarProjectionBJ(GetUnitLoc(tempDat.caster),offset,GetUnitFacing(tempDat.caster))
            set z1=I2R(tempDat.steps/5) //z heights being compared
            set z2=I2R(tempDat.steps)/5 //Should just use mod...
            if z1==z2 then              //This works though.
                set fx=AddSpecialEffectLoc("Abilities\\Weapons\\GlaiveMissile\\GlaiveMissileTarget.mdl",lOffset)
                call DestroyEffect(fx)
            endif
            set tempDat.steps=tempDat.steps-reducer
            call SetUnitFlyHeight(tempDat.caster,GetUnitFlyHeight(tempDat.caster)+zMultiplier*tempDat.steps,0)
            call SetUnitPositionLoc(tempDat.caster,lOffset)
            if IsTerrainPathable(GetLocationX(lOffset),GetLocationY(lOffset),PATHING_TYPE_FLOATABILITY)==false then
                set tempDat.last=lOffset
            endif
            if tempDat.steps<-1*iSteps then
                call SetUnitPathing(tempDat.caster,true)
                set leapDB[index]=leapDB[dbIndex]
                set dbIndex=dbIndex-1
                call SetUnitFlyHeight(tempDat.caster,0,0)
                if dbIndex==-1 then
                    call PauseTimer(time)
                endif
                if IsTerrainPathable(GetLocationX(lOffset),GetLocationY(lOffset),PATHING_TYPE_FLOATABILITY) then //WHY IS THIS BACKWARDS!?
                    call SetUnitPositionLoc(tempDat.caster,tempDat.last)
                    call SetUnitState(tempDat.caster,UNIT_STATE_LIFE,GetUnitState(tempDat.caster,UNIT_STATE_LIFE)/2+1)
                endif
                call tempDat.destroy()
            endif
            set index=index+1
        endloop
        call RemoveLocation(lOffset)
    endfunction
    
    private function a takes nothing returns nothing
        local dLeap tempDat=dLeap.create()
        local unit caster=GetSpellAbilityUnit()
        local real rCasterX=GetUnitX(caster)
        local real rCasterY=GetUnitY(caster)
        call SetSoundPosition(gg_snd_jumpSoundDefendCasterWav,rCasterX,rCasterY,100)
        call StartSound(gg_snd_jumpSoundDefendCasterWav)
        call UnitAddAbility(caster,'Amrf')
        call UnitRemoveAbility(caster,'Amrf')
        call SetUnitPathing(caster,false)
        set tempDat.steps=iSteps+GetUnitLevel(caster)/2
        set tempDat.caster=caster
        if dbIndex==-1 then //While negative 1, the stack is empty. An empty stack must be jumpstarted!
            call TimerStart(time,.03,true,function p)
        endif
        set dbIndex=dbIndex+1
        set leapDB[dbIndex]=tempDat
    endfunction

    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t,Condition(function c))
        call TriggerAddAction(t,function a)
    endfunction
endscope

Hope it helps.

EDIT: wtf? it converted brackets in arrays to their ascii escape characters..?
 
Level 3
Joined
Aug 9, 2008
Messages
60
Code:
library KnockBackSystem

globals
    private constant real ANIMATION_RATE = 0.02
endglobals

struct KB
    private unit    un = null
    private real    ex = 0
    private real    ey = 0
    private real    ju = 0
    private real    le = 0
    private real    el = 0
    private real    an = 0
    private boolean de
    private boolean ac
    private boolean st
    
    private static timer    ti
    private static KB       in
    private static KB array kb
    private static integer  nu = 0
    private static boolexpr kf
    
    static method create takes unit target, real distance, real length, real angle, boolean destroy returns KB
        local KB this = KB.allocate()
        set this.un = target
        set this.ju = distance * ANIMATION_RATE / length
        set this.le = length
        set this.an = angle
        set this.de = destroy
        set this.ac = true
        set this.ex = GetUnitX(target)
        set this.ey = GetUnitY(target)
        set this.el = 0
        set this.kb[this.nu] = this
        set this.nu = this.nu + 1
        if .nu == 1 then
            call TimerStart( .ti, ANIMATION_RATE, true, function KB.timer)
        endif
        return this
    endmethod
    
    static method remove takes nothing returns boolean
        local destructable tree = GetEnumDestructable()
        local KB this = .in
        if this.de == true then
            call KillDestructable(tree)
        else
            set .st = true
        endif
        return false
    endmethod
    
    static method timer takes nothing returns nothing
        local integer i    = 0
        local integer k    = 0
        local real    ang
        local rect    r
        local KB      this
        loop
            exitwhen i == .nu
            set this = .kb[i]
            if this.ac then
            endif
            set this.el = this.el + ANIMATION_RATE
            if this.ac == false then
                call this.destroy()
            else
                if this.el > this.le then
                    set this.ac = false
                else
                    set .in = this
                    set r = Rect(this.ex - 30, this.ey - 30, this.ex + 30, this.ey + 30)
                    call EnumDestructablesInRect( r, .kf, null)
                    if .st == false then
                        set .ex = GetUnitX(.un)
                        set .ey = GetUnitY(.un)
                        set .ex = .ex + .ju*Cos(bj_DEGTORAD*.an)
                        set .ey = .ey + .ju*Sin(bj_DEGTORAD*.an)
                        call SetUnitX(.un, .ex)
                        call SetUnitY(.un, .ey)
                    endif
                endif
                set .kb[k] = this
                set k = k + 1
            endif
            set i = i + 1
        endloop
        set .nu = k
        if k == 0 then
            call PauseTimer(.ti)
        endif
    endmethod
    
    static method onInit takes nothing returns nothing
        set .ti = CreateTimer()
        set .kf = Condition(function KB.remove)
    endmethod
endstruct

endlibrary

Took 30 minutes instead of said 5 minutes... sadface. By the way, I'm not even sure if my destructible destroy method works, theoretically it should work, but I haven't tested this code.

Jass tags are broken so I'm using code.
 
Status
Not open for further replies.
Top