1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

NewSpell

Discussion in 'Graveyard' started by Cheezeman, Nov 7, 2009.

  1. Cheezeman

    Cheezeman

    Joined:
    Aug 19, 2008
    Messages:
    437
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Header should say it all.
    Code

    Code (vJASS):

    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
     

    Code (safe)

    Code (vJASS):

    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
     

     
  2. azlier

    azlier

    Joined:
    Oct 3, 2008
    Messages:
    354
    Resources:
    4
    JASS:
    4
    Resources:
    4
    This is just slow wrapper for spell event registry? :slp:

    Yeah, I'll just use GTrigger, which is unfortunately not submitted here.
     
  3. Cheezeman

    Cheezeman

    Joined:
    Aug 19, 2008
    Messages:
    437
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    How is it slow?
    And sure, do that. I know I'm not the best coder in the world.
     
  4. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    805
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
  5. Viikuna

    Viikuna

    Joined:
    Aug 6, 2008
    Messages:
    430
    Resources:
    0
    Resources:
    0
    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.
     
  6. Cheezeman

    Cheezeman

    Joined:
    Aug 19, 2008
    Messages:
    437
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Duh, it's just a module, nothing special. I thought it was easier than making all those functions and events, but I suppose it isn't worth of a jass script.
     
  7. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,167
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
  8. Viikuna

    Viikuna

    Joined:
    Aug 6, 2008
    Messages:
    430
    Resources:
    0
    Resources:
    0
    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 ) )
     
  9. Cheezeman

    Cheezeman

    Joined:
    Aug 19, 2008
    Messages:
    437
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    It seems I didn't do my research before posting this. Google is my friend, but I did not ask him.