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

Using LUA Scripts

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
Im trying to use some LUA scripts for my map (never used them before) but whenever i try it always throws me this error

Unhandled Code Exception!

On external call:
//! external FileExporter $FILENAME#

Warcraft mpqs could not be opened

What am i doing? o_O
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
The Lua errors are always vague. It could be a permissions error (try running as admin), but I can't be sure.

Post the code.

Block

initscript

getvarobject

header

objectid

JASS:
//! externalblock extension=lua FileExporter $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    
    //BonusAbility v1.0.0.1
    //BonusJASS v1.0.0.0
    
    //! i writelua("BonusAbility", [======[
    //////////////////////////////////////////////////////////////////
    //code
    
    //! i abilities = {}
    //! i
    //! i Ability = {}    --[[
    //! i -------------------------------------------------------------------------------------------------------
    //! i *
    //! i *   Fields
    //! i *   ---------------------------------------------------------------------------------------------------
    //! i *   *   ->  maxpower        |   maximum power of ability (in base 2)
    //! i *   *   ->  isperc          |   is percent
    //! i *   *   ->  abilityid       |   id of ability object
    //! i *   *   ->  field           |   id of ability field that gives data bonus
    //! i *   *   ->  name            |   name to assign to ability object
    //! i *   *   ->  ranged          |   the ability has a definite range
    //! i *   ---------------------------------------------------------------------------------------------------
    //! i *
    //! i *   Functions
    //! i *   ---------------------------------------------------------------------------------------------------
    //! i *   *   ->  function Ability.new(perc, abilityid, bonusfield, name, ranged, enabled) returns ability
    //! i *   ---------------------------------------------------------------------------------------------------
    //! i *
    //! i ------------------------------------------------------------------------------------------------------- ]]
    //! i local function genobjects(self)
    //! i     local function getmultiplier(power)
    //! i         --[[get multiplier value]]
    //! i         local multiplier
    //! i
    //! i         multiplier = 1
    //! i
    //! i         if (self.isperc) then
    //! i             multiplier = .01
    //! i         end
    //! i
    //! i         --[[get multiplier sign]]
    //! i         if (self.ranged) then
    //! i             if (power == self.maxpower) then
    //! i                 multiplier = -multiplier
    //! i             end
    //! i         elseif (power == 0) then
    //! i             multiplier = 0
    //! i         elseif (power ~= self.maxpower + 1) then
    //! i             multiplier = -multiplier
    //! i         end
    //! i
    //! i         return multiplier
    //! i     end
    //! i
    //! i     ----------------------------------------------------------------------------
    //! i     --  CODE
    //! i     ----------------------------------------------------------------------------
    //! i         --[[generate objects]]
    //! i         if (self.ranged) then
    //! i             for power = 0, self.maxpower, 1 do
    //! i                 --[[create object]]
    //! i                 self.objects[power]=getvarobject(self.abilityid, "abilities","BONUS_" .. self.name .. "_" .. tostring(power), false)
    //! i                 self.abilities[power] = createobject(self.abilityid, self.objects[power])
    //! i
    //! i                 --[[set object name]]
    //! i                 makechange(self.abilities[power], "anam", "BONUS_" .. self.name .. "_" .. tostring(power))
    //! i
    //! i                 --[[set object bonus]]
    //! i                 makechange(current, self.field, 1, getmultiplier(power)*2^power)
    //! i             end
    //! i         else
    //! i             --[[create object]]
    //! i             self.objects[0] = getvarobject(self.abilityid, "abilities", "BONUS_" .. self.name, false)
    //! i             self.abilities[0] = createobject(self.abilityid, self.objects[0])
    //! i             makechange(self.abilities[0], "anam", "BONUS_" .. self.name .. "_" .. tostring(power))
    //! i
    //! i             --[[Level 1: 0]]
    //! i             --[[Level Mid: Negative Power - 1]]
    //! i             --[[Level Max: Positive Power - 1]]
    //! i             makechange(current, "alev", self.maxpower + 2)
    //! i
    //! i             --[[set object bonus]]
    //! i             for power = 0, self.maxpower + 2, 1 do
    //! i                 makechange(current, self.field, power + 1, getmultiplier(power)*2^(power - 1))
    //! i             end
    //! i         end
    //! i     ----------------------------------------------------------------------------
    //! i end
    //! i
    //! i function Ability.new(perc, abilityid, bonusfield, name, ranged, enabled, maxpower)    --[[
    //! i -------------------------------------------------------------------------------------------------------
    //! i *   -> perc                 |   is ability value percent?
    //! i *   -> abilityid            |   base ability id
    //! i *   -> bonusfield           |   field with value of ability
    //! i *   -> name                 |   name of ability
    //! i *   -> ranged               |   does ability have defined range
    //! i *   -> enabled              |   is ability enabled
    //! i *   -> maxpower             |   maximum power
    //! i ------------------------------------------------------------------------------------------------------- ]]
    //! i     local self = nil
    //! i
    //! i     if (enabled) then
    //! i         self = {}
    //! i
    //! i         --[[init fields]]
    //! i         self.objects = {}               --> stores generated ability ids
    //! i         self.abilities = {}             --> stores generated ability objects
    //! i         self.maxpower = maxpower        --> stores max power of 2 ability value can be
    //! i         self.isperc = perc              --> does ability use a percent value?
    //! i         self.abilityid = abilityid      --> base ability id
    //! i         self.field = bonusfield         --> object field that modifies bonus value
    //! i         self.name = name                --> ability name
    //! i         self.ranged = ranged            --> ability has definite range
    //! i
    //! i         --[[generate objects]]
    //! i         genobjects(self)
    //! i       end
    //! i
    //! i     table.insert(abilities,self)
    //! i     abilities = Ability.getvalid(abilities)                             --> filter out invalid abilities
    //! i     abilities.containslimited = Ability.limitedenabled(abilities)       --> determine if any abilities are limited
    //! i     abilities.containsunlimited = Ability.unlimitedenabled(abilities)   --> determines if any abilites are unlimited
    //! i
    //! i     return self
    //! i end
    //! i
    //! i function Ability.getvalid(abilities)
    //! i     local abilitylist = {}
    //! i     for id, ability in ipairs(abilities) do
    //! i         if (ability~=nil) then
    //! i             table.insert(abilitylist, ability)
    //! i         end
    //! i     end
    //! i     return abilitylist
    //! i end
    //! i
    //! i function Ability.limitedenabled(abilities)
    //! i     for id, ability in ipairs(abilities) do
    //! i         if (ability.limited) then
    //! i             return true
    //! i         end
    //! i     end
    //! i     return false
    //! i end
    //! i function Ability.unlimitedenabled(abilities)
    //! i     for id, ability in ipairs(abilities) do
    //! i         if (ability.limited) then
    //! i             return true
    //! i         end
    //! i     end
    //! i     return false
    //! i end
    
    //end code
    //////////////////////////////////////////////////////////////////
    //! i ]======])
    
    
    //! i writelua("BonusJASS", [======[
    //////////////////////////////////////////////////////////////////
    //code

    //! i BonusJASS = { }
    //! i
    //! i local POWER_MAX = "pm"      --> max power
    //! i local POWER_SET = "ps"      --> power set (2^0 to 2^POWER_MAX)
    //! i local OBJECT_ID = "bo"      --> object ids
    //! i local IS_RANGED = "ir"      --> is ranged
    //! i local BINARY_POWER = "bp"   --> power of 2
    //! i local CURRENT_BONUS = "cb"  --> current bonus of unit
    //! i
    //! i local function getabilityids(abilities)
    //! i     local constants = ""
    //! i     local prefix
    //! i     local cur = 0
    //! i
    //! i     for id, ability in ipairs(abilities) do
    //! i         constants = constants .. "constant integer BONUS_" .. ability.name .. "=" .. tostring(cur) .. "\n"
    //! i         cur = cur + ability.maxpower + 1
    //! i         if (not ability.ranged) then
    //! i             cur = cur + 1
    //! i         end
    //! i     end
    //! i
    //! i     return constants
    //! i end
    //! i
    //! i local function getisranged(abilities)
    //! i     local isranged = ""
    //! i     local cur = 0
    //! i
    //! i     for id, ability in ipairs(abilities) do
    //! i         if (ability.ranged) then
    //! i             isranged = isranged .. "set " .. IS_RANGED .. "[" .. tostring(cur) .. "]=true\n"
    //! i         else
    //! i             isranged = isranged .. "set " .. IS_RANGED .. "[" .. tostring(cur) .. "]=false\n"
    //! i             cur = cur + 1
    //! i         end
    //! i         cur = cur + ability.maxpower + 1
    //! i     end
    //! i
    //! i     return isranged
    //! i end
    //! i
    //! i local function getpowermax(abilities)
    //! i     local powermax = ""
    //! i     local cur = 0
    //! i
    //! i     for id, ability in ipairs(abilities) do
    //! i         powermax = powermax .. "set " .. POWER_MAX .. "[" .. tostring(cur) .. "]=" .. tostring(ability.maxpower) .. "\n"
    //! i         cur = cur + ability.maxpower + 1
    //! i         if (not ability.ranged) then
    //! i             cur = cur + 1
    //! i         end
    //! i     end
    //! i
    //! i     return powermax
    //! i end
    //! i
    //! i local function getpowerset(abilities)
    //! i     local powerset = ""
    //! i     local index = 0
    //! i     for id, ability in ipairs(abilities) do
    //! i         if (ability.ranged) then
    //! i             for power = 0, ability.maxpower - 1, 1 do
    //! i                 powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring((2^power)) .. "\n"
    //! i                 powerset = powerset .. "set " .. BINARY_POWER .. "[" .. tostring(index) .. "]=" .. tostring(power) .. "\n"
    //! i                 index = index + 1
    //! i             end
    //! i         else
    //! i             powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring(0) .. "\n"
    //! i             index = index + 1
    //! i             for power = 0, ability.maxpower - 1, 1 do
    //! i                 powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring((2^power)) .. "\n"
    //! i                 powerset = powerset .. "set " .. BINARY_POWER .. "[" .. tostring(index) .. "]=" .. tostring(power) .. "\n"
    //! i                 index = index + 1
    //! i             end
    //! i         end
    //! i         powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring(-(2^ability.maxpower)) .. "\n"
    //! i         powerset = powerset .. "set " .. BINARY_POWER .. "[" .. tostring(index) .. "]=" .. tostring(-ability.maxpower) .. "\n"
    //! i         index = index + 1
    //! i     end
    //! i     return powerset
    //! i end
    //! i
    //! i local function getobjectids(abilities)
    //! i     local powerset = ""
    //! i     local index = 0
    //! i     for id, ability in ipairs(abilities) do
    //! i         if (ability.ranged) then
    //! i             for power = 0, ability.maxpower, 1 do
    //! i                 powerset = powerset .. "set " .. OBJECT_ID .. "[" .. tostring(index) .. "]='" .. ability.objects[power] .. "'\/\/" .. tostring(power) .. "\n"
    //! i                 index = index + 1
    //! i             end
    //! i         else
    //! i             powerset = powerset .. "set " .. OBJECT_ID .. "[" .. tostring(index) .. "]='" .. ability.objects[0] .. "'\n"
    //! i             index = index + 2 + ability.maxpower
    //! i         end
    //! i     end
    //! i     return powerset
    //! i end
    //! i
    //! i local function getpreload(abilities)
    //! i     local preload=""
    //! i     for id, ability in ipairs(abilities) do
    //! i         if (ability.ranged) then
    //! i             for power = 0, ability.maxpower, 1 do
    //! i                 preload = preload .. "call UnitAddAbility(u,'" .. ability.objects[power] .. "')\n"
    //! i             end
    //! i         else
    //! i             preload = preload .. "call UnitAddAbility(u,'" .. ability.objects[0] .. "')\n"
    //! i         end
    //! i     end
    //! i     return preload
    //! i end
    //! i
    //! i function BonusJASS.get(abilities)
    //! i     local beginglobals = "globals\n"
    //! i         local powermax = "private integer array " .. POWER_MAX .. "\n"
    //! i         local powerset = "private integer array " .. POWER_SET .. "\n"
    //! i         local binarypower = "private integer array " .. BINARY_POWER .. "\n"
    //! i         local objectid = "private integer array " .. OBJECT_ID .. "\n"
    //! i         local isranged = "private boolean array " .. IS_RANGED .. "\n"
    //! i         local currentbonus = "private Table array " .. CURRENT_BONUS .. "\n"
    //! i         local abilityids = getabilityids(abilities)
    //! i     local endglobals = "endglobals\n"
    //! i
    //! i     local begininit = "private module I\nprivate static method onInit takes nothing returns nothing\n"
    //! i         local preloadif = "static if PRELOAD then\n"
    //! i         local preloadend = "endif\n"
    //! i         local preload = "local unit u\nset UnitIndexer.enabled=false\nset u = CreateUnit(Player(14),'hpea',0,0,0)\n" .. getpreload(abilities) .. "call RemoveUnit(u)\nset u = null\nset UnitIndexer.enabled=true\n"
    //! i         local index = "call RegisterUnitIndexEvent(Condition(function thistype.index), UnitIndexer.INDEX)\n"
    //! i         local deindex = "call RegisterUnitIndexEvent(Condition(function thistype.deindex), UnitIndexer.DEINDEX)\n"
    //! i         local objectids = getobjectids(abilities)   --> actual object ids of abilities for UnitAddAbility
    //! i         local powermaxes = getpowermax(abilities)   --> max power (from config)
    //! i         local powersets = getpowerset(abilities)    --> power set: 1, 2, 4, 8, -16 etc
    //! i         local israngeds = getisranged(abilities)    --> is ability ranged or not
    //! i     local endinit = "endmethod\nendmodule\n"
    //! i
    //! i     local beginstruct = "private struct O extends array\n"
    //! i         local beginindex = "private static method index takes nothing returns boolean\n"
    //! i             local indexcode =
    //! i             [[set cb[GetIndexedUnitId()] = Table.create()]] .. "\n"
    //! i         local endindex = "return false\nendmethod\n"
    //! i         local begindeindex = "private static method deindex takes nothing returns boolean\n"
    //! i             local deindexcode =
    //! i             [[call cb[GetIndexedUnitId()].destroy()]] .. "\n"
    //! i         local enddeindex = "return false\nendmethod\n"
    //! i     local endstruct = "implement I\nendstruct\n"
    //! i
    //! i     local jass = ""
    //! i
    //! i     jass = jass .. [[//! textmacro BONUS_SCRIPT]] .. "\n"
    //! i         jass = jass .. beginglobals
    //! i             jass = jass .. powermax
    //! i             jass = jass .. powerset
    //! i             jass = jass .. binarypower
    //! i             jass = jass .. objectid
    //! i             jass = jass .. isranged
    //! i             jass = jass .. currentbonus
    //! i             jass = jass .. abilityids
    //! i         jass = jass .. endglobals
    //! i
    //! i         jass = jass .. begininit
    //! i             jass = jass .. preloadif
    //! i                 jass = jass .. preload
    //! i             jass = jass .. preloadend
    //! i             jass = jass .. index
    //! i             jass = jass .. deindex
    //! i             jass = jass .. objectids
    //! i             jass = jass .. powermaxes
    //! i             jass = jass .. powersets
    //! i             jass = jass .. israngeds
    //! i         jass = jass .. endinit
    //! i
    //! i         jass = jass .. beginstruct
    //! i             jass = jass .. beginindex
    //! i                 jass = jass .. indexcode
    //! i             jass = jass .. endindex
    //! i             jass = jass .. begindeindex
    //! i                 jass = jass .. deindexcode
    //! i             jass = jass .. enddeindex
    //! i         jass = jass .. endstruct
    //! i     jass = jass .. [[//! endtextmacro]] .. "\n"
    //! i
    //! i     return jass
    //! i end

    //end code
    //////////////////////////////////////////////////////////////////
    //! i ]======])
