HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Spell - Dark Ritual - (Cs Error/Refund mana problems)

01-05-2007, 11:48 AM#1
Fulla
Firstly, It seems Dark Ritual/Death Pact are hardcoded to only be castable on Undead type units?
So I thought id quickly make custom versions>

Ive been having difficulties getting the
- If cast is already at full Mana, prevent him casting.

Is there a way to prevent the spell from being cast in first place, instead of refunding?
Currently the refund mana doesnt seem to work properly.
(I double checked mana cost of spell = to refund values I have).

Here is current code

Collapse JASS:
      //####################################################################################\\
      //                            Spell Name: Dark Ritual                                 \\
      //                            Spell Auth: Fulla                                       \\
      //####################################################################################\\


               //################################################################\\
               //                                                                \\
               //                     Configuration Section                      \\
               //                                                                \\
               //################################################################\\


constant function Dark_Ritual_AbilId takes nothing returns integer
    return 'A07W'
endfunction

constant function Dark_Ritual_Error_Msg takes nothing returns string
    return "Lich is already at full mana"
endfunction

constant function Dark_Ritual_SFX_Caster takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualCaster.mdl"
endfunction

constant function Dark_Ritual_SFX_Target takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl"
endfunction

constant function Dark_Ritual_Life takes integer lvl returns real
    if (lvl != 5) then
        return (lvl * 0.25) + 0.
    endif
    return 1.50
endfunction

constant function Dark_Ritual_Refund_Mana takes integer lvl returns real
    if (lvl != 5) then
        return (lvl * 5) + 25.
    endif
    return 55.
endfunction


               //################################################################\\
               //                                                                \\
               //                        Spell Section                           \\
               //                                                                \\
               //################################################################\\

function Trig_Dark_Ritual_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Dark_Ritual_AbilId() 
endfunction

function Trig_Dark_Ritual_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()    
    local unit targ = GetSpellTargetUnit()
    local integer lvl = GetUnitAbilityLevel(cast, Dark_Ritual_AbilId())
    local real life = Dark_Ritual_Life(lvl)
    local real refund = Dark_Ritual_Refund_Mana(lvl)
    local real manamax = GetUnitState(cast, UNIT_STATE_MAX_MANA)
    local real manacur = GetUnitState(cast, UNIT_STATE_MANA)
    local real hp = GetUnitState(targ, UNIT_STATE_LIFE)
    local real newhp = life * hp
    
    if manamax == manacur then
    call IssueImmediateOrder(cast, "stop")
    call SetUnitState(cast, UNIT_STATE_MANA, manacur + refund) 
    call CS_Error(GetOwningPlayer(cast), Dark_Ritual_Error_Msg())
    else
    call DestroyEffect(AddSpecialEffectTarget(Dark_Ritual_SFX_Caster(), cast, "origin"))
    call DestroyEffect(AddSpecialEffectTarget(Dark_Ritual_SFX_Target(), targ, "origin"))
    call KillUnit(targ)
    call SetUnitState(cast, UNIT_STATE_MANA, manacur + newhp)
    endif
    
    set cast = null
    set targ = null
endfunction

//===========================================================================
function InitTrig_Dark_Ritual takes nothing returns nothing
    set gg_trg_Dark_Ritual = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Dark_Ritual, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Dark_Ritual, Condition( function Trig_Dark_Ritual_Conditions ) )
    call TriggerAddAction( gg_trg_Dark_Ritual, function Trig_Dark_Ritual_Actions )
endfunction             

thx for any help.
01-05-2007, 11:59 AM#2
Vexorian
You need to handle 2 events here. One of them is constant playerunitevent EVENT_PLAYER_UNIT_SPELL_CAST

When this event executes when a unit is about to cast an spell but it didn't spend mana/cooldown yet, so if you stop the unit during this event you won't have to refill mana.

Then you need to handle EVENT_PLAYER_UNIT_SPELL_EFFECT to do the actual spell.
01-05-2007, 03:36 PM#3
Fulla
Ok, id be grateful if some1 could show me how to combine these 2 triggers into one.

