Snippet DbMod-alpha

weaaddar

New Member
Reaction score
6
Edit updated:: Now its configurable. You can now modify the levels of each sub property, the abilityId and the button positions. I don't know if Lua has a string format like C does, if it does I'll make the tooltip configurable.

Here is a resource that is used to manipulate drunken brawler and set different levels of evasion, critical hit rate and the crit hit damage multiplier.

The whole thing generates an ability and is fairly easy to configure with some minor textmacro abuse.

I realize that there is some belief that using text macros should be discouraged, but since there isn't an easy way to generate 100 level abilities in the worldeditor, this macro abuse is probably the best way.

I don't know lua, so I have no idea how to do proper string formatting (for now just straight concat). if someone can share how, I'll allow configuration of the tooltip for the ability.


(Note the current example code creates a 100 level ability, with
evasion (5 levels): 0,0.07,0.14,0.21,0.28
DamageMultiplier(4 levels): 1.5,2.0,2.5,3.0
Critical Hit rate(5 levels): 0,10,15,20,25)

It is in Vjass now.
Zinc and external blocks don't mix for some reason.
JASS:
library DBMod
    struct DBMod
    //! externalblock extension=lua ObjectMerger $FILENAME$
    /*****************************************************************
     *                       DBMod  -- Alpha                               
     *****************************************************************
        DBMod is a framework to manipulate the ability Drunken Brawler
        and allow it to be modified in runtime. It turns the ability
        into 3 extra properties for a unit,allowing the modification 
        of the evasion, damage multiplier and critical hit rate at run
        time. 
        Static properties and methods::
        -------------------------------
        thistype operator[unit u]
            Get the DBMod for this unit. A Dbmod holds the data stored
            for this unit, and allows application of different levels of
            evasion, dmg multiple, crit hit rate. 
            Note: On first retrieval the DBMod ability is added at level 1.
            
        setBonuses(unit u,integer evs,integer dmg,integer crt)
            Sets the evasion at evs,damage multiplier at dmg,crit hit rate at crt
            for unit u.
        
        Instance properties::
        ---------------------
        integer EvsRateLevel
            gets or sets the evasion rate level for this unit.*
        
        integer DmgMultLevel
            gets or sets the damage multiplier level for this unit.*
        
        integer CrtRateLevel
            gets or sets the critical hit rate for this unit.*
        
        * While you can set these values to anything you like, the abilities
        only function between 0 and MaxLevel for the ability.
    Configuration macros
        StartDBModConfig takes AbilityId,posX,posY
            configures the ability. Choose the abilityId, and its position on the Command
        ConfigEvsRate takes Rates,lvl
        ConfigDmgMult takes Rates,lvl
        ConfigCrtRate takes Rates,lvl
            configures the levels. Rates is a comma delimited list of values. Lvl
            is the number of levels
    EndDBModConfig()
            finishes the configuration. Must be called.
        *****************************************************************/
        //! runtextmacro StartDBModConfig("WAFP","0","0")
            //! runtextmacro ConfigEvsRate("0,0.07,0.14,0.21,0.28","5")
            //! runtextmacro ConfigDmgMult("1.5,2.0,2.5,3.0","4")
            //! runtextmacro ConfigCrtRate("0,10,15,20,25","5")
        //! runtextmacro EndDBModConfig()
        static constant integer EVS = 0
        static constant integer DMG = 1
        static constant integer CRT = 2
        private static integer array MaxLevels
        private unit m_unit
        private integer m_evs
        private integer m_dmg
        private integer m_crt
        private static hashtable Table = InitHashtable()
        static method GetMaxLevel takes integer dbType returns integer
            return MaxLevels[dbType]
        endmethod
        private static method GetSafeVal takes integer dbtype,integer val returns integer
            if(val <= 0)then
                return 0
            elseif(val >= GetMaxLevel(dbtype)-1)then
                return GetMaxLevel(dbtype)-1
            endif
            return val
        endmethod
        private method setBonus takes nothing returns nothing
            local integer level = 1 + GetSafeVal(CRT,m_crt)+ GetMaxLevel(CRT)*GetSafeVal(DMG,m_dmg)+(GetMaxLevel(CRT)*GetMaxLevel(DMG))*GetSafeVal(EVS,m_evs)
            debug call BJDebugMsg(I2S(level))
            call UnitRemoveAbility(m_unit,DBMOD_ABIL )
            call UnitAddAbility(m_unit,DBMOD_ABIL)
            call SetUnitAbilityLevel(m_unit,DBMOD_ABIL,level)
        endmethod
        
        static method create takes unit u returns thistype
            local thistype ret = thistype.allocate()
            set ret.m_unit = u
            call SaveInteger(Table,GetHandleId(ret.m_unit),0,ret)
            set ret.m_evs = 0
            set ret.m_dmg = 0
            set ret.m_crt = 0
            call ret.setBonus()
            return ret
        endmethod
        
                
        static method operator[] takes unit u returns thistype
            local thistype data = LoadInteger(Table,GetHandleId(u),0)
            if(data > 0)then
                return data
            endif
            return thistype.create(u)
        endmethod
        
        static method setBonuses takes unit u,integer evs,integer dmg,integer crt returns nothing
            local thistype data = DBMod<u>
            set data.m_evs = evs
            set data.m_dmg = dmg
            set data.m_crt = crt
            call data.setBonus()
        endmethod
        
        method operator EvsRateLevel takes nothing returns integer
            return m_evs
        endmethod
        
        method operator DmgMultLevel takes nothing returns integer
            return m_dmg
        endmethod
        
        method operator CrtRateLevel takes nothing returns integer
            return m_crt
        endmethod
        
        method operator EvsRateLevel= takes integer value returns nothing
            set m_evs = value
            call setBonus()
        endmethod 
        
        method operator DmgMultLevel= takes integer value returns nothing
            set m_dmg = value
            call setBonus()
        endmethod
        
        method operator CrtRateLevel= takes integer value returns nothing
            set m_crt = value
            call setBonus()
        endmethod
    endstruct
