uberfoop
~=Admiral Stukov=~
- Reaction score
- 177
Mana Cost event
Requires:
vJass
Event by Jesus4Lyf
Description:
A snippet offering an event which can be used in a map instead of 'a unit starts the effect of an ability'. In addition to event responses filling the same function as the regular event, this event has an event response which gives the mana cost of the ability. It does, however, function slightly differently, which is described in the documentation of the trigger script:
A use demonstration is included in the demo map; use any ability and it will display general information about it.
Requires:
vJass
Event by Jesus4Lyf
Description:
A snippet offering an event which can be used in a map instead of 'a unit starts the effect of an ability'. In addition to event responses filling the same function as the regular event, this event has an event response which gives the mana cost of the ability. It does, however, function slightly differently, which is described in the documentation of the trigger script:
JASS:
//ManaCostEvent
//
//By uberfoop
//
//Requires:
//-vJass
//-Event
//
//Description:
//Replaces 'unit starts effect of an ability' events with a system
//that detects the mana cost of the ability. Register your spell
//trigger with the registration function in this system instead of
//the regular one to use. Event response functions are slightly
//different.
//
//Implimentation:
//Create a trigger called 'ManaCostEvent', go to edit -->
//"Convert to Custom Text", and replace everything in it
//with this script.
//
//Limitations and Quirks:
//-If for some reason you DO use the regular starts effect of
//ability event, do NOT modify a unit's mana in that thread or
//any other thread created to run instantly from that thread.
//-Disrupting a caster in a trigger from the special event
//will NOT stop the ability's basic effects from taking place,
//whereas with a regular event, it stops the effects, although
//mana is still lost.
//Like the normal event, does not detect autocast-on-attack
//abilities like searing arrows unless manually cast.
//
//Use:
//Register the event as you would regularily, but with:
//RegisterSpellManaEvent(<trigger>)
//
//Use the following event response functions:
//
//function GetSpellManaCost takes nothing returns real
//--Returns the mana cost of the spell
//
//function GetSpellManaCaster takes nothing returns unit
//--Replaces GetSpellAbilityUnit and GetTriggerUnit
//
//function GetSpellManaTarget takes nothing returns unit
//--Replaces GetSpellTargetUnit
//
//function GetSpellManaId takes nothing returns integer
//--Replaces GetSpellAbilityId
//
//function GetSpellManaX takes nothing returns real
//function GetSpellManaY takes nothing returns real
//--Replaces GetSpellTargetX and GetSpellTargetY
//
//========================================================
library Mana initializer Init requires Event
private struct Packet
unit SpellAbilityUnit
unit SpellTargetUnit
integer SpellRawcode
real SpellX
real SpellY
real Mana
endstruct
globals
private Event ManaCostEvent
private Packet P
private timer ManaT = CreateTimer()
private Packet array PA
private integer PacketCount = -1
endglobals
//===Event Response===
function GetSpellManaCaster takes nothing returns unit
return P.SpellAbilityUnit
endfunction
function GetSpellManaTarget takes nothing returns unit
return P.SpellTargetUnit
endfunction
function GetSpellManaId takes nothing returns integer
return P.SpellRawcode
endfunction
function GetSpellManaX takes nothing returns real
return P.SpellX
endfunction
function GetSpellManaY takes nothing returns real
return P.SpellY
endfunction
function GetSpellManaCost takes nothing returns real
return P.Mana
endfunction
//====================
private function ManaCostCallback takes nothing returns nothing
loop
set P = PA[PacketCount]
set P.Mana = P.Mana - GetUnitState(P.SpellAbilityUnit,UNIT_STATE_MANA)
call ManaCostEvent.fire()
call P.destroy()
set PacketCount = PacketCount - 1
exitwhen PacketCount == -1
endloop
endfunction
private function RunManaCost takes nothing returns boolean
local Packet D = Packet.create()
set D.SpellAbilityUnit = GetTriggerUnit()
set D.SpellTargetUnit = GetSpellTargetUnit()
set D.SpellRawcode = GetSpellAbilityId()
set D.SpellX = GetSpellTargetX()
set D.SpellY = GetSpellTargetY()
set D.Mana = GetUnitState(D.SpellAbilityUnit,UNIT_STATE_MANA)
set PacketCount = PacketCount + 1
set PA[PacketCount] = D
call TimerStart(ManaT,0.,false,function ManaCostCallback)
return false
endfunction
function RegisterSpellManaEvent takes trigger t returns nothing
call ManaCostEvent.register(t)
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 RunManaCost))
set ManaCostEvent = Event.create()
endfunction
endlibrary
A use demonstration is included in the demo map; use any ability and it will display general information about it.