- 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: