• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Help Picking random unit from unit group

Status
Not open for further replies.
Level 2
Joined
Jul 4, 2016
Messages
14
I am making triggerd spell an "insanity curse"

"Insanity Curse (Passive)"
Grants a chance to curse attacked enemy with "Insanity curse". Cursed unit attacks random ally near him untill curse ends.

But I can't get unit filter for this working...
Here is a code of problem place:

JASS:
//unit u = udg_cursed_unit
//unit t = udg_cursed_unit_attack_target
//location p = udg_cursed_unit_position

if (( t == null ) or (IsUnitDeadBJ(t))) then
            set t = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(512, p, Condition(function GetBooleanAnd(( IsUnitAlly(GetFilterUnit(), GetOwningPlayer(t)) == true), IsUnitAliveBJ(GetFilterUnit()) == true))))  ///// This line causes problems - syntax checker says ' symbol is missing
        endif
        call IssueTargetOrderBJ( u, "attack", t)

Here is a code of the spell:
JASS:
//////////////////////////////////////////////////////////////////////
//////////////////////////// INSANITY PASSIVE ////////////////////////////
//////////////////////////////////////////////////////////////////////
function Trig_Insanity_Passive_Conditions takes nothing returns boolean
    if ( (GetUnitAbilityLevelSwapped('Abun', GetAttackedUnitBJ()) > 0 ) or (IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_HERO) == true) or ( IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_STRUCTURE) == true )) then
        return false
    endif
  
    if ( not ( GetUnitAbilityLevelSwapped('Aesr', GetAttacker()) > 0 ) ) then
        return false
    endif
    return true
endfunction


function Trig_Insanity_Passive_Actions takes nothing returns nothing
    // ------create local variables------//
    local effect e
    local unit u
    local unit t
    local real r = 0.0
    local location p
  
    // ------assign local variables------//
    set u = GetAttackedUnitBJ()
    set p = GetUnitLoc(u)

    // ------calculate chance ------//
    if ( GetUnitLevel(u) <= 1 ) then
        set r = 0.75
    else   
        set r = r +  (0.7 - 0.07 * (I2R(GetUnitLevel(u))))/2  /// depends on victim Level
        set r = r + (1 - GetUnitLifePercent(u)/75)  /// and current health
        if (r > 0.5) then
           set r = 0.5
        endif
    endif
    // ----


    // ------compare chance ------//
    if ( r >= GetRandomReal(0, 1) ) then
        call DoNothing(  )
    else
        return
    endif

  
    // ------attach effect ------//
   /// call AddSpecialEffectTargetUnitBJ( "overhead", u, "war3campImported\\ForsakenInsanity.mdx" )
    call AddSpecialEffectTargetUnitBJ( "overhead", u, "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdx" )
    set e = GetLastCreatedEffectBJ()
  
    // ------PROBLEM PLACE------//
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 6
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
      
        if (( t == null ) or (IsUnitDeadBJ(t))) then
            set t = GroupPickRandomUnit(GetUnitsInRangeOfLocMatching(512, p, Condition(function GetBooleanAnd(( IsUnitAlly(GetFilterUnit(), GetOwningPlayer(t)) == true), IsUnitAliveBJ(GetFilterUnit()) == true))))
        endif
        call IssuePointOrderLocBJ( u, "move", PolarProjectionBJ(p, 256.00, GetRandomDirectionDeg()) )
        call IssueTargetOrderBJ( u, "attack", t)
        call TriggerSleepAction( 0.5 )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop


    // ------destroy effect------//
    call DestroyEffectBJ(e)
    call RemoveLocation(p)
    set u = null
    set r = 0.0
    set t = null
  
    // ------resume order ------//
    call IssuePointOrderLocBJ( u, "attack", p )
endfunction

//===========================================================================
function InitTrig_Insanity_Passive takes nothing returns nothing
    set gg_trg_Insanity_Passive = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Insanity_Passive, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Insanity_Passive, Condition( function Trig_Insanity_Passive_Conditions ) )
    call TriggerAddAction( gg_trg_Insanity_Passive, function Trig_Insanity_Passive_Actions )
endfunction

Thanks in advance.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,206
The group filter is nonsense.
IsUnitAlly(GetFilterUnit(), GetOwningPlayer(t)) == true
This can run when...
t == null
So you are getting the owner of null.

GetFilterUnit is also null given the context. You are evaluating it inside the function to produce a boolean constant which then is used as the filter. Since GetFilterUnit is null this filter is probably always false so the group is always empty so there are no units to select a random unit from.
 
Level 2
Joined
Jul 4, 2016
Messages
14
The group filter is nonsense.

This can run when...

So you are getting the owner of null.

GetFilterUnit is also null given the context. You are evaluating it inside the function to produce a boolean constant which then is used as the filter. Since GetFilterUnit is null this filter is probably always false so the group is always empty so there are no units to select a random unit from.
Ah, I feel myself so noob(
Thanks for help!
 
Status
Not open for further replies.
Top