Units attacking allies with sleep

Kajik

New Member
Reaction score
4
Hello everyone,
I want to make spell which put targeted unit in sleep for some duration. My problem is that units allied with affected one are attacking it -> canceling spell effect. Is there any chance to turn this off (maybe in AI editor or gameplay constants)?
I know that Sleep has field named "stun duration", but that will make sleeping units INVULNERABLE -> thats unwanted (I want that unit to be attackable).
I hope you know how do I mean it, thanks for any constructive posts.
 

Faust

You can change this now in User CP.
Reaction score
123
JASS:
function Trig_Untitled_Trigger_001_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'AUsl' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_002_Conditions takes nothing returns boolean
    if ( not ( IsUnitInGroup(GetTriggerUnit(), udg_SleepingUnits) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    call GroupAddUnit(udg_SleepingUnits), GetTriggerUnit())
    call TriggerSleepAction(5)
    call GroupRemoveUnit(udg_SleepingUnits, GetTriggerUnit())
endfunction

function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    call IssueImmediateOrder(GetAttacker(), "stop")
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_002, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_001, Condition( function Trig_Untitled_Trigger_001_Conditions ) )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_002, Condition( function Trig_Untitled_Trigger_002_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_001_Actions )
endfunction


Create a new trigger, convert it to custom text, delete everything, copy the text above

Change the 5 in
JASS:


to any value, currently they can't attack it for 5 seconds.

Change the 'AUsl' to the rawcode of your sleep spell (to see rawcode of a spell, go to ability editor, press Ctrl + D, press again to switch back.


JASS:
if ( not ( GetSpellAbilityId() == 'AUsl' ) ) then


SleepingUnits is a Unit Group variable.
If you wish I could add 2 conditions, so units won't cast spells on it, and if you wake it up prior to 5 seconds, they can attack it.
 

Nina

New Member
Reaction score
8
Sorry but I was bored and I had nothing to do so I cleaned up your code a little and it will probably also help him because if he wants to learn JASS he doesn't want to get thrown into a not false true threesome relationship:p Hope your don't mind=o

JASS:
function CheckSpell takes nothing returns boolean
    return( GetSpellAbilityId() == 'AUsl' )
endfunction

function CheckUnitSleeps takes nothing returns boolean
    return( IsUnitInGroup(GetTriggerUnit(), udg_SleepingUnits) == true )
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call GroupAddUnit(udg_SleepingUnits), u)
    call TriggerSleepAction(5)
    call GroupRemoveUnit(udg_SleepingUnits, u)
endfunction

function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    local unit a = GetAttacker()
    call IssueImmediateOrder(a, "stop")
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_002, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_001, Condition( function CheckSpell ) )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_002, Condition( function CheckUnitSleeps ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_001_Actions )
endfunction


-Nina
 

Kajik

New Member
Reaction score
4
I am doing spells in JASS, I just didnt know that IssueImmediateOrder(GetAttacker(), "stop")
will cancel attack before first hit.
Thanks a lot!!!
 

Nina

New Member
Reaction score
8
It will cancel it because of the event EVENT_PLAYER_UNIT_ATTACKED which is triggered when the owner of a unit command its to attack. If you ever want to detect when the unit actually gets hit instead of issued the order to attack you should search for a damage detection system but in this case EVENT_PLAYER_UNIT_ATTACKED is what you need just wanted to point that out.
 

Kajik

New Member
Reaction score
4
Well, it just didnt work as intended, so I reworked it a bit. There is final, working version:

JASS:
function Sap_Conditions takes nothing returns boolean
    // Check if the attacked unit have "sleep buff"
    // Filter allied units, I want my own units to be able to attack
    return ( GetUnitAbilityLevel(GetTriggerUnit(),'B016') > 0 and IsUnitAlly(GetAttacker(),GetOwningPlayer(GetTriggerUnit())))
endfunction

function Sap_Actions takes nothing returns nothing
    call IssueImmediateOrder(GetAttacker(), "stop")
endfunction

//===========================================================================
function InitTrig_Sap takes nothing returns nothing
    local trigger Sap = CreateTrigger()  
    call TriggerRegisterAnyUnitEventBJ( Sap, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( Sap, Condition( function Sap_Conditions ) )
    call TriggerAddAction( Sap, function Sap_Actions )
    set Sap = null 
endfunction


I can set up duration and buff in spell options, so I just need check if attacker is allied with attacked unit and attacked unit has "sleep buff". But thanks anyway for stop order idea.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top