Although its not really a big deal, I guess its just more 'pro' :D

This is simply Dark Ritual.

Collapse JASS:
      //####################################################################################\\
      //                            Spell Name: Dark Ritual                                 \\
      //                            Spell Auth: Fulla                                       \\
      //####################################################################################\\


               //################################################################\\
               //                                                                \\
               //                     Configuration Section                      \\
               //                                                                \\
               //################################################################\\


constant function Dark_Ritual_AbilId takes nothing returns integer
    return 'A07W'
endfunction

constant function Dark_Ritual_SFX_Caster takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualCaster.mdl"
endfunction

constant function Dark_Ritual_SFX_Target takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl"
endfunction

constant function Dark_Ritual_Life takes integer lvl returns real
    if (lvl != 5) then
        return (lvl * 0.25) + 0.
    endif
    return 1.50
endfunction


               //################################################################\\
               //                                                                \\
               //                        Spell Section                           \\
               //                                                                \\
               //################################################################\\

function Trig_Dark_Ritual_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Dark_Ritual_AbilId() 
endfunction

function Trig_Dark_Ritual_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()    
    local unit targ = GetSpellTargetUnit()
    local integer lvl = GetUnitAbilityLevel(cast, Dark_Ritual_AbilId())
    local real life = Dark_Ritual_Life(lvl)
    local real manamax = GetUnitState(cast, UNIT_STATE_MAX_MANA)
    local real manacur = GetUnitState(cast, UNIT_STATE_MANA)
    local real hp = GetUnitState(targ, UNIT_STATE_LIFE)
    local real newhp = life * hp
    
    call DestroyEffect(AddSpecialEffectTarget(Dark_Ritual_SFX_Caster(), cast, "origin"))
    call DestroyEffect(AddSpecialEffectTarget(Dark_Ritual_SFX_Target(), targ, "origin"))
    call KillUnit(targ)
    call SetUnitState(cast, UNIT_STATE_MANA, manacur + newhp)
    
    set cast = null
    set targ = null
endfunction

//===========================================================================
function InitTrig_Dark_Ritual takes nothing returns nothing
    set gg_trg_Dark_Ritual = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Dark_Ritual, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Dark_Ritual, Condition( function Trig_Dark_Ritual_Conditions ) )
    call TriggerAddAction( gg_trg_Dark_Ritual, function Trig_Dark_Ritual_Actions )
endfunction             

This is if Cast is at max mana when attempting to cast Dark Ritual

Collapse JASS:
      //####################################################################################\\
      //                            Spell Name: Dark Ritual                                 \\
      //                            Spell Auth: Fulla                                       \\
      //####################################################################################\\


               //################################################################\\
               //                                                                \\
               //                     Configuration Section                      \\
               //                                                                \\
               //################################################################\\


constant function Dark_Ritual2_AbilId takes nothing returns integer
    return 'A07W'
endfunction

constant function Dark_Ritual2_Error_Msg takes nothing returns string
    return "Lich is already at full mana"
endfunction


               //################################################################\\
               //                                                                \\
               //                        Spell Section                           \\
               //                                                                \\
               //################################################################\\

function Trig_Dark_Ritual2_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Dark_Ritual_AbilId() 
endfunction

function Trig_Dark_Ritual2_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()    
    local integer lvl = GetUnitAbilityLevel(cast, Dark_Ritual2_AbilId())
    local real manamax = GetUnitState(cast, UNIT_STATE_MAX_MANA)
    local real manacur = GetUnitState(cast, UNIT_STATE_MANA)

    
    if manamax == manacur then
    call IssueImmediateOrder(cast, "stop")
    call CS_Error(GetOwningPlayer(cast), Dark_Ritual2_Error_Msg())
    else
    endif
    
    set cast = null
endfunction

