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

Make Paralyzing Cask spell to only bounce to organic units.

Level 14
Joined
Jul 19, 2007
Messages
772
So once again I have imported a spell into my map from a Dota Spellpack and this time I imported the "Paralyzing Cask" spell and it seems to be working like it should but the problem is that it even seems to bounce into buildings and wards for some reason. How can I make so it only bounces to organic units?
JASS:
//TESH.scrollpos=33
//TESH.alwaysfold=0
scope ParalyzingCask initializer Init

globals
    private constant integer AbilId = 'A0IO'
    private constant integer DumAbilId = 'A0IN'
    
    private integer I
endglobals
private struct data
    unit u
    player p
    unit targ
    integer lvl
    integer count = 1
    timer t
    
    method onDestroy takes nothing returns nothing
        call ReleaseTimer(.t)
    endmethod
endstruct

private function Cast takes unit cast,unit oldtarg,unit newtarg,integer lvl returns real
    local unit dum=CreateUnit(GetOwningPlayer(cast),CasterId,GetUnitX(oldtarg),GetUnitY(oldtarg),0.)

    call UnitAddAbility(dum,DumAbilId)
    call IssueTargetOrder(dum,"thunderbolt",newtarg)
    call UnitApplyTimedLife(dum,'BTLF',1.)
    set dum = null
    
    return DBU(oldtarg,newtarg)/500.
endfunction
private function Filt takes nothing returns boolean
    local data d = I
    
    if GetFilterUnit()!=d.targ and IsUnitVisible(GetFilterUnit(),d.p) and IsUnitEnemy(GetFilterUnit(),d.p) and GetWidgetLife(GetFilterUnit())>.405 then
        return true
    endif    
    return false
endfunction
private function GetTarget takes unit cast, unit targ, data d returns unit
    local group g=NewGroup()
    
    set I=d
    call GroupEnumUnitsInRange(g,GetUnitX(targ),GetUnitY(targ),575.,Condition(function Filt))
    set targ=GroupPickRandomUnit(g)
    call ReleaseGroup(g)
    
    return targ
endfunction
private function Check takes nothing returns nothing
    local data d = GetTimerData(GetExpiredTimer())
    local unit old
    
    set d.count = d.count + 1
    if IsUnitType(d.targ,UNIT_TYPE_HERO)==false then
        call UnitDamageTargetEx(d.u, d.targ, 50.+(25.*d.lvl), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_SPELL, false)
    else
        call UnitDamageTargetEx(d.u, d.targ, 50., ATTACK_TYPE_NORMAL, DAMAGE_TYPE_SPELL, false)
    endif
    if d.count<=d.lvl*2 then
        set old = d.targ
        set d.targ=GetTarget(d.u,d.targ,d)
        if d.targ!=null then
            call TimerStart(d.t,Cast(d.u,old,d.targ,d.lvl),false,function Check)    
        else
            call d.destroy()
        endif
        set old = null
    else
        call d.destroy()
    endif
endfunction
private function Actions takes nothing returns nothing
    local data d = data.create()
    
    set d.u=GetTriggerUnit()
    set d.p = GetOwningPlayer(d.u)
    set d.targ=GetSpellTargetUnit()
    set d.lvl=GetUnitAbilityLevel(d.u,AbilId)

    set d.t = NewTimer()
    call SetTimerData(d.t,d)
    call TimerStart(d.t,Cast(d.u,d.u,d.targ,d.lvl),false,function Check)
endfunction

private function Conds takes nothing returns boolean
    if GetSpellAbilityId()==AbilId then
        call Actions()
    endif
    return false
endfunction
private function Init takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t,Condition(function Conds))    
    call PreloadAbil(DumAbilId)
endfunction

endscope
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,558
vJASS:
if GetFilterUnit()!=d.targ and IsUnitVisible(GetFilterUnit(),d.p) and IsUnitEnemy(GetFilterUnit(),d.p) and GetWidgetLife(GetFilterUnit())>.405 then
^ You need to add a check for Organic units in that line of code.

Go into the Trigger Editor and create a new trigger. Then add a new Condition to the trigger that says:
  • ((Matching unit) is A structure) Equal to False
Now that you have the Condition you want to use, go to the Edit menu and click Convert To Custom Script. You'll now have some code, ignore most of it and look for the words that say something related to GetFilterUnit(). Copy only that line of code that looks similar to the code I posted above, try to match them if you're confused.

You can do this for any classification Condition -> Magic Immune, Invulnerable, Structure, etc...
 
Level 14
Joined
Jul 19, 2007
Messages
772
vJASS:
if GetFilterUnit()!=d.targ and IsUnitVisible(GetFilterUnit(),d.p) and IsUnitEnemy(GetFilterUnit(),d.p) and GetWidgetLife(GetFilterUnit())>.405 then
^ You need to add a check for Organic units in that line of code.

Go into the Trigger Editor and create a new trigger. Then add a new Condition to the trigger that says:
  • ((Matching unit) is A structure) Equal to False
Now that you have the Condition you want to use, go to the Edit menu and click Convert To Custom Script. You'll now have some code, ignore most of it and look for the words that say something related to GetFilterUnit(). Copy only that line of code that looks similar to the code I posted above, try to match them if you're confused.

You can do this for any classification Condition -> Magic Immune, Invulnerable, Structure, etc...
Well there is no option in World Editor that can check if an unit is organic as far as I can see.
 
Level 14
Joined
Jul 19, 2007
Messages
772
I tried to import the script into the unit check but I got this error.
error.png
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,558
vJASS:
if IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false
and GetFilterUnit()!=d.targ and IsUnitVisible(GetFilterUnit(),d.p) and IsUnitEnemy(GetFilterUnit(),d.p) and GetWidgetLife(GetFilterUnit())>.405 then
1697062508029.png
 
Level 14
Joined
Jul 19, 2007
Messages
772
vJASS:
if IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false
and GetFilterUnit()!=d.targ and IsUnitVisible(GetFilterUnit(),d.p) and IsUnitEnemy(GetFilterUnit(),d.p) and GetWidgetLife(GetFilterUnit())>.405 then
View attachment 450605
Thanks but I still got a little error message...
error.png
 
Top