endlibrary
//! endexternalblock

//! textmacro StartDBModConfig takes abilityId,posX,posY
    //! i local level = 0
    //! i local ability = &quot;$abilityId$&quot;
    //! i setobjecttype(&quot;abilities&quot;)
    //! i createobject(&quot;ANdb&quot;,ability)
    //! i makechange(current,&quot;abpx&quot;,$posX$)
    //! i makechange(current,&quot;abpy&quot;,$posY$)
            static constant integer DBMOD_ABIL = &#039;$abilityId$&#039;
        static method onInit takes nothing returns nothing
//! endtextmacro
//! textmacro ConfigEvsRate takes rates,lvl
            set MaxLevels[EVS] = $lvl$
            
    // Ocr4
    //! i local evsrate = {$rates$} 
    //! i local maxevslvl = #evsrate
//! endtextmacro

//! textmacro ConfigDmgMult takes rates,lvl
            set MaxLevels[DMG] = $lvl$
    // Ocr2
    //! i local dmgmult = {$rates$}
    //! i local maxdmglvl = #dmgmult
//! endtextmacro
//! textmacro ConfigCrtRate takes rates,lvl
            set MaxLevels[CRT] = $lvl$
    // Ocr1
    //! i local crtrate = {$rates$}
    //! i local maxcrtlvl = #crtrate
//! endtextmacro

//! textmacro EndDBModConfig
            endmethod
    //! i makechange(current,&quot;alev&quot;,maxevslvl*maxdmglvl*maxcrtlvl)
    //! i for i = 1,maxevslvl do
        //! i for j = 1,maxdmglvl do
            //! i for k = 1,maxcrtlvl do
                //! i level = 1+(i-1)*(maxcrtlvl*maxdmglvl)+(j-1)*maxcrtlvl+(k-1)
                //! i makechange(current,&quot;Ocr4&quot;,level,evsrate<i>)
                //! i makechange(current,&quot;Ocr2&quot;,level,dmgmult[j])
                //! i makechange(current,&quot;Ocr1&quot;,level,crtrate[k])
                //! i makechange(current,&quot;atp1&quot;,level,&quot;---Combat Profeciencies---&quot;)
                //! i makechange(current,&quot;aub1&quot;,level,&quot;Evasion Rate: |cffffcc00&lt;&quot;.. ability..&quot;,DataD&quot;.. level ..&quot;,%&gt;% |n|rCritical Hit Multiplier: |cffffcc00&lt;&quot;..ability..&quot;,DataB&quot;.. level ..&quot;,%&gt;%|r|nCritical Hit Rate: |cffffcc00&lt;&quot;..ability..&quot;,DataA&quot;.. level ..&quot;&gt;% |r&quot;)
            //! i end            
        //! i end
    //! i end
