• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

NewSpell

Level 10
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
 
Level 8
Joined
Aug 6, 2008
Messages
451
This is just a some BJ thingy that does nothing new. Just saves some lines of typing and thats all.

Then again: SpellEvent fixxes blizzards fucked up event responses, so its actually pretty damn cool.

edit. SpellEvent is that thingy Deaod linked up there, in case you decided not to care about that link.
 
Level 8
Joined
Aug 6, 2008
Messages
451
That Redscores thing is GUI, right?

Also whatever spell templates vexorian is making, those should use and require SpellEvent for obvious reasons.

( Or possibly some other system that does what SpellEvent does, but better. ( There just aint systems like that as far as I know ) )
 
Top