• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] LUA_NEW_BUFF

Level 11
Joined
Sep 30, 2009
Messages
697
Simple LUA to create a dummy buff based on Tornado Slow Aura. Useful if your spell requires a custom buff etc. Perfect for buff systems which need loads of data.

JASS:
//! textmacro NewBuff takes ABILITY_ID, BUFF_ID, NAME, DESCRIPTION, ICON
    //! externalblock extension=lua ObjectMerger $FILENAME$
    //! i setobjecttype("abilities")
    //! i createobject("Aasl", "$ABILITY_ID$")
    //! i makechange(current, "anam", "$NAME$")
    //! i makechange(current, "aart", "$ICON$")
    //! i makechange(current, "ansf", " ")
    //! i makechange(current, "arac", "other")
    //! i makechange(current, "abuf", 1, "$BUFF_ID$")
    //! i makechange(current, "aare", 1, "0")
    //! i makechange(current, "atar", 1, "self")
    //! i makechange(current, "Slo1", 1, "0")
    
    //! i setobjecttype("buffs")
    //! i createobject("Basl", "$BUFF_ID$")
    //! i makechange(current, "ftip", "$NAME$")
    //! i makechange(current, "fart", "$ICON$")
    //! i makechange(current, "fnsf", " ")
    //! i makechange(current, "fube", "$DESCRIPTION$")
    //! i makechange(current, "ftat", " ")
    //! endexternalblock
//! endtextmacro

Usage example:
JASS:
//! runtextmacro NewBuff("A000", "B000", "Awesome", "This unit is awesome.", "ReplaceableTextures\CommandButtons\BTNTemp.blp")
 
Level 8
Joined
Oct 3, 2008
Messages
367
Ah, this is something I like to see. The only issue (and it's a rather large issue) is the actual adding of buffs. You need to add the generated ability to a spellbook, disable said spellbook, and add the spellbook to a unit for the buff to take effect. If I'm remembering correctly.

I think ABuff by Anitarf over at WC3C accomplishes all this, but I have never actually looked over the features or code deeply or checked if it uses outdated methods. But what I do know about ABuff is that it contains a menagerie of what might be seen as unnecessary features, and it is intolerant of any indexing system besides the outdated Autoindex. I think the only reason it needs an indexer is because of the aforementioned features.

In conclusion, I'd like to see where this goes.
 
Level 8
Joined
Oct 3, 2008
Messages
367
Really? I didn't know that. The spellbook approach must be for applying buffs through auras then. In that case, the only potential problems here are how this acts when a unit is morphed via Chaos.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
making an ability permanent makes it work through morphs like chaos ;\

Well, actually, I'm not sure about hex or w/e it is from Troll Witch Doctor (turn into a creep).

It's making me wonder if there may be a possible bug in my indexing system ;o.

Also, tornado slow aura comes from a tornado unit : \. If the aura effects a specific unit, then it would be added to the unit with targets marked as self, meaning the ability would be shown.

A spellbook is a good approach in most situations. I suggest you create 2 *Lua functions*, one for spellbook approach and one for reg. I don't like that your thing is a macro... >.>

I hate running macros and I only personally use them for importing functions : P. You should do the same : ).

Use some Lua knowledge to make the function OO.
 
Last edited:
Original

I made an updated version for Nestharus' scripts. This one also allows you to specify a buff alignment, because the tornado aura defaults negative:

Requires:
LUA_FILE_HEADER

JASS:
/* Requires:
    LUA_FILE_HEADER     [url]http://www.hiveworkshop.com/forums/jass-functions-413/snippet-lua_file_header-186775/[/url]
*/
// Copy and paste this script into a map to install it. You only need to do this once.
//      Arguments:
//
//          name - The name of the buff.
//
//          alignment - POSITIVE , NEUTRAL , or NEGATIVE. If it is not any of those, it will default negative.
//           The buff alignment will determine the color of the name.
//
//          description - The tooltip of the buff shown when you hover over it in the buff tray.
//
//          icon - The icon of the buff shown in the buff tray.
//

