Jass Locals/spell

Powergoat

New Member
Reaction score
0
Hey
As I do alot of spells in GUI I've noticed that some spells are pretty impossible to do in MUI.
I've grasped the basics of JASS but I can't figure out how to use locals since my brain is locked in on GUI programming. I'd be grateful if sombody could show me how you would do a MUI JASS spell based on channel(targetpoint) which you aim and throws for example an axe, and when it reaches the target point it shall return to the caster (working pretty much as rexxar's wild axes in DotA)

Thanks in advance
 

Flare

Stops copies me!
Reaction score
662
For locals, you declare them like so

JASS:
local unit myUnit
local real myReal
//They can also be initialized to a value
local string myString = "Hello"


and they MUST be declared at the top of a function
JASS:
//Valid
function Test takes nothing returns nothing
local unit myUnit = GetTriggerUnit ()
call KillUnit (myUnit)
set myUnit = null
endfunction

//Invalid
function Test takes nothing returns nothing
call KillUnit (GetTriggerUnit ())
local real myReal = 0
endfunction


Local arrays are declared like so: (they can't be initialized though)
JASS:
local unit array myUnitArray


I'd be grateful if sombody could show me how you would do a MUI JASS spell based on channel(targetpoint) which you aim and throws for example an axe, and when it reaches the target point it shall return to the caster (working pretty much as rexxar's wild axes in DotA)

That's a pretty big request :\ And will need more than just locals since you will need to use timers to do the motion
 

chobibo

Level 1 Crypt Lord
Reaction score
48
something like Rexxar's Wild Axes isn't simple because you need to know some mathematical equations concerning its movement.
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
JASS:
scope WildAxes

//******************************************************************************************
//*
//*  Wild Axes - By emjlr3, Original seen in DotA Allstars
//*
//*  Hurl two axes outward, which then intersect and return. Each axe can 
//*  only damage a unit once and destroys trees in its wake. 
//* 
//*  Requires:
//*    - "TT" trigger copied to your map, if not already there
//*    - The "Wild Axes" ability copied to your map
//*    - The "Wild Axes" unit copied to your map
//*    - A vJASS Preprocessor
//*
//******************************************************************************************

globals
    // Config. Globals:
    private constant integer abil_id = 'A003' // Wild Axes ability rawcode
    private constant integer dummy_id = 'e000' // Wild Axes unit rawcode
    private constant real speed = .028 // Speed for axes, this is an arbitrary value, increasing it increases the axes speed, while decreasing it decreases their speed
    private constant real width = 375. // Width for bezier curve, larger values give a wider arc, and vice versa
    private constant real area = 150. // Area to damage units around axes and destroy trees
    private constant string sfx = "Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl" // Effect created on hit units
    private constant attacktype attack_type = ATTACK_TYPE_NORMAL // Attack type for damage
    private constant damagetype damage_type = DAMAGE_TYPE_NORMAL // Damage type for damage
    
    // Needed Globals:
    public trigger Trigger = null // Output trigger will be WildAxes_Trigger, which can be used publically
    private group G = CreateGroup()
    private group TempG = null
    private player P = null
    private location L = null
    private rect R = null
endglobals
// Config. Functions:
private function Damage takes integer lvl returns real
    return 50.+(lvl*30.) // Damage/lvl
endfunction

private struct data
    unit u
    unit axe
    player p
    group grp
    real x
    real y
    real xl
    real yl
    real a = 1.
    real outx
    real outy
    real ang
    integer lvl
    boolean first = true
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId()==abil_id
endfunction
private function Filt takes nothing returns boolean
    return not IsUnitInGroup(GetFilterUnit(),TempG) and GetWidgetLife(GetFilterUnit())>.405 and not IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and IsUnitEnemy(GetFilterUnit(),P)
endfunction
private function Kill_Trees takes nothing returns nothing
        call KillDestructable(GetEnumDestructable())