//! endexternalblock
JASS:
/****************************************************************************************
*                                                                                       *
*                               Ranged Bonus Power                                      *
*                                                                                       *
*   Power determines how big a bonus range can go. For example, a power of 15 would be  *
*   -(2^16) to 2^(16)-1 or -65536 to 65535.                                            *
*                                                                                       *
*****************************************************************************************
*                                                                                       *
*                               Unlimited Bonus Power                                   *
*                                                                                       *
*   Power for unlimited bonuses increases speed of add/remove for larger values         *
*   and makes larger values easier to get to. For example, 50,000,000 is much           *
*   faster adding units of 1,048,576 than adding units of 16. In units of 16,           *
*   50,000,000 might as well be impossible to get to.                                   *
*                                                                                       *
*****************************************************************************************
*                                                                                       *
*                               ENABLED                                                 *
*                                                                                       *
*   Should the bonus be implemented into the system? By disabling a bonus, it will not  *
*   be in the system at all. Abilities and constants won't be made.                     *
*                                                                                       *
****************************************************************************************/
//! textmacro BONUS_CREATE_BONUSES
    /********************
    *                   *
    *   ability data    *
    *                   *
    ********************/
    //                perc          abil        field       name                    ranged             enabled          max power
    //! i Ability.new(false,        "AId1",     "Idef",     "ARMOR",                true,              true,            13)            --> armor
    //! i Ability.new(false,        "AItg",     "Iatt",     "DAMAGE",               true,              true,            23)            --> damage
    //! i Ability.new(false,        "AIa1",     "Iagi",     "AGILITY",              true,              true,            18)            --> agility
    //! i Ability.new(false,        "AIs1",     "Istr",     "STRENGTH",             true,              true,            18)            --> strength
    //! i Ability.new(false,        "AIi1",     "Iint",     "INTELLIGENCE",         true,              true,            18)            --> intelligence
    //! i Ability.new(false,        "AIlf",     "Ilif",     "LIFE",                 false,             true,            25)            --> life
    //! i Ability.new(false,        "Arel",     "Ihpr",     "LIFE_REGEN",           true,              true,            15)            --> life regen
    //! i Ability.new(false,        "AImb",     "Iman",     "MANA",                 false,             true,            1)            --> mana
    //! i Ability.new(true,         "AIrm",     "Imrp",     "MANA_REGEN",           true,              true,            8)             --> mana regen, 8 max
    //! i Ability.new(false,        "AIsi",     "Isib",     "SIGHT",                true,              true,            10)            --> sight, 10 max
    //! i Ability.new(true,         "AIsx",     "Isx1",     "ATTACK_SPEED",         true,              true,            8)             --> attack speed, 8 max
