Help with Spell in target AoE

rafaxik

New Member
Reaction score
2
Hi,

I had an idea but I can't do it by myself yet =/
Well, see the description:
The Hero creates effects in a target area, dealing damage and sucking mana for himself.

Actually, I want to damage as flame strike/blizzard does to enemy units, but gaining all mana drained from those units at the end of the spell effect or when it leaves that area.

Please, I just know a bit of GUI and a small idea of MUI, so don't make it JASS.

Help me please :D
 

Ashlebede

New Member
Reaction score
43
Ain't used to GUI enough to make that timer stuff. Could make it in JASS, though.

Anyways, here are some clues : you'd need a timer that picks every unit in range of the spell target location (you'd have to store that location in a variable) and check if the units in range of the location have enough mana, are alive and are enemies. If all the conditions are true, it reduces their mana and gives it to the caster (saved through another variable).

Now, the timer should be a repeating countdown timer that expires every, say, .5 second.

Again, I ain't sure how I would make it Multi-Unit instanceable in GUI.
 

Ayanami

칼리
Reaction score
288
Adding on to Ashlebede's post, the easiest way to achieve MUI in GUI is to use hashtable.
 

tommerbob

Minecraft. :D
Reaction score
110
You could trigger the Flame Strike using a dummy unit. Add the dummy unit to a unit group.

Whenever a unit takes damage, you can check if the damage source is in the above unit group. If it is, you can trigger any extra damage, or drain mana. Then put the drained mana in a variable, and add it to the unit that cast the spell.
 

rafaxik

New Member
Reaction score
2
Ain't used to GUI enough to make that timer stuff. Could make it in JASS, though.

Anyways, here are some clues : you'd need a timer that picks every unit in range of the spell target location (you'd have to store that location in a variable) and check if the units in range of the location have enough mana, are alive and are enemies. If all the conditions are true, it reduces their mana and gives it to the caster (saved through another variable).

Now, the timer should be a repeating countdown timer that expires every, say, .5 second.

Again, I ain't sure how I would make it Multi-Unit instanceable in GUI.

I just don't understand JASS =/
but if you know it only in JASS, post it and I'll try to get it.
Anyway, I tried to do something like this:
Trigger:
  • CastManaBurnStrike
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Mana Burn Strike
    • Actions
      • Set mbstrikepoint = (Target point of ability being cast)
      • Set mbstrikeunit = (Casting unit)
      • Set mbstrikegroup = (Units within 450.00 of mbstrikepoint matching ((((Matching unit) has buff Mana Burn Strike ) Equal to True) and ((((Matching unit) belongs to an enemy of (Owner of mbstrikeunit)) Equal to True) and (((Matching unit) is alive) Equal to True))))
      • Unit Group - Pick every unit in mbstrikegroup and do (Actions)
        • Loop - Actions
          • Set mbstrikeunit2 = (Picked unit)
          • Unit - Create (Number of units in mbstrikegroup) dummy01 for (Owner of mbstrikeunit) at (Position of mbstrikeunit2) facing Default building facing degrees
          • Set mbstrikeunit3 = (Last created unit)
          • Set mbstrikeinitialmana = (Mana of mbstrikeunit3)
          • Unit - Add siphon mana dummy ability to mbstrikeunit2
          • Unit - Order mbstrikeunit3 to Human Blood Mage - Siphon Mana mbstrikeunit2
          • Unit - Add a 16.00 second Generic expiration timer to mbstrikeunit3
          • Countdown Timer - Start mbstriketime1 as a One-shot timer that will expire in 16.00 seconds
          • Set mbstriketime1 = (Last started timer)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (mbstrikeunit2 has buff Mana Burn Strike ) Equal to False
            • Then - Actions
              • Unit - Set the custom value of mbstrikeunit2 to (Integer((Elapsed time for mbstriketime1)))
              • Set mbstrikeinteger = (Integer((Elapsed time for mbstriketime1)))
              • Unit - Set mana of mbstrikeunit to ((Mana of mbstrikeunit) + (Real((Point-value of mbstrikeunit2))))
            • Else - Actions
              • Do nothing
      • Custom script: call RemoveLocation (udg_mbstrikepoint)
      • Set mbstrikeunit = No unit
      • Custom script: call DestroyGroup (udg_mbstrikegroup)
      • Set mbstrikeunit2 = No unit
      • Set mbstrikeunit3 = No unit