endfunction
private function Effects takes unit u, real x, real y, group grp, integer lvl returns nothing
    local unit dum
    
    set R = Rect(x-150.,y-150.,x+150.,y+150.)
    call EnumDestructablesInRect(R,null,function Kill_Trees)
    call RemoveRect(R)
    call GroupClear(G)
    set P = GetOwningPlayer(u)
    set TempG = grp
    call GroupEnumUnitsInRange(G,x,y,area,Condition(function Filt))
    loop
        set dum = FirstOfGroup(G)
        exitwhen dum==null
        call GroupRemoveUnit(G,dum)
        call UnitDamageTarget(u,dum,Damage(lvl),false,false,attack_type,damage_type,null)
        call DestroyEffect(AddSpecialEffectTarget(sfx,dum,"chest"))
        call GroupAddUnit(grp,dum)
    endloop
endfunction
private function Movement takes nothing returns boolean
    local data d = TT_GetData()
    local real b = 1.-d.a
    
    call SetUnitX(d.axe,d.x*d.a*d.a+d.outx*2*d.a*b+d.xl*b*b)
        call SetUnitY(d.axe,d.y*d.a*d.a+d.outy*2*d.a*b+d.yl*b*b)
    call Effects(d.u,GetUnitX(d.axe),GetUnitY(d.axe),d.grp,d.lvl)
    if d.first then
                set d.a = d.a-speed
        else
                set d.a = d.a+speed
                set d.x = GetUnitX(d.u)
                set d.y = GetUnitY(d.u)
        endif
    if d.a<0. and d.first then
                set d.first = false
                set d.outx = d.x+width*Cos(Atan2(d.yl-d.y,d.xl-d.x)+d.ang)
        set d.outy = d.y+width*Sin(Atan2(d.yl-d.y,d.xl-d.x)+d.ang)
        endif
    if d.a>1. and d.first==false then
                call DestroyGroup(d.grp)
                call RemoveUnit(d.axe)
                call d.destroy()
        return true
        endif
    return false
endfunction
private function Actions takes nothing returns nothing
    local data d1 = data.create()
    local data d2 = data.create()
    
    set d1.u = GetTriggerUnit()
    set d2.u = d1.u
    set d1.x = GetUnitX(d1.u)
    set d2.x = d1.x
    set d1.y = GetUnitY(d1.u)
    set d2.y = d1.y
    set d1.p = GetOwningPlayer(d1.u)
    set d2.p = d1.p
    set d1.axe = CreateUnit(d1.p,dummy_id,d1.x,d1.y,0.)
    set d2.axe = CreateUnit(d1.p,dummy_id,d1.x,d1.y,0.)
    set d1.grp = CreateGroup()
    set d2.grp = CreateGroup()
    set d1.lvl = GetUnitAbilityLevel(d1.u,abil_id)
    set d2.lvl = d1.lvl
    set L = GetSpellTargetLoc()
    set d1.xl = GetLocationX(L)
    set d2.xl = d1.xl
    set d1.yl = GetLocationY(L)
    set d2.yl = d1.yl
    
    set d1.outx = d1.x+width*Cos(Atan2(d1.yl-d1.y,d1.xl-d1.x)+45.)
    set d1.outy = d1.y+width*Sin(Atan2(d1.yl-d1.y,d1.xl-d1.x)+45.)
    set d2.outx = d1.x+width*Cos(Atan2(d1.yl-d1.y,d1.xl-d1.x)-45.)
    set d2.outy = d1.y+width*Sin(Atan2(d1.yl-d1.y,d1.xl-d1.x)-45.)
    set d1.ang = -45.
    set d2.ang = 45.
    
    call TT_Start(function Movement,d1)
    call TT_Start(function Movement,d2)
    
    call RemoveLocation(L)
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    set Trigger = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( Trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Trigger, Condition( function Conditions ) )
    call TriggerAddAction( Trigger, function Actions )
endfunction

endscope

Taken from here:
http://www.thehelper.net/forums/showthread.php?t=81733
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top