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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top