• 🏆 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_CREATE_OBJECT

Level 31
Joined
Jul 10, 2007
Messages
6,306
OUTDATED, DO NOT USE!

Use LUA_JASS_GLOBALS instead!

JASS:
//uncomment after running script once
//change FILE_NAME to your map name
//keep in mind that the object data file takes 2 saves to update
///! import "objectDataLua.FILE_NAME.j"
//! textmacro LUA_GET_OBJECT takes FILE_NAME
    //FILE_NAME refers to the name of your map
    
    //uses
    //LUA_GET_OBJECT_ID
    //hiveworkshop.com/forums/submissions-414/snippet-lua_object_id-176943/
    //LUA_STRING_EXPLODE
    //hiveworkshop.com/forums/submissions-414/snippet-lua_string_explode-176944/#post1686054
    
    //! i function getobject(objectname, obj, objecttype)
        //objectname refers to the name of the object var/tag
        //obj refers to the base object id, like "hpea"
        //objecttype refers to the type, like "units" or "buffs"
        
        //! i local PATH = "jass\\objectDataLua.$FILE_NAME$.j"
        //! i local TYPE = "constant integer "
        //! i local GLOBAL_START = "globals\n"
        //! i local GLOBAL_END = "endglobals"
        
        //! i local function read()
            //! i local f = io.open(PATH, "r")
            //! i if (f == nil) then
                //! i return nil
            //! i end
            //! i local text = f:read("*all")
            //! i f:close()
            
            //! i if (text ~= nil) then
                //! i return string.match(text, GLOBAL_START .. "(.*)" .. GLOBAL_END)
            //! i end
            
            //! i return nil
        //! i end
        
        //! i local function write(text)
            //! i local f = io.open(PATH, "w")
            //! i f:write(GLOBAL_START .. text .. GLOBAL_END)
            //! i f:close()
        //! i end
        
        //! i local function convert(object)
            //! i return TYPE .. objectname .. "='" .. object .. "'"
        //! i end
        
        //! i local function retrieveid(text)
            //! i setobjecttype(objecttype)
            
            //! i if (text ~= nil) then
                //! i local i,j,object = string.find(text, TYPE .. objectname .. "='(....)'")
                //! i if (object ~= nil) then
                    //! i if (objectexists(object)) then
                        //! i return object, text
                    //! i else
                        //! i local object2 = object
                        //! i object = getobjectid(obj, objecttype)
                        //! i return object, string.gsub(text, TYPE .. objectname .. "='(" .. object2 .. ")'", convert(object))
                    //! i end
                //! i else
                    //! i local object = getobjectid(obj, objecttype)
                    //! i return object, text .. convert(object) .. "\n"
                //! i end
            //! i else
                //! i local object = getobjectid(obj, objecttype)
                //! i return object, convert(object) .. "\n"
            //! i end
        //! i end
        
        //! i do
            //! i local object, text = retrieveid(read())
            //! i write(text)
            //! i return object
        //! i end
    //! i end
//! endtextmacro

Demo
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_GET_OBJECT_ID()
    //! runtextmacro LUA_GET_OBJECT("FILE_NAME")
    //! runtextmacro LUA_STRING_EXPLODE()
    
    //! i local object = getobject("Root", "Acrs", "abilities")
    //! i local object2 = getobject("Root2", "Acrs", "abilities")
//! endexternalblock
 
Last edited:
Level 8
Joined
Oct 3, 2008
Messages
367
Interesting. You can create objects with the unique object names, of course?

While I'm quite certain that you can, confirmation is always nice. Something very useful. And quite mad. But madness is a good thing.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
You can create objects with the unique object names, of course

Well, it just creates the variable and makes the var name whatever name you wanted. The unique id created is accessed via the name since there is no way you can know the unique id without looking into the generated jass scripted.

From here, you use the unique id to create your own object editor object via Lua (which stabilizes scripts like Buff Struct and Bonus Mod and gives more power over scripts that use the Object Editor). Obviously, you can name the Object Editor object w/e you like, but you access the id in JASS via the var that's generated by this script ; ).

You get all of that? Ask any other questions ; D.

Now, for convention, you should name your vars with OBJECTTYPE_NAME like UNITS_PEASANT or ABILITIES_ROOT. This is a convention I made myself since this is the first script to do something like this = ).

Anywho ; D.

Next thing I need to do is make chained abilities that store the object ids into an array ; O, dummy spell book stuff, and buff stuff ; ).
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I didn't spot that. You aren't going to make me go through the agonizing process of unapproving now, are you?

Well, the API won't change so I guess it's fine. I'm just adding a lot of functionality to it.

Furthermore, I really doubt anyone will use this besides me : |. I need it for a morale and bonus system as well as the evo/devo system.
 
Top