//! endtextmacro

/********************
*                   *
*       code        *
*                   *
********************/
//! externalblock extension=lua ObjectMerger $FILENAME$
//! runtextmacro LUA_FILE_HEADER()
//! i dofile("GetVarObject")
//! i dofile("BonusAbility")
//! i dofile("BonusJASS")
//! runtextmacro BONUS_CREATE_BONUSES()
//! i local jass = BonusJASS.get(abilities)
//! i writejass("BONUS",jass)
//! i updateobjects()
//! endexternalblock)
JASS:
//GetVarObject 3.0.0.5
//function getvarobject(base, objtype, varname, import)
    //base: base id of object
        //"hpea", "Amov", "Bphx", etc
        
    //objtype: type of object
        //"units", "abilities", "items", etc
        
    //varname: name assigned to variable
        //OBJECTTYPE_NAME
        //"UNITS_MY_UNIT", "ABILITIES_RAIN_OF_CHAOS", etc
        
    //import: should the variable be imported into the map as a global?
        //true, false, nil
        
//function getvarobjectname(value)
    //retrieve name given value ("hpea", etc)
    
//function getvarobjectvalue(objectname)
    //retrieve value given name ("UNITS_MY_UNIT", etc)
    
//function updateobjects()
    //call at end of script
        
//! externalblock extension=lua FileExporter $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    
    //! i writelua("GetVarObject", [[
    //////////////////////////////////////////////////////////////////
    //code
    
    //! i local filename = "JassGlobals"
    //! i local filename_lua = getfilename() .. "_VAR_OBJECT_JassGlobals1"
    
    //! i dofile("GetObjectId")
    
    //! i local vars = readlua(filename_lua)
    //! i local vars2 = readjass(filename)
    //! i local varsdata
    //! i local newvars = ""
    
    //! i if (vars == nil) then
        //! i vars = {}
        //! i vars2 = ""
        //! i varsdata = ""
    //! i else
        //! i if (vars ~= "return {}") then
            //! i varsdata = vars:sub(9,vars:len()-1)
            //! i vars = loadstring(vars)()
        //! i else
            //! i varsdata = ""
            //! i vars = {}
        //! i end
        //! i if (vars2 == nil) then
            //! i vars2 = ""
        //! i else
            //! i vars2 = vars2:sub(string.len("globals")+1, vars2:len()-string.len("\nendglobals"))
        //! i end
    //! i end
    
    //! i local imports = {}
    //! i do
        //! i local s,k = vars2:find("constant integer ")
        //! i local s2,k2
        //! i while (s ~= nil) do
            //! i s2,k2 = vars2:find("=", k)
            //! i imports[vars2:sub(k+1, s2-1)] = true
            //! i s,k = vars2:find("constant integer ", k2)
        //! i end
    //! i end
    
    //! i function getvarobject(base, objtype, varname, import)
        //! i local value = vars[varname]
        //! i local imported
        //! i if (import == nil) then
            //! i import = false
        //! i end
        //! i if (value == nil) then
            //! i imported = false
            //! i value = getobjectid(base, objtype)
            //! i while (vars["1" .. value] ~= nil) do
                //! i value = getobjectid(base, objtype)
            //! i end
            //! i vars[varname] = value
            //! i vars["1" .. value] = varname
            //! i if (newvars == "") then
                //! i newvars = "['" .. varname .. "']='" .. vars[varname] .. "',['1" .. value .. "']='" .. varname .. "'"
            //! i else
                //! i newvars = newvars .. ",['" .. varname .. "']='" .. vars[varname] .. "',['1" .. value .. "']='" .. varname .. "'"
            //! i end
        //! i else
            //! i imported = imports[varname] or false
            //! i if (currentobjecttype() ~= objtype) then
                //! i setobjecttype(objtype)
            //! i end
        //! i end
        //! i if (import ~= imported) then
            //! i if (not imported) then
                //! i vars2 = vars2 .. "\nconstant integer " .. varname .. "='" .. value .. "'"
            //! i elseif (imported) then
                //! i local s,k = string.find(vars2, "\nconstant integer " .. varname .. "='" .. value .. "'")
                //! i vars2 = vars2:sub(1,s-1) .. vars2:sub(k+1, vars2:len())
            //! i end
            //! i imports[varname] = import
        //! i end
        //! i return value
    //! i end
    
    //! i function getvarobjectname(value)
        //! i return vars["1" .. value]
    //! i end
    
    //! i function getvarobjectvalue(objectname)
        //! i return vars[objectname]
    //! i end
    
    //! i function updateobjects()
        //! i writejass(filename, "globals" .. vars2 .. "\nendglobals")
        //! i if (varsdata == "") then
            //! i varsdata = newvars
        //! i elseif (newvars ~= "") then
            //! i varsdata = varsdata .. "," .. newvars
        //! i end
        //! i newvars = ""
        //! i writelua(filename_lua, "return {" .. varsdata .. "}")
    //! i end

    //end code
    //////////////////////////////////////////////////////////////////
    //! i ]])
