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

[vJASS] Adding abilities to last created unit.

Status
Not open for further replies.
Level 4
Joined
Apr 7, 2012
Messages
63
In this spell it creates a wolf and then it is supposed to add two abilities but it doesnt do anything, the wolf is a normal unit, the base unit was a peasant, when I try to add abilities by that way with a hero it works, why isn't this working?

JASS:
scope Wolf initializer Init
globals
      private constant integer ABI_ID = 'A00K'
      private constant integer WOLF = 'h00C'
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00K'
endfunction

private function Actions takes nothing returns nothing
    local unit hero    = GetTriggerUnit()
    local player owner = GetOwningPlayer(hero)
    local integer pid  = GetPlayerId(owner) + 1 
    local real str     = GetHeroStr(hero, true)
    local real agi     = GetHeroAgi(hero, true)
    local real int     = GetHeroInt(hero, true)
    local unit wolf

    call CreateUnit(owner, WOLF, GetUnitX(hero), GetUnitY(hero), 0)
    set wolf = GetLastCreatedUnit()
    call UnitAddAbility(wolf, 'A016' )
    call UnitAddAbility(wolf, 'A012' )

 
    
    

    set wolf = null
    set hero = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger WolfTrg = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( WolfTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( WolfTrg, Condition( function Conditions ) )
    call TriggerAddAction( WolfTrg, function Actions )
endfunction
endscope
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
You will _NEVER_ need any of these "lastCreatedWhatever..." in jass, its only required for GUI. In Jass this kind of stuff is done by using the return value of a function (like in Tirlititis posts).

Maybe that helps you understand:

The GUI Create-Unit when converted to jass:
JASS:
function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction
which is basically this:
JASS:
function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    //...
    set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    //...
endfunction

The GetLastCreatedUnit() function:
JASS:
function GetLastCreatedUnit takes nothing returns unit
    return bj_lastCreatedUnit
endfunction
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
make sure the ability you want to add is a unit ability not a hero ability

also id use this more simple ftw, there is no reason to use a scope there
JASS:
function onInit takes nothing returns nothing
    local u = GetLastCreatedUnit()
    call UnitAddAbility(u, 'a000')
    call UnitAddAbility(u, 'a001')
    set u = null
endfunction
 
Status
Not open for further replies.
Top