• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Removing Unit From Group

Status
Not open for further replies.
Level 5
Joined
Oct 10, 2010
Messages
71
Hello, I've started with JASS and I've encoutered first problem

Code:
loop
        set temp_unit = FirstOfGroup(picked_enemies)
        exitwhen temp_unit == null 
        call PauseUnit(temp_unit,true)
        call SetUnitX(u,GetUnitX(temp_unit))
        call SetUnitY(u,GetUnitY(temp_unit))
        call GroupRemoveUnit(picked_enemies, temp_unit)
        call SetUnitAnimation(u,"Attack")
        call UnitDamageTarget(u,temp_unit,500,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_METAL_LIGHT_CHOP)
        call PauseUnit(temp_unit,false)
        call PolledWait(0.3)
        call DisplayTimedTextToForce( GetPlayersAll(), 30, "Zaatakowano na " + R2S(GetUnitX(temp_unit)) + "," + R2S(GetUnitY(temp_unit)) )
  endloop

Problem is whenever loop is fired, it gets all units from "Picked_enemies" group and moves "u" unit to their localization
 
Level 5
Joined
Oct 10, 2010
Messages
71
I'm rewriting the code, PoolingWait is necessary, Unit needs to be for a "second" near unit and attack it, I'll post it within 15min

---

Maybe I could use some principles?

I want to create common popular spell called "Omnislash", so blademaster fires ability, and teleports up to 4 units and attack them, being untargetable.

I've got problem, because I need to have "fresh" group of enemies each time ability fires up

How do I do smth like this: "GroupEnumUnitsInRange" but limit them to 4?
 
Level 5
Joined
Oct 10, 2010
Messages
71
Code:
function Trig_Omnislash_Conditions takes nothing returns boolean
        return ( GetSpellAbilityId() == 'A00A' ) //AbilityID
endfunction

function DisplayGroup takes nothing returns nothing
    call DisplayTimedTextToForce(GetPlayersAll(),30,GetUnitName(GetEnumUnit()))
endfunction

function OmegaStrikeFilter takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > .405
endfunction

//Get Enemies near Current Attacked Unit
function OmegaStrikeEnemies takes unit target_enemy returns group
local unit temp_unit
local group picked_enemies
    call GroupEnumUnitsInRange(picked_enemies,GetUnitX(target_enemy),GetUnitY(target_enemy),400,Filter(function OmegaStrikeFilter))
    call ForGroup(picked_enemies,function DisplayGroup)
return picked_enemies
endfunction

function Trig_Omnislash_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit() //Our Caster
    local group picked_enemies = CreateGroup() //Group of picked enemies to attack (we get them form "OmegaStrikeEnemies" function!
    local unit target_enemy //Targeted Enemy, First to be attacked (we send this to "OmegaStrikeEnemies" function!
    //-----------------------------------------------------------------------
    set picked_enemies = OmegaStrikeEnemies(target_enemy)
    call OmegaStrikeEnemies(target_enemy)
    
endfunction

//===========================================================================
function InitTrig_Omnislash takes nothing returns nothing
    set gg_trg_Omnislash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Omnislash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Omnislash, Condition(function Trig_Omnislash_Conditions ) )
    call TriggerAddAction( gg_trg_Omnislash, function Trig_Omnislash_Actions )
endfunction
I don't get any Text, why?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Do not use polled wait because it leaks a handle index due to the local reference counter bug. It creates a timer locally and removes it but does not null the local variable used to compensate the reference counter properly.

JASS:
function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining
    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction
 
Level 5
Joined
Oct 10, 2010
Messages
71
Thanks for this! I've got another question, how do I operate with globals?

Swordmaster uses ability -> attack target unit -> Jass finds next target nearby and add previous unit to "already attacked units", how do I do something like this?

JASS:
globals
    local group affected_units = CreateGroup()
endglobals
function Trig_Omnislash_Conditions takes nothing returns boolean
        return ( GetSpellAbilityId() == 'A00A' ) //AbilityID
endfunction

function EnemyFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit()))
endfunction

function GetNearbyUnits takes unit target returns group
local group output_group = CreateGroup()
local real target_x = GetUnitX(target)
local real target_y = GetUnitY(target)
    call GroupEnumUnitsInRange(output_group,target_x,target_y,400,Filter(function EnemyFilter))
return output_group
endfunction

