• 🏆 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] Applying the effect on summoned unit and not triggerer unit

Status
Not open for further replies.
Level 8
Joined
Jun 13, 2008
Messages
346
Hello,

I found an old spell in the section and wanted to modify and use it in my map.

spell: [vJass] Fiery Run v1.1b

What it does is simply, I just need to change it so the effect doesn't apply on the triggerUnit but on the summonedUnit that is created when I cast the spell.


Code:
private function Actions takes nothing returns nothing
    // Starting the Spell
    // If you want a modification that its targeted and the Targeted unit starts burning just change the GetTriggerUnit() to the unit you want
    call CreateUnitAtLoc( GetOwningPlayer(GetTriggerUnit()),'hfoo', GetUnitLoc(GetTriggerUnit()), bj_UNIT_FACING )
    call F.create(GetLastCreatedUnit(),GetUnitAbilityLevel(GetTriggerUnit(),Spell))
endfunction

Code compiles but just doesn't take any effect. Unit is created but nothing after that, no any effect whatsoever as if spell doesn't call the rest of the functions. What is it wrong that I'm doing?
 
Level 39
Joined
Feb 27, 2007
Messages
5,012
GetLastCreatedUnit() only works with the BJ functions that actually set it. For example, CreateUnitAtLocSaveLast():
JASS:
function GetLastCreatedUnit takes nothing returns unit
    return bj_lastCreatedUnit
endfunction

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
What you need to do is use the return value of CreateUnit in the F.create() call:
JASS:
private function Actions takes nothing returns nothing
    // Starting the Spell
    // If you want a modification that its targeted and the Targeted unit starts burning just change the GetTriggerUnit() to the unit you want
    call F.create(CreateUnit(GetOwningPlayer(GetTriggerUnit()), 'hfoo', GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), bj_UNIT_FACING),GetUnitAbilityLevel(GetTriggerUnit(),Spell))
endfunction
 
Level 8
Joined
Jun 13, 2008
Messages
346
Yeah that actually did it but I also needed to remove the need of the buff for this spell to take the effect. The author added the buff effect as a condition for this spell to work.

But now I'm trying to do something else. Somehow I need to bind the periodically created units to this unit so if this unit dies, all those "dummy" units die as well.

Should I store the information about those units in a hashtable or something? is there any practical way of doing this? I searched for similar examples but they're all GUI:(

This is the function which creates those dummy effect units:

Code:
private function CreateFlame takes integer level, unit u, real x, real y, real angle returns nothing
    // Simply creating flames
    // Yes i know it uses TSA ...but due the duration is not really low and has not an insanely importance i decided to use waits after i got several bugs before which drove me crazy
    local unit flame = CreateUnit(GetOwningPlayer(u),DummyID,x,y,bj_RADTODEG * angle)
    call UnitAddAbility(flame,PassiveEffect1)
    call SetUnitAbilityLevel(flame,PassiveEffect1,level)
    call UnitAddAbility(flame,PassiveEffect2)
    call SetUnitAbilityLevel(flame,PassiveEffect2,level)
    call TriggerSleepAction(Lasts(level))
    call KillUnit(flame)
    call TriggerSleepAction(DelayedRemoval)
    call RemoveUnit(flame)
    set flame = null
    return              
endfunction

I removed the:

Code:
call TriggerSleepAction(Lasts(level))
    call KillUnit(flame)
    call TriggerSleepAction(DelayedRemoval)
    call RemoveUnit(flame)

section so these units would only die if the caster (the one that I create at actions) of this spell dies. But couldn't figure out how to kill all of them at once.

Any tips?
 
Level 39
Joined
Feb 27, 2007
Messages
5,012
Store them in a unit group, save the group in a hashtable with the created unit's handle ID as one of the keys. Put the created unit into a different unit group, and when a unit in that group dies:
  1. Remove it from the second group (not the saved one)
  2. Load the saved group
  3. Kill/remove all the units in the loaded group
  4. Destroy the group
  5. Properly flush the hashtable to remove the stored data
 
Level 8
Joined
Jun 13, 2008
Messages
346
I have a GUI code that does almost exactly the same. Can I use the same code with little changes by converting it to custom text? Otherwise, I'm gonna have to stick to some JASS manuals or something:\
 
Status
Not open for further replies.
Top