//! endexternalblock
JASS:
//Writes map header to map (run once, but multiple times won't hurt)
//------------------------------------------------------------------------
    //function initmap()
    
    //comment after initialization
    ///*
    //! externalblock extension=lua FileExporter $FILENAME$
        //! runtextmacro LUA_FILE_HEADER()
        //! i initmap()
    //! endexternalblock
    //*/

    //uncomment after initialization
    ///! import "luajass.FILE_NAME.j"
//------------------------------------------------------------------------


//import and run lua script to current script (all do same thing)
//------------------------
    //function dofile(name)
    //function require(name)
    //function loadfile(name)

//lua scripts are shared across all maps
//jass scripts are local to a map

//returns code inside of file
//------------------------
    //function readlua(name)
    //function readjass(name)

//writes code to file
//------------------------
    //function writelua(name, code)
    //function writejass(name, code)

//deletes file
//------------------------
    //function deletelua(name)
    //function deletejass(name)

//! textmacro LUA_FILE_HEADER
    //! i do
        //replace "FILE_NAME" with the name of the map
        //must be valid directory name
        //! i local FILENAME = "FILE_NAME"
        
        //! i function getfilename()
            //! i return FILENAME
        //! i end
        
        //Initialization
        ///////////////////////////////////////////////////////////////////////
        //! i local PATH_LUA_p = "grimext\\luadir"
        //! i local PATH_JASS_p = PATH_LUA_p .. "\\" .. FILENAME .. "_dir"
        
        //! i local PATH_LUA = PATH_LUA_p .. "\\"
        //! i local PATH_JASS = PATH_JASS_p .. "\\"
        //! i local JASS_HUB = "jass\\luajass." .. FILENAME .. ".j"
        //! i function initmap()
            //! i os.execute("if not exist " .. PATH_LUA .. " (mkdir " .. PATH_LUA .. ")")
            //! i os.execute("if not exist " .. PATH_JASS .. " (mkdir " .. PATH_JASS .. ")")
            //! i local file = io.open(JASS_HUB, "r")
            //! i if (file == nil) then
                //! i file = io.open(JASS_HUB, "w")
                //! i file:write("")
                //! i file:close()
            //! i else
                //! i file:close()
            //! i end
            
            //! i os.execute("if not exist grimext\\luadir\\" .. FILENAME .. "_dir (mkdir grimext\\luadir\\" .. FILENAME .. "_dir)")
        //! i end
        ///////////////////////////////////////////////////////////////////////
        
        //! i local olddofile = dofile
        //! i local oldrequire = require
        //! i local oldloadfile = loadfile
        //! i function dofile(name)
            //! i oldrequire("luadir\\" .. name)
        //! i end
        //! i function require(name)
            //! i dofile(name)
        //! i end
        //! i function loadfile(name)
            //! i dofile(name)
        //! i end
        
        //! i local function getluapath(name)
            //! i return (PATH_LUA .. name .. ".lua")
        //! i end
        //! i local function getjasspath(name)
            //! i return (PATH_JASS .. name .. ".luajass.j")
        //! i end
        //! i local function getjassimport(name)
            //! i return ("\/\/! import \"..\\" .. getjasspath(name) .. "\"")
        //! i end
        
        //! i local function del(name)
            //! i os.remove(name)
        //! i end
        //! i local function read(path)
            //! i local file = io.open(path, "r")
            //! i code = nil
            //! i if (file ~= nil) then
                //! i code = file:read("*all")
                //! i file:close()
            //! i end
            //! i return code
        //! i end
        //! i local function write(path, code)
            //! i file = io.open(path, "w")
            //! i file:write(code)
            //! i file:close()
        //! i end
        //! i local function import(name)
            //! i local code = read(JASS_HUB)
            //! i local line = getjassimport(name) .. "\n"
            //! i local s,k = code:find(line)
            //! i if (s == nil) then
                //! i write(JASS_HUB, code .. line)
            //! i end
        //! i end
        
        //! i function readlua(name)
            //! i return read(getluapath(name))
        //! i end
        //! i function writelua(name, code)
            //! i write(getluapath(name), code)
        //! i end
        //! i function readjass(name)
            //! i return read(getjasspath(name))
        //! i end
        //! i function writejass(name, code)
            //! i write(getjasspath(name), code)
            //! i import(name)
        //! i end
        //! i function deletelua(name)
            //! i del(getluapath(name))
        //! i end
        //! i function deletejass(name)
            //! i del(getjasspath(name))
            //! i local line = getjassimport(name) .. "\n"
            //! i local code = read(JASS_HUB)
            //! i local s,k = code:find(line)
            //! i if (s ~= nil) then
                //! i write(JASS_HUB, code:sub(1,s-1) .. code:sub(k+1))
            //! i end
        //! i end
    //! i end