function Trig_Omnislash_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit() //Our Caster
    local unit target = GetSpellTargetUnit() //Inital Target
    local group temp_group = CreateGroup()
    local integer i = 0
    call DisplayTimedTextToForce(GetPlayersAll(),30,"Pierwszy cel " + GetUnitName(target))
    loop
        exitwhen (i == 4)
        set temp_group = GetNearbyUnits(target)
        set target = GroupPickRandomUnit(temp_group)
        call DisplayTimedTextToForce(GetPlayersAll(),30,"Cel numer " + I2S(i) + GetUnitName(target))
        set i = i + 1
    endloop
    

endfunction

//===========================================================================
function InitTrig_Omnislash takes nothing returns nothing
    set gg_trg_Omnislash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Omnislash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Omnislash, Condition(function Trig_Omnislash_Conditions ) )
    call TriggerAddAction( gg_trg_Omnislash, function Trig_Omnislash_Actions )
endfunction

Maybe in Filter check? Add "If unit is not in "Already Attacked Units", if so, how I crete multiple filters? with AND operand?
 
Level 5
Joined
Oct 10, 2010
Messages
71
JASS:
function Trig_Omnislash_Conditions takes nothing returns boolean
        return ( GetSpellAbilityId() == 'A00A' ) //AbilityID
endfunction

function EnemyFilter takes nothing returns boolean
    if(GetWidgetLife(GetFilterUnit()) > .405) then
        if (IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit()))) then
            return true
        endif
        return false
    endif
    return false
endfunction

function GetNearbyUnits takes unit target returns group
local group output_group = CreateGroup()
local real target_x = GetUnitX(target)
local real target_y = GetUnitY(target)
    call GroupEnumUnitsInRange(output_group,target_x,target_y,1200,Filter(function EnemyFilter))
    call GroupRemoveGroup(udg_OmegaStrikeAffected[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))],output_group)
    call GroupAddUnit(output_group,target)
return output_group
endfunction

function Trig_Omnislash_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit() //Our Caster
    local unit target = GetSpellTargetUnit() //Inital Target
    local group temp_group = CreateGroup()
    local integer i = 0
    local real target_x
    local real target_y
    local real origin_x = GetUnitX(target)
    local real origin_y = GetUnitY(target)
    local effect graphic
    //call DisplayTimedTextToForce(GetPlayersAll(),30,"Pierwszy cel " + GetUnitName(target)) - DEBUG
    call AddSpecialEffectTarget("Abilities\\Weapons\\BansheeMissile\\BansheeMissile.mdl",u,"chest")
    call UnitDamageTarget(u,target,500,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_METAL_LIGHT_SLICE)
    call GroupAddUnit(udg_OmegaStrikeAffected[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))],target)
    loop
        exitwhen (i == 3)
        set temp_group = GetNearbyUnits(target)
        set target = GroupPickRandomUnit(temp_group)
        //call DisplayTimedTextToForce(GetPlayersAll(),30,"Cel numer " + I2S(i) + GetUnitName(target)) - DEBUG
        call UnitDamageTarget(u,target,500,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_METAL_LIGHT_SLICE)
        set target_x = GetUnitX(target)
        set target_y = GetUnitY(target)
        call SetUnitX(u,target_x)
        call SetUnitY(u,target_y)
        call PolledWait( 0.25 )
        call GroupAddUnit(udg_OmegaStrikeAffected[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))],target)
        set i = i + 1
    endloop
    call DestroyGroup(udg_OmegaStrikeAffected[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))])
    call DestroyGroup(temp_group)
    
    call SetUnitX(u,origin_x)
    call SetUnitY(u,origin_y)
    
endfunction

//===========================================================================
function InitTrig_Omnislash takes nothing returns nothing
    set gg_trg_Omnislash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Omnislash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Omnislash, Condition(function Trig_Omnislash_Conditions ) )
    call TriggerAddAction( gg_trg_Omnislash, function Trig_Omnislash_Actions )
endfunction
That's final for me, could You check for leaks etc? It's my first spell ever and I don't want to make same mistakes in further spells.

Desc: Hero Dashes with incredible speed becoming untargetable, striking 4 enemies, it is possbile to reach enemy that is 4200 meters away! - This skill should resemble Masters Yi "Alpha Strike" ability from League of Legends
 
Status
Not open for further replies.
Top