I just set my dummy unit to have maximum mana and a small cast range of the siphon mana dummy ability.
Ps: I didn't test yet

EDIT: I based the hero ability in flame strike, and it gives the damage i want. And based the dummy ability in siphon mana
EDIT2: Tested... Didn't work
 

Ashlebede

New Member
Reaction score
43
I'm going to make that trigger a JASS trigger then. Shouldn't take too long, I'm starting right now. o_O

Edit : Done. Didn't test, but it should work as intended. You need 2 global variables ; a variable named "H" of type Hashtable and a variable named "owner" of type Player. You need to initialize the hashtable at map initialization:

Trigger:
  • Hashtable Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set H = (Last created hashtable)


You also need to change the Raw code on the second line ('A000') to that of your ability, keeping it between simple-quotes. See commented text.

JASS:
function Trig_MyTrigger_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A000' //IMPORTANT: Replace this with your ability's raw code
                                       // it can be found by pressing CTRL+D in the object editor
endfunction

function Trig_MyTrigger_Enum_Conds takes nothing returns boolean
    //here we check if the unit is an enemy, has mana and is alive
    return IsUnitEnemy(GetFilterUnit(),udg_owner) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE)>0 and GetUnitState(GetFilterUnit(),UNIT_STATE_MANA)>0
endfunction

function Trig_MyTrigger_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    
    local integer i = LoadInteger(udg_H,GetHandleId(t),0)
    local unit caster = LoadUnitHandle(udg_H,GetHandleId(t),1)
    local location loc = LoadLocationHandle(udg_H,GetHandleId(t),2)
    
    local group g = null
    local unit f = null
    
    if i<10 then //change the number to (Duration in seconds * 2)
        
        // here, we pick all units within 500.00 range. Change "500." to the desired range
        // you need a global variable of type player and of name "owner" declared using CTRL+B (case sensitive)
        set udg_owner = GetOwningPlayer(caster)
        call GroupEnumUnitsInRange(g,GetLocationX(loc),GetLocationY(loc),500.,Condition(function Trig_MyTrigger_Enum_Conds))
    
    //loop for the group's actions
        loop
            set f = FirstOfGroup(g)
                exitwhen f==null //exit this loop when there is no unit in the group
            call SetUnitState(f,UNIT_STATE_MANA,GetUnitState(f,UNIT_STATE_MANA)-10)//change "10" to (Mana drain per second/2)
            call SetUnitState(caster,UNIT_STATE_MANA,GetUnitState(caster,UNIT_STATE_MANA)+10)//same here
            call GroupRemoveUnit(g,f)
        endloop
        
        call DestroyGroup(g)//to avoid leaks
        
        //adds one to the loop counter and saves it in the hashtable
        call SaveInteger(udg_H,GetHandleId(t),0,i+1)
        
    else //the duration is passed, we need to delete the variables.
    
        call RemoveLocation(loc)//to avoid leaks
        call FlushChildHashtable(udg_H,GetHandleId(t))//to avoid leaks
        call DestroyTimer(t)//to end the effect & avoid leaks
        
    endif
    
endfunction

function Trig_MyTrigger_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    
    // here we store an integer, the caster and the spell target location in the hashtable
    call SaveInteger(udg_H,GetHandleId(t),0,0) // int (counter)
    call SaveUnitHandle(udg_H,GetHandleId(t),1,GetTriggerUnit()) //caster
    call SaveLocationHandle(udg_H,GetHandleId(t),2,GetSpellTargetLoc()) //spell target loc
    
    //starts timer as a repeating timer that will expire in .5 seconds
    call TimerStart(t,.5,true,function Trig_MyTrigger_Timer)
endfunction

