Spell Non-stackable Basher

the Immortal

I know, I know...
Reaction score
51
Mm, saw it requested a few times (more specifically Crusher's tread out there that got unanswered for weeks) and decided to create 2 versions of the DotA-like basher:

1) Non-stackable basher.
Really simple, just multiple bashers don't stack. Uses hashtables (requiring unit indexing for such a snippet-like spell is.. pointless imo), vJASS, is MUI and should be leakless. Needs 2 abilities (actual bash spell and a spell book to hide it inside.. easily creatable via ObjectMerger). Once again, it's damn simple and straightforward.

JASS:
/*
                                  Non-stackable Basher w/o cooldown
    
    To import:
    
     - Create a new trigger, name it something like 'Basher' and copy all that shiet to it.
     - Uncomment the next two lines, save the map, close it, open it, and COMMENT them again.   */

//     //! external ObjectMerger w3a AHbh aFdS alev 1 ahdu 1 1.40 adur 1 1.40 Hbh1 1 25 anam "Basher Stun"
//     //! external ObjectMerger w3a Aspb aFdT spb1 1 aFdS anam "Basher Spellbook"

/*   - Now go to Object Editor -> Items -> Custom -> Basher Stun
       and set the Chance / Duration / Bonus Dmg as you want them to be
     - If your desired item has bash on it, REMOVE it. 
     - Write the item Id of your basher and modify the filter function as you wish.. right down there they are.
     - Mmm, that should be everything ^_-
     
                                                            made by Ixtreon (a.k.a. the Immortal)
*/

scope Basher initializer init
    globals
        private constant integer BASHER_ID = 'I000'             //the item with bash. (it must NOT have bash ability at all)
        
        
        private constant integer BASHER_SPELLBOOK_ABIL = 'aFdT' //SpellBook ability rawcode. Do NOT change unless you know what ya'r doing
    endglobals
    
    private function ToBashOrNot takes unit Bashing returns boolean
        //return true                                           //will bash.. everytime
        return GetUnitAbilityLevel(Bashing, 'AHbh') == 0        //won't bash if unit has ability bash
    endfunction
    
//==============================================================

    globals
        private constant hashtable ht = InitHashtable()
    endglobals

    private function onPickup takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = LoadInteger(ht, 0, GetHandleId(u))
        if i == 0 then
            call UnitAddAbility(u, BASHER_SPELLBOOK_ABIL)
        endif
        call SaveInteger(ht, 0, GetHandleId(u), i + 1)
        set u = null
    endfunction
    
    private function onPickupCond takes nothing returns boolean
        if GetItemTypeId(GetManipulatedItem()) == BASHER_ID then
            call onPickup()
        endif
        return false
    endfunction

    private function onDrop takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = LoadInteger(ht, 0, GetHandleId(u))
        if i == 1 then
            call UnitRemoveAbility(u, BASHER_SPELLBOOK_ABIL)
        endif
        call SaveInteger(ht, 0, GetHandleId(u), i-1)
        set u = null
    endfunction
    
    private function onDropCond takes nothing returns boolean
        if GetItemTypeId(GetManipulatedItem()) == BASHER_ID then
            call onDrop()
        endif
        return false
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local trigger t2 = CreateTrigger()
        local integer i = 0
        loop
            call SetPlayerAbilityAvailable(Player(i), BASHER_SPELLBOOK_ABIL, false)
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DROP_ITEM, null)
            call TriggerRegisterPlayerUnitEvent(t2, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function onDropCond))
        call TriggerAddCondition(t2, Condition(function onPickupCond))
        set t = null
        set t2 = null
    endfunction

endscope

2) Non-stackable Basher with cooldown

Kinda harder to implement since bash behaves strangely (seems decision whether to bash or not is made at UNIT_ATTACKED event, meaning I can't just remove it then since it'll chainbash).
But in short, adds the 100% bash abil on the unit if it's not on cooldown, removes it when the unit takes damage by attacker and is stunned, and also creates a timer to count cooldown.
Again uses hashtables, vJASS, is MUI and should be leakless. Requires 2 abilities (100% bash spell and a spell book to hide it inside, again easily creatable via ObjectMerger). Still uses a simple and straightforward method, and is kinda sloppy thou it works as intended. (If you suspect it does not, write me, I have 2 more ideas how to implement it.. thou for me it works perfectly)
JASS:
/*
                                  Non-stackable Basher with cooldown

    To import:
    
     - Create a new trigger, name it something like 'Basher' and copy all that shiet to it.
     - Uncomment the next two lines, save the map, close it, open it, and COMMENT them again.   */

