Snippet Lua_object_id

Nestharus

o-o
Reaction score
84
Actually LUA_OBJECT_ID, not Lua_object_id.

A very simple snippet for generating unique ids for objects with object merger.

The generateid function in object merger starts at its first index, so it does not return a completely unique id and may overwrite custom objects.

This script will continue to loop until it finds a unique id. Very simple, but very useful.

This script only returns a unique object id. It does not create the actual object for you.

Must be run through ObjectMerger

LUA_FILE_HEADER
JASS:

//GetObjectId 1.0.0.5
//! externalblock extension=lua FileExporter $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i writelua("GetObjectId", [[
    //////////////////////////////////////////////////////////////////
    //code

    //! i function getobjectid(obj, objecttype)
        //obj refers to the base object
            //"hpea", "Amov", "Bphx", etc
        //objectType refers to the type of object to create
        
        //! i if (currentobjecttype() ~= objecttype) then
            //! i setobjecttype(objecttype)
        //! i end
        //! i local object = generateid(obj)
        //! i while (
            //! i objectexists(object) or 
            //! i string.find(object, "'", 1, true) ~= nil or 
            //! i string.find(object, '\\', 1, true) ~= nil or 
            //! i string.find(object, ',', 1, true) ~= nil or 
            //! i string.find(object, '/', 1, true) ~= nil) do
            
            //! i object = generateid(obj)
            
        //! i end
        //! i return object
    //! i end

    //end code
    //////////////////////////////////////////////////////////////////
    //! i ]])
//! endexternalblock


Demo
JASS:

//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i dofile("GetObjectId")

    //generates an object id for hpea (peasant) of object type units
    //! i local object obj = getobjectid("hpea", "units")

    //create the object using the retrieved object id
    //! i setobjecttype("units")
    //! i createobject("hpea", obj)
        //modifications
//! endexternalblock
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top