//! externalblock extension=lua FileExporter $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i writelua("NewBuff", [[
    
        //! i dofile("GetVarObject")
    
        //! i function newbuff(name, alignment, description, icon)
            //! i local buffID = getvarobject("Basl", "buffs", "BUFFS_" .. name, true)
            //! i createobject("Basl",buffID)
            
            //! i if (alignment=="POSITIVE") then
                //! i makechange(current, "ftip", "|cff00FF00" .. name .. "|r")
            //! i elseif (alignment=="NEUTRAL") then
                //! i makechange(current, "ftip", "|cff00FFFF" .. name .. "|r")
            //! i else
                //! i makechange(current, "ftip", name)
            //! i end
            
            //! i makechange(current, "fart", icon)
            //! i makechange(current, "fnsf", " ")
            //! i makechange(current, "fube", description)
            //! i makechange(current, "ftat", " ")
        
            //! i local abilID = getvarobject("Aasl", "abilities", "ABILITIES_" .. name .. "_DUMMY", true)
            //! i createobject("Aasl",abilID)
            //! i makechange(current, "anam", name .. "_DUMMY")
            //! i makechange(current, "aart", icon)
            //! i makechange(current, "ansf", " ")
            //! i makechange(current, "arac", "other")
            //! i makechange(current, "abuf", 1, buffID)
            //! i makechange(current, "aare", 1, "0")
            //! i makechange(current, "atar", 1, "self")
            //! i makechange(current, "Slo1", 1, "0")
            
            //! i updateobjects()
        //! i end
        
    //! i ]])
//! endexternalblock

Example of usage:
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i dofile("NewBuff")
    
    //! i newbuff("TestingBuff", "NEUTRAL", "A buff used for testing.", "ReplaceableTextures\\CommandButtons\\BTNAvatar.blp")
//! endexternalblock

// The above script creates a buff named "TestingBuff". 
// It has a NEUTRAL buff alignment.
// Its description is "A buff used for testing."
// It has the "Avatar" icon.

scope TestSpell initializer Init
    function UnitAddBuff takes unit u, integer dummyAbilID returns nothing 
        //will add a buff to a unit until it is removed
        call UnitAddAbility(u,dummyAbilID)
        call UnitMakeAbilityPermanent(u,true,dummyAbilID)
    endfunction
    function UnitRemoveBuff takes unit u, integer dummyAbilID, integer buffID returns nothing 
        //will remove a buff from a unit
        call UnitMakeAbilityPermanent(u,false,dummyAbilID)
        call UnitRemoveAbility(u,dummyAbilID)
        call UnitRemoveAbility(u,buffID)
    endfunction
    
    private function onCast takes nothing returns nothing
        call UnitAddBuff(GetTriggerUnit(),ABILITIES_TestingBuff_DUMMY)
        call TriggerSleepAction(5)
        call UnitRemoveBuff(GetTriggerUnit(),ABILITIES_TestingBuff_DUMMY,BUFFS_TestingBuff)
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddAction(t,function onCast)
    endfunction
endscope
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
I initially made it to use getvarobject(), but then I decided to retain the functionality to set your own rawcodes because some people (like me) like to change little things, and it would be a hassle to delete the buffs in the object editor just to run the script again.

You don't have to delete the buffs in the object editor to run the script again... createobject overwrites them, lol...

Run it on LUA_GET_VAR_OBJECT =)


LUA_GET_VAR_OBJECT has been so useful for me when trying to find a good ability for AdvDamageEvent in LUA_DUMMY_PHYSICAL_ABILITY or w/e. All I had to do was change the ability id and maybe add/subtract 1 field, the rest was all good to go (the generated buffs, the variables, etc) =).
 