//     //! external ObjectMerger w3a AHbh aFdU alev 1 ahdu 1 1.40 adur 1 1.40 Hbh1 1 100 anam "Basher Stun (100%)"
//     //! external ObjectMerger w3a Aspb aFdV spb1 1 aFdU anam "Basher Spellbook (100%)"

/*   - Now go to Object Editor -> Items -> Custom -> Basher Stun
       and set the Duration / Bonus damage as you want them to be. Do NOT touch the % chance!
     - If your desired item has bash on it, REMOVE it. 
     - Write the item Id of your basher and modify the filter function as you wish.. right down there they are.
     - Mmm, that should be everything ^_-
     
                                                            made by Ixtreon (a.k.a. the Immortal)
*/

scope CDBasher initializer init
    globals
        private constant integer BASHER_ID = 'I001'             //the item with bash. (it must NOT have bash ability at all)
        private constant integer BASHER_SPELLBOOK_ABIL = 'aFdV' //The spellbook's Id. Do NOT change this line unless you know what ya'r doing
        private constant integer CHANCE_TO_PROC = 25            //% chance to bash
        private constant real    COOLDOWN = 2.0                 //basher's cooldown
        private constant integer STUNNED_BUFF = 'BPSE'          //the buff when a unit is stunnd (usually no reason to change it)
    endglobals
    
    private function ToBashOrNot takes unit Bashing returns boolean
        //return true                                           //will bash.. everytime
        return GetUnitAbilityLevel(Bashing, 'AHbh') == 0        //won't bash if unit has ability bash
    endfunction
    
//==============================================================

    globals
        private constant hashtable ht = InitHashtable()
    endglobals
    
    private function RemoveCd takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer ui = LoadInteger(ht, 0, GetHandleId(t))
        call RemoveSavedBoolean(ht, 1, ui)  //no cd
        call RemoveSavedInteger(ht, 0, GetHandleId(t))  //flush timer data
        call DestroyTimer(t)
        set t = null
    endfunction
    
    private function onDamage takes nothing returns boolean
        local trigger t = GetTriggeringTrigger()
        if LoadUnitHandle(ht, 0, GetHandleId(t)) == GetEventDamageSource() then
            if GetUnitAbilityLevel(GetTriggerUnit(), STUNNED_BUFF) > 0 then
                call UnitRemoveAbility(GetEventDamageSource(), BASHER_SPELLBOOK_ABIL)
                call RemoveSavedHandle(ht, 0, GetHandleId(t))
                call DestroyTrigger(t)
            endif
        endif
        set t = null
        return false
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit a = GetAttacker()
        local timer t
        local trigger trg
        local boolean OnCd = LoadBoolean(ht, 1, GetHandleId(a))
        if not OnCd then
            call UnitAddAbility(a, BASHER_SPELLBOOK_ABIL)
            set trg = CreateTrigger()
            call TriggerRegisterUnitEvent(trg, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
            call TriggerAddCondition(trg, function onDamage)
            call SaveUnitHandle(ht, 0, GetHandleId(trg), a)
            call SaveBoolean(ht, 1, GetHandleId(a), true)   //is OnCD
            set t = CreateTimer()
            call TimerStart(t, COOLDOWN, false, function RemoveCd)
            call SaveInteger(ht, 0, GetHandleId(t), GetHandleId(a))
            set t = null
            set trg = null
        endif
        set a = null
    endfunction

    private function Cond takes nothing returns boolean
        local integer i = 0
        if GetRandomInt(0, 99) < CHANCE_TO_PROC and ToBashOrNot(GetAttacker()) then
            loop
                if GetItemTypeId(UnitItemInSlot(GetAttacker(), i)) == BASHER_ID then
                    call Actions()
                    return false
                endif
                exitwhen i == 5
                set i = i + 1
            endloop
        endif
        return false
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            call SetPlayerAbilityAvailable(Player(i), BASHER_SPELLBOOK_ABIL, false)
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, null)
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Cond))
        set t = null
    endfunction