//===========================================================================
function InitTrig_Dark_Ritual2 takes nothing returns nothing
    set gg_trg_Dark_Ritual2 = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Dark_Ritual2, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition( gg_trg_Dark_Ritual2, Condition(function Trig_Dark_Ritual2_Conditions) )
    call TriggerAddAction( gg_trg_Dark_Ritual2, function Trig_Dark_Ritual2_Actions)
endfunction             
01-05-2007, 05:42 PM#4
moyack
Well, This is how it would look your spell. I really love JASS, in gui you have to repeat code several times :P

Collapse Spell improved:
      //####################################################################################\\
      //                            Spell Name: Dark Ritual                                 \\
      //                            Spell Auth: Fulla                                       \\
      //####################################################################################\\


               //################################################################\\
               //                                                                \\
               //                     Configuration Section                      \\
               //                                                                \\
               //################################################################\\


constant function Dark_Ritual_AbilId takes nothing returns integer
    return 'A07W'
endfunction

constant function Dark_Ritual_SFX_Caster takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualCaster.mdl"
endfunction

constant function Dark_Ritual_SFX_Target takes nothing returns string
    return "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl"
endfunction

constant function Dark_Ritual_Error_Msg takes nothing returns string
    return "Lich is already at full mana"
endfunction

constant function Dark_Ritual_Life takes integer lvl returns real
    if (lvl != 5) then
        return (lvl * 0.25) + 0.
    endif
    return 1.50
endfunction


               //################################################################\\
               //                                                                \\
               //                        Spell Section                           \\
               //                                                                \\
               //################################################################\\

function Trig_Dark_Ritual_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Dark_Ritual_AbilId() 
endfunction

function Trig_Dark_Ritual2_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()    
    local integer lvl = GetUnitAbilityLevel(cast, Dark_Ritual_AbilId())
    local real manamax = GetUnitState(cast, UNIT_STATE_MAX_MANA)
    local real manacur = GetUnitState(cast, UNIT_STATE_MANA)

    
    if manamax == manacur then
    call IssueImmediateOrder(cast, "stop")
    call CS_Error(GetOwningPlayer(cast), Dark_Ritual_Error_Msg())
    endif
    
    set cast = null
endfunction

function Trig_Dark_Ritual_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()    
    local unit targ = GetSpellTargetUnit()
    local integer lvl = GetUnitAbilityLevel(cast, Dark_Ritual_AbilId())
    local real life = Dark_Ritual_Life(lvl)
    local real manamax = GetUnitState(cast, UNIT_STATE_MAX_MANA)
    local real manacur = GetUnitState(cast, UNIT_STATE_MANA)
    local real hp = GetUnitState(targ, UNIT_STATE_LIFE)
    local real newhp = life * hp
    
    call DestroyEffect(AddSpecialEffectTarget(Dark_Ritual_SFX_Caster(), cast, "origin"))
    call DestroyEffect(AddSpecialEffectTarget(Dark_Ritual_SFX_Target(), targ, "origin"))
    call KillUnit(targ)
    call SetUnitState(cast, UNIT_STATE_MANA, manacur + newhp)
    
    set cast = null
    set targ = null
endfunction

//===========================================================================
function InitTrig_Dark_Ritual takes nothing returns nothing
    local trigger t1 = CreateTrigger()
    local trigger t2 = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t1, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t1, Condition( function Trig_Dark_Ritual_Conditions ) )
    call TriggerAddAction( t1, function Trig_Dark_Ritual_Actions )
    call TriggerRegisterAnyUnitEventBJ(t2, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition( t2, Condition(function Trig_Dark_Ritual_Conditions) )
    call TriggerAddAction( t2, function Trig_Dark_Ritual2_Actions)
    set t1 = null
    set t2 = null 
endfunction            
01-05-2007, 06:28 PM#5
Chuckle_Brother
Or you could make both triggers fire the same action and use GetTriggerEventId() to determine how its firing.
01-05-2007, 06:48 PM#6
Vexorian
There's no reason to do that unless the trigger is created dynamically thus saving you some cleanup code otherwise an event a trigger is good.