- Joined
- Aug 19, 2008
- Messages
- 491
Header should say it all.
JASS:
library NewSpell initializer Init
//===========================================================================
//
// NewSpell
// =====================
// Written by Cheezeman
//
// If you also think that making new spells is a pain in the neck,
// then this is the module for you.
// Takes care of (hopefully) everything you'll need to create a spell
// in one, simple function call. Plus it's leakless.
//
//
// Functions
// =====================
// NewSpell( integer Spell_id, code Action_func ) -> trigger
// Just call this at map init somewhere and
// the spell is configured.
//
// Example:
// local trigger t = NewSpell( 'AHhl', function Actions )
//
// Miscellaneous notes
// =====================
// There are two versions of this module: One fast and one safe.
// This is the fast version, and I recommend it for smaller maps.
// If you're making a RPG-like map I'd recommend the safe version,
// since it's not limited by handle ids.
//
//
// =====================
// I Version 1.0 I
// I Made by Cheezeman I
// =====================
//
//===========================================================================
globals
private boolexpr Dummy_Filter
private integer array SpellId[40800]
private trigger t
endglobals
private function GetReducedHandleId takes handle h returns integer
return GetHandleId( h ) - 0x100000
endfunction
private constant function ReturnTrue takes nothing returns boolean
return true
endfunction
//===========================================================================
private function Cond takes nothing returns boolean
return GetSpellAbilityId() == SpellId[GetReducedHandleId( GetTriggeringTrigger() )]
endfunction
function NewSpell takes integer spell_id, code act returns trigger
local integer i = 0
set t = CreateTrigger()
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent( t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, Dummy_Filter )
set i = i + 1
exitwhen i > 15
endloop
set SpellId[GetReducedHandleId( t )] = spell_id
call TriggerAddCondition( t, Condition( function Cond ) )
call TriggerAddAction( t, act )
return t
endfunction
//===========================================================================
private function Init takes nothing returns nothing
set Dummy_Filter = Condition( function ReturnTrue )
endfunction
endlibrary
JASS:
library NewSpell initializer Init
//===========================================================================
//
// NewSpell
// =====================
// Written by Cheezeman
//
// If you also think that making new spells is a pain in the neck,
// then this is the module for you.
// Takes care of (hopefully) everything you'll need to create a spell
// in one, simple function call. Plus it's leakless.
//
//
// Functions
// =====================
// NewSpell( integer Spell_id, code Action_func ) -> trigger
// Just call this at map init somewhere and
// the spell is configured.
//
// Example:
// local trigger t = NewSpell( 'AHhl', function Actions )
//
// Miscellaneous notes
// =====================
// There are two versions of this module: One fast and one safe.
// This is the safe version, and I recommend it for larger maps.
// If you're making a AoS-like map I'd recommend the fast version,
// since it uses an integer array instead of hashtable.
//
//
// =====================
// I Version 1.0 I
// I Made by Cheezeman I
// =====================
//
//===========================================================================
globals
private boolexpr Dummy_Filter
private hashtable Hash
private trigger t
endglobals
private constant function ReturnTrue takes nothing returns boolean
return true
endfunction
//===========================================================================
private function Cond takes nothing returns boolean
return GetSpellAbilityId() == LoadInteger( Hash, 0, GetHandleId( GetTriggeringTrigger() ) )
endfunction
function NewSpell takes integer spell_id, code act returns trigger
local integer i = 0
set t = CreateTrigger()
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent( t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, Dummy_Filter )
set i = i + 1
exitwhen i > 15
endloop
call SaveInteger( Hash, 0, GetHandleId( t ), spell_id )
call TriggerAddCondition( t, Condition( function Cond ) )
call TriggerAddAction( t, act )
return t
endfunction
//===========================================================================
private function Init takes nothing returns nothing
set Dummy_Filter = Condition( function ReturnTrue )
set Hash = InitHashtable()
endfunction
endlibrary