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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top