//===========================================================================
function InitTrig_MyTrigger takes nothing returns nothing //change "MyTrigger" to the name of the trigger
                                                          // (replace spaces with "_")
                                                          
    set gg_trg_MyTrigger = CreateTrigger(  ) //also change "MyTrigger" on this line and the following ones
    
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MyTrigger,EVENT_PLAYER_UNIT_SPELL_EFFECT)//such as this one
    
    call TriggerAddCondition(gg_trg_MyTrigger,Condition(function Trig_MyTrigger_Conditions))
    call TriggerAddAction( gg_trg_MyTrigger, function Trig_MyTrigger_Actions )
endfunction


You'll also need to change a couple other things, such as the Area of effect and the number of loops to make (which is equal to (Duration in seconds * 2))

Just read all that commented green text and you should be able to understand how it works, more or less. When you read it, unlike what you may think, the trigger somewhat starts at the bottom. So the initialization is at the bottom, then right above is the actions. Above that is the code executed when the timer expires. The conditions are at the very top, though.

I commented it as much as possible to make it easier to understand. :D

Also do not change the names of the functions unless you change it everywhere ; it might make some naming issues. Just don't change whatever is after the keyword "function"
 

rafaxik

New Member
Reaction score
2
You'll also need to change a couple other things, such as the Area of effect and the number of loops to make (which is equal to (Duration in seconds * 2))

Just read all that commented green text and you should be able to understand how it works, more or less. When you read it, unlike what you may think, the trigger somewhat starts at the bottom. So the initialization is at the bottom, then right above is the actions. Above that is the code executed when the timer expires. The conditions are at the very top, though.

I commented it as much as possible to make it easier to understand. :D

Also do not change the names of the functions unless you change it everywhere ; it might make some naming issues. Just don't change whatever is after the keyword "function"

JASS:
function Trig_MBstrike_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A007' //IMPORTANT: Replace this with your ability's raw code
                                       // it can be found by pressing CTRL+D in the object editor
endfunction

function Trig_MBstrike_Enum_Conds takes nothing returns boolean
    //here we check if the unit is an enemy, has mana and is alive
    return IsUnitEnemy(GetFilterUnit(),udg_owner) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE)>0 and GetUnitState(GetFilterUnit(),UNIT_STATE_MANA)>0
endfunction

function Trig_MBstrike_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    
    local integer i = LoadInteger(udg_H,GetHandleId(t),0)
    local unit caster = LoadUnitHandle(udg_H,GetHandleId(t),1)
    local location loc = LoadLocationHandle(udg_H,GetHandleId(t),2)
    
    local group g = null
    local unit f = null
    
    if i<16 then //change the number to (Duration in seconds * 2)
        
        // here, we pick all units within 500.00 range. Change "500." to the desired range
        // you need a global variable of type player and of name "owner" declared using CTRL+B (case sensitive)
        set udg_owner = GetOwningPlayer(caster)
        call GroupEnumUnitsInRange(g,GetLocationX(loc),GetLocationY(loc),500.,Condition(function Trig_MBstrike_Enum_Conds))
    
    //loop for the group's actions
        loop
            set f = FirstOfGroup(g)
                exitwhen f==null //exit this loop when there is no unit in the group
            call SetUnitState(f,UNIT_STATE_MANA,GetUnitState(f,UNIT_STATE_MANA)-60)//change "10" to (Mana drain per second/2)
            call SetUnitState(caster,UNIT_STATE_MANA,GetUnitState(caster,UNIT_STATE_MANA)+60)//same here
        endloop
        
        call DestroyGroup(g)//to avoid leaks
        
        //adds one to the loop counter and saves it in the hashtable
        call SaveInteger(udg_H,GetHandleId(t),0,i+1)
        
    else //the duration is passed, we need to delete the variables.
    
        call RemoveLocation(loc)//to avoid leaks
        call FlushChildHashtable(udg_H,GetHandleId(t))//to avoid leaks
        call DestroyTimer(t)//to end the effect & avoid leaks
        
    endif
    
endfunction