//! endtextmacro
</i></u>



Finally, here is a simple test library to show how one might use the library.
JASS:
//! zinc
library test requires DBMod
{
    unit u;
    function onInit()
    {
        integer i;
        u = CreateUnit(Player(0),&#039;Hpal&#039;,0,0,0);
        i = DBMod<u>;
    }
    public function Trig_textMessage_Actions()
    {
         DBMod<u>.EvsRateLevel = S2I(SubString(GetEventPlayerChatString(),0,1));
        DBMod<u>.DmgMultLevel = S2I(SubString(GetEventPlayerChatString(),1,2));
        DBMod<u>.CrtRateLevel = S2I(SubString(GetEventPlayerChatString(),2,3));
    }
}
//! endzinc
//===========================================================================
function InitTrig_textMessage takes nothing returns nothing
    set gg_trg_textMessage = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_textMessage, Player(0), &quot;&quot;, false )
    call TriggerAddAction( gg_trg_textMessage, function Trig_textMessage_Actions )
endfunction
</u></u></u></u>

 

the Immortal

I know, I know...
Reaction score
51
Ynow, reminds me of the time when I was writing WoW addons. Never knew ObjMerger supports LUA, and even when J4L abused it that good in his Inv system didn't look much into it.

And although I find it really.. well, sloppy (read below) it perfectly 'explains' how to use LUA in conj with ObjMerger. And that's win. =P

About the snippet - if one would really use it, (with much more levels as well, I suppose) it'd be just better to use 3 different abilities each giving the different bonuses instead of this.
3 abilities x N levels vs. 1 ability with N^3 levels
No need to say the 2nd would be much more optimized. Even thou it'd probably require 2 more spellbooks.
 

weaaddar

New Member
Reaction score
6
Well, I've updated and made it configurable now. I still don't know lua at all. And I had to switch to Vjass as Zinc and external block don't work together. That idea won't really work that great as then you can't see how much you have (without some other mechanism), and then its per player rather then per unit.

Plus Damage multiplier and crit hit rate are intrinsically tied.

Beside, with OM its stupid easy to generate the ability (which is the best part really), and it doesn't seem to add much to load time.

Its annoying but there doesn't seem to be a mechanism to send data from Lua to Jass. The only thing you can do is have a text macro generate some stuff that can be done at compile time for lua, and at runtime in an OnInit trigger for jass. Which is a shame, as it could've been neat to use lua to do compile time evaluations and code generation.
 

Jesus4Lyf

Good Idea™
Reaction score
397
I don't know lua, so I have no idea how to do proper string formatting (for now just straight concat). if someone can share how, I'll allow configuration of the tooltip for the ability.
No offense, but that's weak.
I didn't know a scrap of LUA before I wrote ItemStruct.
And you can rip string concatenation out of it. It's:
JASS:
//! i myString=&quot;dog&quot;
//! i myString=myString..myString

".." seems to be concatenate.

Edit:
This leaks - it uses hashtables and never flushes the value when the unit leaves the game. I suggest you use AIDS - which is more efficient and user friendly for cleanup functionality.
 

weaaddar

New Member
Reaction score
6
Yeah, I got the concat operator from googling. But I need something like a string format so that you can send it in a text macro what you want as, text macros don't allow escaping characters.
i.e.
[ljass]//! runtextmacro SetToolTip("Here is a tooltip mentioning something"..dataA$.."more text") [/ljass] won't work

As for the autoindexing complaint, while technically valid is a very minor issue. If you really are hellbent on applying dbmod to 8000+ units, then adding an aids/autoindex/pui is certainly a possibility. I'll probably make an optional autoindex version, as the hashtable version is easiest and the leak is one ht index, and array locations. Its not leaking like a sieve.
 

weaaddar

New Member
Reaction score
6
Less icon space on the command card? Hey it was a great Idea in 2005 when I first made this resource :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top