//! endtextmacro
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

for

JASS:
library Bonus /* v2.0.0.2
*************************************************************************************
*
*   Adds bonuses to units. In the ini area, these bonuses can be enabled and disabled.
*   Ranges of bonus values can also be modified.
*
*   Bonuses
*       -   Armor                   any unit                        non percent bonus
*       -   Damage                  units with attack only          non percent bonus
*       -   Agility                 hero only                       non percent bonus
*       -   Strength                hero only                       non percent bonus
*       -   Intelligence            hero only                       non percent bonus
*       -   Life                    any unit                        non percent bonus
*       -   Life Regeneration       any unit                        non percent bonus
*       -   Mana                    any unit                        non percent bonus
*       -   Mana Regeneration       units with mana only            percent bonus
*       -   Sight Range             any unit                        non percent bonus
*       -   Attack Speed            units with attack only          percent bonus
*
*************************************************************************************
*
*   */uses/*
*        UnitIndexer        hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
*       */ Table /*             hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
************************************************************************************
*   SETTINGS
*/
globals
    /*************************************************************************************
    *
    *                                   PRELOAD
    *
    *   Preloads all bonus abilities. This will add a hefty load time to the map but will
    *   prevent lag in game.
    *
    *************************************************************************************/
    private constant boolean PRELOAD = false