function Trig_MBstrike_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    
    // here we store an integer, the caster and the spell target location in the hashtable
    call SaveInteger(udg_H,GetHandleId(t),0,0) // int (counter)
    call SaveUnitHandle(udg_H,GetHandleId(t),1,GetTriggerUnit()) //caster
    call SaveLocationHandle(udg_H,GetHandleId(t),2,GetSpellTargetLoc()) //spell target loc
    
    //starts timer as a repeating timer that will expire in .05 seconds
    call TimerStart(t,.05,true,function Trig_MBstrike_Timer)
endfunction

//===========================================================================
function InitTrig_MBstrike takes nothing returns nothing //change "MBstrike" to the name of the trigger
                                                          // (replace spaces with "_")
                                                          
    set gg_trg_MBstrike = CreateTrigger(  ) //also change "MBstrike" on this line and the following ones
    
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MBstrike,EVENT_PLAYER_UNIT_SPELL_EFFECT)//such as this one
    
    call TriggerAddCondition(gg_trg_MBstrike,Condition(function Trig_MBstrike_Conditions))
    call TriggerAddAction( gg_trg_MBstrike, function Trig_MBstrike_Actions )
endfunction

I tried this. Didn't work... Any suggestions?

EDIT: Only "H" hashtable was the only one variable created.
 

hgkjfhfdsj

Active Member
Reaction score
55
JASS:
>  local group g = null
local group g = CreateGroup() //consider using global group, but dw for now


also did you include the GUI part (initializing the hashtable)?
if not,
JASS:
function InitTrig_MyTrigger takes nothing returns nothing //change "MyTrigger" to the name of the trigger                                                                                                               
    set gg_trg_MyTrigger = CreateTrigger(  )   
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MyTrigger,EVENT_PLAYER_UNIT_SPELL_EFFECT)   
    call TriggerAddCondition(gg_trg_MyTrigger,Condition(function Trig_MyTrigger_Conditions))
    call TriggerAddAction( gg_trg_MyTrigger, function Trig_MyTrigger_Actions )
    
    set udg_H = InitHashtable() //can be initialized here as well
endfunction
 

Ashlebede

New Member
Reaction score
43
Sorry, I had to go off for a while. Anyways, forgetful as I am, I forgot a crucial line:

JASS:
call GroupRemoveUnit(g,f)


I added it to my original script, apparently only after you copied it... oh, well...

@hgkj

How would using a global group help? It's more trouble if you have to initialize it with CTRL+B and even the variable just existing will waste memory space. The spell is also supposed to be MUI.

(I wanted to set it to null so I can create it only after the if, so we don't create the group unnecessarily... I am pretty forgetful, indeed... o_O)
 

rafaxik

New Member
Reaction score
2
JASS:
>  local group g = null
local group g = CreateGroup() //consider using global group, but dw for now


also did you include the GUI part (initializing the hashtable)?
if not,
JASS:
function InitTrig_MyTrigger takes nothing returns nothing //change "MyTrigger" to the name of the trigger                                                                                                               
    set gg_trg_MyTrigger = CreateTrigger(  )   
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MyTrigger,EVENT_PLAYER_UNIT_SPELL_EFFECT)   
    call TriggerAddCondition(gg_trg_MyTrigger,Condition(function Trig_MyTrigger_Conditions))
    call TriggerAddAction( gg_trg_MyTrigger, function Trig_MyTrigger_Actions )
    
    set udg_H = InitHashtable() //can be initialized here as well
endfunction

Sorry, I had to go off for a while. Anyways, forgetful as I am, I forgot a crucial line:

JASS:
call GroupRemoveUnit(g,f)


I added it to my original script, apparently only after you copied it... oh, well...

@hgkj

How would using a global group help? It's more trouble if you have to initialize it with CTRL+B and even the variable just existing will waste memory space. The spell is also supposed to be MUI.

