• 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.

Select Random Unit In Range Matching Conditions

Status
Not open for further replies.
Level 4
Joined
Aug 1, 2007
Messages
66
I've converted this to script and am trying to make it more efficient. The long line in the loop starting with ForGroupBJ is supposed to set the target to a new unit in range of the current target that is an enemy of the caster and not equal to the current target. In it's converted from gui form it used 4 or 5 functions, but I'm sure there's an easier way. I also wonder if there's a way to make the unit attack normally in place of playing his animation and dealing a set amount of damage. I tried it, but it didn't seem to do anything. I assumed the attack cooldown was getting in the way or something.

JASS:
function Trig_Swift_Attack_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00Y' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Swift_Attack_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(caster,'A00Y')
    local effect array castereffect
    local sound array slice
    local real array damage
    local integer hits = 4
    set slice[1] = gg_snd_MetalHeavySliceFlesh1
    set slice[2] = gg_snd_MetalHeavySliceFlesh2
    set slice[3] = gg_snd_MetalHeavySliceFlesh3
    set damage[1] = 50
    set damage[2] = 62.5
    set damage[3] = 78.13
    set damage[4] = 97.66
    set damage[5] = 122.07
    set damage[6] = 152.59
    set damage[7] = 190.73
    set damage[8] = 238.42
    set damage[9] = 298.02
    set damage[10] = 372.53
    call SetUnitTimeScalePercent( caster, 400.00 )
    call AddSpecialEffectTargetUnitBJ( "hand right", caster, "Abilities\\Weapons\\IllidanMissile\\IllidanMissile.mdl" )
    set castereffect[1] = GetLastCreatedEffectBJ()
    call AddSpecialEffectTargetUnitBJ( "hand left", caster, "Abilities\\Weapons\\IllidanMissile\\IllidanMissile.mdl" )
    set castereffect[2] = GetLastCreatedEffectBJ()
    call AddSpecialEffectTargetUnitBJ( "foot right", caster, "Abilities\\Weapons\\IllidanMissile\\IllidanMissile.mdl" )
    set castereffect[3] = GetLastCreatedEffectBJ()
    call AddSpecialEffectTargetUnitBJ( "foot left", caster, "Abilities\\Weapons\\IllidanMissile\\IllidanMissile.mdl" )
    set castereffect[4] = GetLastCreatedEffectBJ()
    call TriggerSleepAction( 0.01 )
    call SetUnitPositionLocFacingLocBJ( caster, GetUnitLoc(target), GetUnitLoc(target) )
    call SetUnitAnimation( caster, "attack" )
    call PlaySoundAtPointBJ( slice[GetRandomInt(1, 3)], 100, GetUnitLoc(caster), 0 )
    call UnitDamageTarget( caster, target, damage[level], true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
loop
    exitwhen hits == 0
    set hits = (hits-1)
    call TriggerSleepAction( 0.15 )
    call ForGroupBJ( GetRandomSubGroup(1, GetUnitsInRangeOfLocMatching(500.00, GetUnitLoc(target), Condition(GetBooleanAnd( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(caster)== true ), ( GetFilterUnit() != target ) , set target = GetEnumUnit() )
    call SetUnitPositionLocFacingLocBJ( caster, GetUnitLoc(target), GetUnitLoc(target) )
    call SetUnitAnimation( caster, "attack" )
    call PlaySoundAtPointBJ( slice[GetRandomInt(1, 3)], 100, GetUnitLoc(caster), 0 )
    call UnitDamageTarget( caster, target, damage[level], true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
endloop 
    call SetUnitTimeScalePercent( caster, 100.00 )
    call DestroyEffectBJ( castereffect[1] )
    call DestroyEffectBJ( castereffect[2] )
    call DestroyEffectBJ( castereffect[3] )
    call DestroyEffectBJ( castereffect[4] )
    set caster = null
    set target = null
    set castereffect[1] = null
    set castereffect[2] = null
    set castereffect[3] = null
    set castereffect[4] = null
    set slice[1] = null
    set slice[2] = null
    set slice[3] = null
endfunction

This spell was made by U.V
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
Dont use that many BJ-Function, that just call other functions^^

For example use
JASS:
DestroyEffect()
for
JASS:
DestroyEffectBJ()

If you're using jass-craft, then you can see why ;)

Also if your using
JASS:
ForGroupBJ
, dont forget to set
JASS:
set bj_wantDestroyGroup=true
before it, otherwise you will be leaking one group.

The Line
JASS:
call ForGroupBJ( GetRandomSubGroup(1, GetUnitsInRangeOfLocMatching(500.00, GetUnitLoc(target), Condition(GetBooleanAnd( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(caster)== true ), ( GetFilterUnit() != target ) , set target = GetEnumUnit() )
is creating some syntax errors in my jass craft, i guess there are some ')' missing. Your sure its working?

Anyways i recommand you to use
JASS:
native GroupEnumUnitsInRangeOfLoc           takes group whichGroup, location whichLocation, real radius, boolexpr filter returns nothing
and pick your units with your own loop.
But if you want to do it like this, you should at least clear your trigger a bit ^^

greets
 
Status
Not open for further replies.
Top