endglobals
/*
*************************************************************************************
*
*   Bonuses
*
*       constant integer BONUS_ARMOR
*       constant integer BONUS_DAMAGE
*       constant integer BONUS_AGILITY
*       constant integer BONUS_STRENGTH
*       constant integer BONUS_INTELLIGENCE
*       constant integer BONUS_LIFE
*       constant integer BONUS_LIFE_REGEN
*       constant integer BONUS_MANA
*       constant integer BONUS_MANA_REGEN
*       constant integer BONUS_ATTACK_SPEED
*       constant integer BONUS_SIGHT
*
*   Functions
*
*       function GetUnitBonus takes unit whichUnit, integer whichBonus returns integer
*       function SetUnitBonus takes unit whichUnit, integer whichBonus, integer value returns nothing
*       function AddUnitBonus takes unit whichUnit, integer whichBonus, integer value returns nothing
*
************************************************************************************/
    //! runtextmacro BONUS_CREATE_BONUSES()
    function SetUnitBonus takes unit u, integer b, integer v returns nothing
        local boolean n
        local integer a
        local integer p
        local integer on
        local integer i
        local integer nch
        local integer nb
        debug if (not IsUnitIndexed(u)) then
            debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT BONUS ERROR: INVALID UNIT")
            debug return
        debug endif
        debug if (0==pm[b]) then
            debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT BONUS ERROR: INVALID BONUS TYPE")
            debug return
        debug endif
        set i=GetUnitUserData(u)
        if (v != cb[i][b]) then
            set nch=0
            if (ir[b]) then
                set n=0>v
                set cb[i][b]=v
                set p=b+pm[b]-1
                set on=p+1
                call UnitRemoveAbility(u,bo[on])
                if (n) then
                    set v=v-ps[on]
                endif
                loop
                    if (0>v-ps) then
                        call UnitRemoveAbility(u,bo)
                    else
                        call UnitAddAbility(u,bo)
                        call UnitMakeAbilityPermanent(u,true,bo)
                        set v=v-ps
                    endif
                    exitwhen p==b
                    set p=p-1
                endloop
                if (n) then
                    call UnitAddAbility(u,bo[on])
                    call UnitMakeAbilityPermanent(u,true,bo[on])
                endif
            else
                set nb=v
                set v=v-cb[i][b]
                set cb[i][b]=nb
                set a=bo[b]
                set on=b+pm[b]+1
                loop
                    loop
                        exitwhen 0<v
                        set v=v-ps[on]
                        set nch=nch+1
                    endloop
                    set p=b+pm[b]
                    loop
                        if (0<=v-ps) then
                            set v=v-ps
                            call UnitAddAbility(u,a)
                            call SetUnitAbilityLevel(u,a,bp+2)
                            call UnitRemoveAbility(u,a)
                        else
                            set p=p-1
                            exitwhen p==b
                        endif
                    endloop
                    exitwhen 0==v
                endloop
                loop
                    exitwhen 0==nch
                    set nch=nch-1
                    call UnitAddAbility(u,a)
                    call SetUnitAbilityLevel(u,a,(-bp[on])+2)
                    call UnitRemoveAbility(u,a)
                endloop
            endif
        endif
    endfunction
    function GetUnitBonus takes unit u, integer b returns integer
        return cb[GetUnitUserData(u)][b]
    endfunction
    function AddUnitBonus takes unit u, integer b, integer v returns nothing
        call SetUnitBonus(u,b,GetUnitBonus(u,b)+v)
    endfunction