(I wanted to set it to null so I can create it only after the if, so we don't create the group unnecessarily... I am pretty forgetful, indeed... o_O)

I did create the Hashtable trigger...

When I get home, I'll try it, Ashlebede.
 

rafaxik

New Member
Reaction score
2
Sorry, I had to go off for a while. Anyways, forgetful as I am, I forgot a crucial line:

JASS:
call GroupRemoveUnit(g,f)


I added it to my original script, apparently only after you copied it... oh, well...

@hgkj

How would using a global group help? It's more trouble if you have to initialize it with CTRL+B and even the variable just existing will waste memory space. The spell is also supposed to be MUI.

(I wanted to set it to null so I can create it only after the if, so we don't create the group unnecessarily... I am pretty forgetful, indeed... o_O)

Jeez...
I just don't understand JASS... Where I can put that line?
My trigger's now:
JASS:
function Trig_MBstrike_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A007' //IMPORTANT: Replace this with your ability's raw code
                                       // it can be found by pressing CTRL+D in the object editor
endfunction

function Trig_MBstrike_Enum_Conds takes nothing returns boolean
    //here we check if the unit is an enemy, has mana and is alive
    return IsUnitEnemy(GetFilterUnit(),udg_owner) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE)>0 and GetUnitState(GetFilterUnit(),UNIT_STATE_MANA)>0
endfunction

function Trig_MBstrike_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    
    local integer i = LoadInteger(udg_H,GetHandleId(t),0)
    local unit caster = LoadUnitHandle(udg_H,GetHandleId(t),1)
    local location loc = LoadLocationHandle(udg_H,GetHandleId(t),2)
    
    local group g = null
    local unit f = null
    
    if i<16 then //change the number to (Duration in seconds * 2)
        
        // here, we pick all units within 500.00 range. Change "500." to the desired range
        // you need a global variable of type player and of name "owner" declared using CTRL+B (case sensitive)
        set udg_owner = GetOwningPlayer(caster)
        call GroupEnumUnitsInRange(g,GetLocationX(loc),GetLocationY(loc),500.,Condition(function Trig_MBstrike_Enum_Conds))
    
    //loop for the group's actions
        loop
            set f = FirstOfGroup(g)
                exitwhen f==null //exit this loop when there is no unit in the group
            call SetUnitState(f,UNIT_STATE_MANA,GetUnitState(f,UNIT_STATE_MANA)-60)//change "10" to (Mana drain per second/2)
            call SetUnitState(caster,UNIT_STATE_MANA,GetUnitState(caster,UNIT_STATE_MANA)+60)//same here
        endloop
        
        call DestroyGroup(g)//to avoid leaks
        
        //adds one to the loop counter and saves it in the hashtable
        call SaveInteger(udg_H,GetHandleId(t),0,i+1)
        
    else //the duration is passed, we need to delete the variables.
    
        call RemoveLocation(loc)//to avoid leaks
        call FlushChildHashtable(udg_H,GetHandleId(t))//to avoid leaks
        call DestroyTimer(t)//to end the effect & avoid leaks
        
    endif
    
endfunction

function Trig_MBstrike_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    
    // here we store an integer, the caster and the spell target location in the hashtable
    call SaveInteger(udg_H,GetHandleId(t),0,0) // int (counter)
    call SaveUnitHandle(udg_H,GetHandleId(t),1,GetTriggerUnit()) //caster
    call SaveLocationHandle(udg_H,GetHandleId(t),2,GetSpellTargetLoc()) //spell target loc
    
    //starts timer as a repeating timer that will expire in .05 seconds
    call TimerStart(t,.05,true,function Trig_MBstrike_Timer)
endfunction

//===========================================================================
function InitTrig_MBstrike takes nothing returns nothing //change "MBstrike" to the name of the trigger
                                                          // (replace spaces with "_")
                                                          
    set gg_trg_MBstrike = CreateTrigger(  ) //also change "MBstrike" on this line and the following ones
    
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MBstrike,EVENT_PLAYER_UNIT_SPELL_EFFECT)//such as this one
    
    call TriggerAddCondition(gg_trg_MBstrike,Condition(function Trig_MBstrike_Conditions))
    call TriggerAddAction( gg_trg_MBstrike, function Trig_MBstrike_Actions )
endfunction

Check my map attached
 

Attachments

  • (6)IceFever.w3x
    1.3 MB · Views: 97
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top