Custom Spell System

Naga'sShadow

Ultra Cool Member
Reaction score
49
I searched for a bit but didn't see one. So I made one. My question is there a more efficient way to set it up. Currently there's an if/then for every spell that can be learned, and then a short block for actually adding the spells.

This is what I'm working with now.

I'm nesting the if/then in else ifs but is that any more efficient than placing and endif followed by another if statement?

JASS:
scope SpellSelection initializer init

    globals
        private constant integer DUMMY = 'a000' //Used as a benchmark
        //Abilites in alphabetical order
        private constant integer AVATAR = 'AHav'
        private constant integer BANISH = 'AHbn'
        private constant integer BLIZZARD = 'AHbz'
        private constant integer HOLY_LIGHT = 'AHhb'
    
        
        
        //Items in numerical order
        private constant integer HOLY_STONE = 'I000'
        private constant integer BLIZ_STONE = 'I001'
        private constant integer AVA_STONE = 'I002'
        private constant integer BANISH_STONE = 'I003'
    
    
    
    endglobals
        
    private function Actions takes nothing returns nothing
        local unit learner = GetTriggerUnit()
        local player owner = GetOwningPlayer(learner)
        local integer spell = DUMMY
        local boolean ult = false
        
        //in the order I get to them
        if GetItemTypeId(GetManipulatedItem()) == BLIZ_STONE then
            set spell = BLIZZARD
        elseif GetItemTypeId(GetManipulatedItem()) == HOLY_STONE then
            set spell = HOLY_LIGHT
        elseif GetItemTypeId(GetManipulatedItem()) == AVA_STONE then
            set spell = AVATAR
            set ult = true
        elseif GetItemTypeId(GetManipulatedItem()) == BANISH_STONE then
            set spell = BANISH
        endif  //for now ;(
        
        if spell != DUMMY and ult == false then
            if GetUnitAbilityLevel(learner, spell) == 0 then
                call UnitAddAbility(learner, spell)
                call UnitMakeAbilityPermanent(learner, true, spell)
                call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " learned!")
            elseif GetUnitAbilityLevel(learner, spell) < 20 then
                call IncUnitAbilityLevel(learner, spell)
                call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " is now level " + I2S(GetUnitAbilityLevel(learner, spell)) + ".")
            elseif GetUnitAbilityLevel(learner, spell) == 20 then
                call SimError(owner, "Max Level Reached.  Refunding Skill Points.")
                call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER) + 1)
            endif
        elseif spell !=DUMMY and ult == true then
            if GetUnitAbilityLevel(learner, spell) == 0 then
                call UnitAddAbility(learner, spell)
                call UnitMakeAbilityPermanent(learner, true, spell)
                call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " learned!")
            elseif GetUnitAbilityLevel(learner, spell) < 3 then
                call IncUnitAbilityLevel(learner, spell)
                call DisplayTextToPlayer(owner, 0, 0, GetObjectName(spell) + " is now level " + I2S(GetUnitAbilityLevel(learner, spell)) + ".")
            elseif GetUnitAbilityLevel(learner, spell) == 3 then
                call SimError(owner, "Max Level Reached.  Refunding Skill Points.")
                call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER) + 3)
            endif
        endif
        
        set learner = null
        set owner = null
    endfunction

    private function Conditions takes nothing returns boolean
        if GetItemType(GetManipulatedItem()) == ITEM_TYPE_POWERUP then
            call Actions()
        endif
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
        call TriggerAddCondition(t, Condition( function Conditions))
    endfunction
endscope


Edit: Is there a way to prevent the lag when a spell is added to a unit for the first time?
 

SanKakU

Member
Reaction score
21
what you mentioned in your edit of your first post...i'm pretty sure what you're asking about is preloading your spell. you need to do that, and that will take care of precisely what you're talking about there.

i guess there are a few different ways ppl do it...and i'm not really sure what's the best way or ways...but i guess all you have to do is make a trigger where you at map initialization create a dummy unit at wherever and give him whatever abilities for your triggered spells that wold lag otherwise be preloaded into the game. otherwise, the spell actually doesn't get bothered to be loaded by the game until it's relevant see...so you're learning an ability and then the trigger is like, heeeyyyy...i need to load up now...but if you loaded the trigger at the beginning of the map then you don't have to worry about that. so all you had to do for preloading it is make a unit at the beginning and give him that ability. of course you need to kill him after that. i guess you need to make it a neutral passive unit. anyway that's just a basic rought outline of what you have to do. there's also preloading effects, and there are other ways you can preload....which may be considered...for example if you have 90 or so heroes all with abilities that need preloading you might consider preventing the map intiailization from needing to load all that data and instead opt to load it only when it's hero picking time...an example of this is something that dota does...since it has that huge number of units it's obvious that it doesn't do that. and apparently the invoker has so much preloading necessitated that there is a special message for him that he's going to lag when someone picks him...so i mean, yeah. do what you gotta do, but isn't it pretty sweet that they at least loaded his abilities when he was picked rather than waiting for him to try learning his abilities...that could really suck to have all that lag in the game... so use your judgement, the map initialization may not be the best place for all your preloading...
 

Jesus4Lyf

Good Idea™
Reaction score
397
textwall.jpg

Edit: Is there a way to prevent the lag when a spell is added to a unit for the first time?
Just add it to a unit on map init, and then remove it again (some dummy unit).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top