so I decided to learn Jass finally

duyen

New Member
Reaction score
214
yeah so I decided to learn JASS finally.

Yeah so I was like 5 minutes into a tutorial by Daelin and I decided to make a simple spell.

All it does is kill the caster and heal all allies around the caster for 50 hp making some nice eye candy in the process.

JASS:
function Cond takes nothing returns boolean
return GetSpellAbilityId() == 'A003'
endfunction


function group_stuff takes nothing returns nothing
//Var declaration
local unit gunit
local real gx = GetUnitX(gunit)
local real gy = GetUnitY(gunit)
local real glife
local real hlife
//Gets picked unit
set gunit = GetEnumUnit()
//Gets the picked unit's life
set glife = GetUnitStateSwap(UNIT_STATE_LIFE, gunit)
//Adds 50 to the picked units live
set hlife = glife + 50.00
//Sets the life
call SetWidgetLife(gunit, hlife)
//Creates SFX
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",gx,gy))
//Sets variables back
set hlife = 0
set glife = 0
set gunit = null
set gx = 0
set gy = 0
endfunction




function damage takes nothing returns nothing
//Var declaration
local unit caster
local group g
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
local location p = GetUnitLoc(caster)
local unit gunit
//Sets the caster
set caster = GetTriggerUnit()

//Makes & Destroys special effect
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectCaster.mdl",x,y))
//Kills the caster
call KillUnit(caster)
//Sets the group to units around caster
set g = GetUnitsInRangeOfLocAll(500.00, p)
//Adds health to units in group
call ForGroupBJ( g, function group_stuff)
//Destroys the group for reuse later.
set caster = null
set x = 0
set y = 0
call DestroyGroup(g)
set g = null
endfunction


function InitTrig_Sacrifice_JASS takes nothing returns nothing
    set gg_trg_Sacrifice_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Sacrifice_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Sacrifice_JASS, Condition( function Cond ) )
    call TriggerAddAction( gg_trg_Sacrifice_JASS, function damage )
    endfunction


So I couldn't find any beginner tutorials on how to use natives so all I did was use BJ's (at least I think I did?).

So go ahead, tell me what I did wrong and if it has leaks, and how to make it 10x more efficient.

oh and btw the function "damage" is the main actions
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Where is the "cond" function?

You are not nulling any location/group variables .

You are not even using gunit in the damage function.
JASS:
call SetUnitLifeBJ(gunit, hlife)


Use :
JASS:
call SetWidgetLife(...)


This:
JASS:
call AddSpecialEffectLoc("Abilities\\Spells\\Human\\Resurrect\\ResurrectCaster.mdl",p)
 call DestroyEffect(GetLastCreatedEffectBJ())


Can be changed into this:

JASS:
call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Human\\Resurrect\\ResurrectCaster.mdl",p))


And finally. Use coordinates rather than locations.
JASS:
local location l = GetSpellTargetLoc()
local real x = GetLocationX(l)
local real y = GetLocationY(l)

//And so forth...
 

duyen

New Member
Reaction score
214
Sorry didn't copy cond function, it was just a spell check.

Will read through rest of your post in 1 sec.

>You are not nulling any location/group variables .

JASS:

call RemoveLocation(p)
call DestroyGroup(g)
 

Vestras

Retired
Reaction score
248
Why do you set the variables after they have been declared?
Just set them when you declare them, ex.:

JASS:
local unit Caster=GetTriggerUnit()


EDIT: > I was looking for what to do instead of p.

The function's name if "AddSpecialEffect". It takes reals.
 

duyen

New Member
Reaction score
214
I put that exact thing (well changed path), but it only allows 2 args. JassCraft even says so.

EDIT: nvm, I put AddSpecialEffectLoc
 

duyen

New Member
Reaction score
214
Read my edit.

Anyhow what do I replace GetUnitsInRangeLocAll with?

Also: Updated first post with my new code.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
JASS:
local group g = CreateGroup()

call GroupEnumUnitsInRange(g, x, y, AoE, function*)


*This can either be a function filtering out units, or just a substitute function returning true (for FirstOfGroup() loops and similiar).

Edit:

JASS:
set glife = GetUnitStateSwap(UNIT_STATE_LIFE, gunit)


Utterly useless BJ, use the native or GetWidgetLife()



Edit2:

JASS:
call ForGroupBJ( g, function group_stuff)


Even more useless BJ since the native is simply:

JASS:
call ForGroup(g, function group_stuff)
 
Reaction score
333
Read my edit.

Anyhow what do I replace GetUnitsInRangeLocAll with?

Also: Updated first post with my new code.

You get rid of ForGroup and use a filter + GroupEnum function instead like this:

JASS:

globals // if you're not using NewGen/jasshelper, you won't be able to do this globals block.
    group G = CreateGroup()
endglobals

function DoStuff takes nothing returns boolean
    local unit u = GetFilterUnit()
    call KillUnit(u)
    set u = null
    return false // must do this
endfunction

function waffle takes nothing returns nothing
    call GroupEnumUnitsInRange(G, 0., 0., 500., Condition(function DoStuff))
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top