Well, this is the var object version:
JASS:
/* Requires:
    LUA_FILE_HEADER     [url]http://www.hiveworkshop.com/forums/jass-functions-413/snippet-lua_file_header-186775/[/url]
*/
// Copy and paste this script into a map to install it. You only need to do this once.
//      Arguments:
//
//          name - The name of the buff.
//
//          alignment - POSITIVE , NEUTRAL , or NEGATIVE. If it is not any of those, it will default negative.
//           The buff alignment will determine the color of the name.
//
//          description - The tooltip of the buff shown when you hover over it in the buff tray.
//
//          icon - The icon of the buff shown in the buff tray.
//

//! externalblock extension=lua FileExporter $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i writelua("NewBuff", [[
    
        //! i dofile("GetVarObject")
    
        //! i function newbuff(name, alignment, description, icon)
            //! i local buffID = getvarobject("Basl", "buffs", "BUFFS_" .. name, true)
            //! i createobject("Basl",buffID)
            
            //! i if (alignment=="POSITIVE") then
                //! i makechange(current, "ftip", "|cff00FF00" .. name .. "|r")
            //! i elseif (alignment=="NEUTRAL") then
                //! i makechange(current, "ftip", "|cff00FFFF" .. name .. "|r")
            //! i else
                //! i makechange(current, "ftip", name)
            //! i end
            
            //! i makechange(current, "fart", icon)
            //! i makechange(current, "fnsf", " ")
            //! i makechange(current, "fube", description)
            //! i makechange(current, "ftat", " ")
        
            //! i local abilID = getvarobject("Aasl", "abilities", "ABILITIES_" .. name .. "_DUMMY", true)
            //! i createobject("Aasl",abilID)
            //! i makechange(current, "anam", name .. "_DUMMY")
            //! i makechange(current, "aart", icon)
            //! i makechange(current, "ansf", " ")
            //! i makechange(current, "arac", "other")
            //! i makechange(current, "abuf", 1, buffID)
            //! i makechange(current, "aare", 1, "0")
            //! i makechange(current, "atar", 1, "self")
            //! i makechange(current, "Slo1", 1, "0")
            
            //! i updateobjects()
        //! i end
        
    //! i ]])
//! endexternalblock

But idk how to make it so it won't create a new one each time the same script is ran. Not sure what you meant in your post. Also, the globals don't work for me for some weird reason. In the first script, using getvarobject could be left up to the user.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
But idk how to make it so it won't create a new one each time the same script is ran.

It doesn't spam ids... it uses the var name as an identifier. If you create a var object called HELLO even once, it'll continue to return the id it got when you first made it. The ids are also map specific.

Also, the globals don't work for me for some weird reason. In the first script, using getvarobject could be left up to the user.

They work for me and they worked in your ReviveHero script ;P.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You might also take a look at the code here (just ignore the text if you are not familiar with german), which combines the object editor buff creation with storing data for jass.

The struct above is just a stub to recognize the shape. The raw only needs three digits (would take a real abbreviation and not 123) and the first textmacro parameter is to decide whether the slow externalblock, which creates the object editor stuff, should be executed.

You should support different levels of the ability/buff as this is visible ingame when hovering over the bufficon.

@Nestharus: I know you always want to have your LuaHeader in Externalblocks, which is surely useful, but you cannot wrap it in another textmacro then as you take runtextmacro away. So couldn't you write an own external tool which features your Header/other functions? Maybe a central tool that is also able to run the other tools.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
@Nestharus: I know you always want to have your LuaHeader in Externalblocks, which is surely useful, but you cannot wrap it in another textmacro then as you take runtextmacro away. So couldn't you write an own external tool which features your Header/other functions? Maybe a central tool that is also able to run the other tools.

Why on earth would you want to wrap it in a textmacro. When you're using Lua, you can write functions... lol, textmacros were only used in Lua because people weren't using functions ;p.
 
Top