endscope

Blahblah, haven't put any resources here or coded seriously in vJASS for almost 2 years, so if something isn't how it should be, please say so. =P

PS. add an [Item] prefix, lols?
PPS. And forgot to add the test map.. how typical of me, eh -.-

EDIT: Removed that minor leak that skipp'd through and abilities are now added via ObjectMerger.
 

Attachments

  • BashTest.w3x
    21.9 KB · Views: 240

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
1)
JASS:
   private function onPickup takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = LoadInteger(ht, 0, GetHandleId(u))
        if i == 0 then
            call UnitAddAbility(u, BASHER_SPELLBOOK_ABIL)
        endif
        call SaveInteger(ht, 0, GetHandleId(u), i + 1)
        // set u = null
    endfunction


null 'u'
also:

JASS:
if i == 0 then
    call UnitAddAbility(u, BASHER_SPELLBOOK_ABIL)
endif


could be, I believe

JASS:
if UnitAddAbility(u,BASHER_SPELLBOOK_ABIL) then
endif
/* Nothing else, it basicly adds the ability to units who doesn't have it.
It also allows you to remove the hashtable part which saves the ability level.
Probally also makes the the system simplier. */


2)
JASS:
local boolean OnCd = LoadBoolean(ht, 1, GetHandleId(a))

null it, I believe.
 

the Immortal

I know, I know...
Reaction score
51
1) Must've skipped it somehow, sad.

2) Can't do that. First of all
JASS:
if UnitAddAbility(u,BASHER_SPELLBOOK_ABIL) then
endif
does exactly the same as just [ljass]UnitAddAbility(u,BASHER_SPELLBOOK_ABIL)[/ljass] except that it'll do the 'if' block if unit didn't have the ability (the function returns whether adding the ability was successful or not).
And I can't remove the hashtable part since I need to know how many of the basher item the hero has when one is dropped. And that must be either done with a loop thru' all his slots or with hashtables. Haven't benchmarked it, but I believe the 2nd variant is faster.

3) Booleans are not handles, and as such I believe they can't be nulled.

One-liner update incoming tomorrow (cba reuploading it now, plus it's 3:33 AM, plus I'd first like to see if there are any other problems).
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129

Executor

I see you
Reaction score
57
Could you include the abilities by using the ObjectMerger? Would be much easier to import.
 

Crusher

You can change this now in User CP.
Reaction score
121
Thanks for your work. I already repped you so I cannot do it again.

:thup:
 

Romek

Super Moderator
Reaction score
964
@ GetTriggerUnit-
No, you don't seem to get it.
He's not saying that you can't do it, he's saying that it's completely and utterly useless to have an empty if block. You might as well just call the function directly.
Obviously [ljass]UnitAddAbility[/ljass] only adds the ability if the unit hasn't got it; a unit can't have the same ability twice after all. You don't need an if to do that.
 

the Immortal

I know, I know...
Reaction score
51
> Could you include the abilities by using the ObjectMerger? Would be much easier to import.
Think I did it. Though not really sure, lols ^^. First time I'm using it.. but seems to work anyway.

@GetTriggerUnit- The reason it is used in AutoFly is that the function returns whether the ability was successfully added. If it was, its return value is true and the ability is removed from the unit (that means the unit didn't have the ability before, and that's why it's removed). If the retval of the function is false, that means the unit had it before, and then the ability shouldn't be removed.

Yes, I can directly add the ability, but I suppose a simple check is faster if you already have the ability.. plus it looks neater. Anyway it's something that is neither senseless nor buggy/leaky or whatever. I prefer it that way.

Oh, and of course fixed that minor 'u = null;' mistake.
 

the Immortal

I know, I know...
Reaction score
51
*cough* any reason 'dis stays here? Should I change it to a spell? (i.e. not using an item) Or is overdone? Or is obsolete? Or...? Simply no1 has lewk'd it? ;x
 

Viikuna

No Marlo no game.
Reaction score
265
Making some generalized unit picks up item and gets some shit -thingy would make sense, but not this.

This is useful just as long as dota has something similiar and some noobs want to know how it is done. When dota changes that stuff, this is forgotten and noone cares about it anymore.


So, either turn this to a proper system with more functionality, or get rid of it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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 Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top