endlibrary

e/ tried to follow

http://www.hiveworkshop.com/forums/...art-guide-installing-lua-scripts-easy-195612/

but got same error when i tried to save
 
Last edited:
Do you get this error for all Lua codes? Disable those Lua triggers and then try using this:
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
    //! i setobjecttype("abilities")
    //! i createobject("Amls","AXFX")
    //! i makechange(current,"anam","Fire")
    //! i makechange(current,"atar","1","Air,Enemy,Organic,Neutral")
    //! i makechange(current,"amcs","1","15")
//! endexternalblock
See if it works.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Same error.

E/ my JassHelper might not be 100% updated

//=====================================
// 2012-03-10
//=====================================
* Fixed a bug with //! external directive
* Fixed a bug with debug keyword

ill try updating

e/ nope updating didnt help
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
1. right click newgen, go to compatability, check run as admin
2. select windows xp sp 2
3. clean your registry with ccleaner
4. restart comp

try to run lua again

if still not working, clean out tmp with ccleaner, then try again

if still not working, uninstall wc3, clean registry again, reinstall, install newgen via vid 1 in my tuts. Don't use cohadar's. Make sure you still have admin and compat on.

try lua again

if it still doesn't work, double check tmp to make sure it's not full: 65536 files

if it isn't, i'm out of ideas
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
1. right click newgen, go to compatability, check run as admin
2. select windows xp sp 2
3. clean your registry with ccleaner
4. restart comp

try to run lua again

if still not working, clean out tmp with ccleaner, then try again

if still not working, uninstall wc3, clean registry again, reinstall, install newgen via vid 1 in my tuts. Don't use cohadar's. Make sure you still have admin and compat on.

try lua again

if it still doesn't work, double check tmp to make sure it's not full: 65536 files

if it isn't, i'm out of ideas

nnnnnnnnnnnnnope.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Arhowk said:
Warcraft mpqs could not be opened

Are you sure you are not currently using the MPQ for something else, do you have any MPQ editor open, warcraft III open etc?

If the MPQ doesn't open this means that it's currently in use by another application. Perhaps this is what is causing your problem?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Status
Not open for further replies.
Top