--######################################################################################################### -- IRLUA PLUGIN HELPER FUNCTIONS By MicroByte (Revised by Centauri Soldier) ||@#$|| VERSION 2.7 ||$#@|| --######################################################################################################### _ShowErrorEventContext=true-- set this to false to disable 'EventContext' display --######################################################################################################### local IRLUA_PLUGIN_ERROR = error; --######################################################################################################### -- Sets a Global error message in the runtime engine. IRLUA_PLUGIN_SetGlobalErrorMessage = function(nCode, sMessage) if _tblErrorMessages[nCode] then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() IRLUA_PLUGIN_ERROR("Error code "..nCode.." already in use, please use another.\r\n\r\nEventContext: "..sEventContext,2) else IRLUA_PLUGIN_ERROR("Error code "..nCode.." already in use, please use another.",2) end else _tblErrorMessages[nCode]=sMessage end end --######################################################################################################### -- Checks the number of arguments in the table and throws a syntax error If there are Not enough. -- This is useful For checking the number of arguments available To your aciton. local IRLUA_PLUGIN_CheckNumArgs = function(tbArgs,nArgs) local nCount=table.getn(tbArgs) if nCount < nArgs then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() IRLUA_PLUGIN_ERROR(nArgs.." Arguments expected, "..nCount.." Arguments passed.\r\n\r\nEventContext: "..sEventContext,3) else IRLUA_PLUGIN_ERROR(nArgs.." Arguments expected, "..nCount.." Arguments passed.",3) end end end --######################################################################################################### -- Checks the value at a given argument table position To see if it is any of the specified types. -- If Not it throws a syntax error. --Possible variable types[ boolean, function, nil, number, string, table, thread, userdata] local IRLUA_PLUGIN_CheckTypes = function(tbArgs,nArg,tTypes) local sType = type(tbArgs[nArg]); local nTotalTypes = Table.Count(tTypes); local nStrikes = 0; local sAllowedTypes = ""; for nIndex, sAllowedType in pairs(tTypes) do if nIndex < (nTotalTypes - 1) then sAllowedTypes = sAllowedTypes.." "..sAllowedType..","; elseif nIndex == nTotalTypes - 1 then sAllowedTypes = sAllowedTypes.." "..sAllowedType; elseif nIndex == nTotalTypes then if nTotalTypes == 1 then sAllowedTypes = " "..sAllowedType; else sAllowedTypes = sAllowedTypes.." or "..sAllowedType; end end if sType ~= String.Lower(sAllowedType) then nStrikes = nStrikes + 1; end end if nStrikes == nTotalTypes then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() IRLUA_PLUGIN_ERROR("bad argument #" .. nArg .. ", must be a "..sAllowedTypes..", you passed a "..sType..".\r\n\r\nEventContext: "..sEventContext,3) else IRLUA_PLUGIN_ERROR("bad argument #" .. nArg .. ", must be a "..sAllowedTypes..", you passed a "..sType..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Ensures that your table contains data of only the specified type. If it does not then false is returned. -- This will see nil values as subtable declarations and will, therefore, ignore them. local IRLUA_PLUGIN_CheckTableVars = function(tTable,tVarTypes) local bRet = true; local nTypes = Table.Count(tVarTypes); local nStrikes = 0; for nIndex, sItem in pairs(tTable) do nStrikes = 0; for nType, sType in pairs(tVarTypes) do if type(sItem) ~= sType then nStrikes = nStrikes + 1; end end if nStrikes >= nTypes then bRet = false; break; end end return bRet end --######################################################################################################### -- Converts certain datatypes into other datatypes ||| Supported Types ||| -- [String <-> Boolean] [Number <-> Boolean] [String <-> Number] --######################################################################################################### local CONVERT = function (vInput, sNewType) local sOldType = type(vInput); if sNewType == "boolean" then if sOldType == "string" then if String.Lower(vInput) == "true" then return true elseif String.Lower(vInput) == "false" then return false end elseif sOldType == "number" then if vInput == 0 then return false elseif vInout == 1 then return true end end elseif sNewType == "string" then if sOldType == "boolean" then if vInput == true then return "true" elseif vInput == false then return "false" end elseif sOldType == "number" then return ""..vInput.."" end elseif sNewType == "number" then if sOldType == "boolean" then if vInput == true then return 1 elseif vInput == false then return 0 end elseif sOldType == "string" then return tonumber(vInput); end end end --######################################################################################################### --ERROR PLUGIN DETAILS local ERROR_PLUGIN_NAME = "Box"; --######################################################################################################### --Displays a custom error message using the plugin and function name and lists the event context as well. local ERROR = function(sFunctionName,sMessage,nEmbedLevel) if not nEmbedLevel then nEmbedLevel = 0; elseif type(nEmbedLevel) ~= "number" then nEmbedLevel = 0; end if type(sFunctionName) ~= "string" then sFunctionName = ""; end local sFunctionNameCode = ""; if String.Replace(sFunctionName, " ", "", false) ~= "" then sFunctionNameCode = ", function \""..sFunctionName.."()\""; end IRLUA_PLUGIN_ERROR("\r\nError in \""..ERROR_PLUGIN_NAME.."\" plugin"..sFunctionNameCode.."\r\n\r\n"..sMessage.."\r\n\r\nEventContext: "..Debug.GetEventContext(),3 + nEmbedLevel); end --######################################################################################################### --Throws and error if the required plugin is not loaded local REQUIRE = function(tPlugin,sPluginName) if not tPlugin then IRLUA_PLUGIN_ERROR("\r\nError loading the \""..ERROR_PLUGIN_NAME.."\" plugin.\r\nThis plugin requires the \""..sPluginName.."\" plugin by retest."); end end --######################################################################################################### -- END IRLUA PLUGIN HELPER FUNCTIONS --######################################################################################################### Box = {}; _BOXES = {}; _BOX_NAMES = {}; _BOX_MAX = 100; _BOX_CHECKLIST = {}; REQUIRE(GlobalTimer, "GlobalTimer"); --[[Version History Version 1.0.0.1 Fixed a bug in Box.IsFull() ]] --============================== --Box.Bump --============================== function Box.Bump(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then loadstring(_BOXES[Box.GetID(sBox)])(); end end --============================== --Box.Close --============================== function Box.Close(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then GlobalTimer.Stop(Box.GetID(sBox)); end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.Empty --============================== function Box.Empty(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then local nID = Box.GetID(sBox); _BOXES[nID] = {}; _BOXES[nID].Open = false; _BOXES[nID].Interval = -1; _BOXES[nID].Script = ""; _BOX_NAMES[sBox] = nil; _BOX_CHECKLIST[nID] = 0; end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.Fill --============================== function Box.Fill(...) IRLUA_PLUGIN_CheckNumArgs(arg,4); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); local sLoadType = IRLUA_PLUGIN_CheckTypes(arg,2,{"string"}); local sScript = IRLUA_PLUGIN_CheckTypes(arg,3,{"string"}); local nInterval = IRLUA_PLUGIN_CheckTypes(arg,4,{"number"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then Box.Empty(sBox); end local nID = Box.GetEmpty(); if nID ~= -1 then if sLoadType == "file" then if File.DoesExist(sScript) then _BOX_NAMES[sBox] = nID; _BOXES[nID].Script = TextFile.ReadToString(sScript); _BOXES[nID].Interval = nInterval; _BOX_CHECKLIST[nID] = 1; else return -1 end elseif sLoadType == "string" then _BOX_NAMES[sBox] = nID; _BOXES[nID].Script = sScript; _BOXES[nID].Interval = nInterval; _BOX_CHECKLIST[nID] = 1; end return 0 else return -1 end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.GetBumpInterval --============================== function Box.GetBumpInterval(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then return _BOXES[Box.GetID(sBox)].Interval else return -2 end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.GetClosedBoxes --============================== function Box.GetClosedBoxes() if _BOX_NAMES then local tRet = {}; local x = 0; for sBox, nID in pairs(_BOX_NAMES) do if _BOXES[Box.GetID(sBox)].Open == false then x = x + 1; tRet[x] = sBox; end end return tRet else return nil end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== HIDDEN --Box.GetEmpty --============================== HIDDEN function Box.GetEmpty() for nIndex, nIndicator in pairs(_BOX_CHECKLIST) do if nIndicator == 0 then return nIndex end end return -1 end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== HIDDEN --Box.GetID --============================== HIDDEN function Box.GetID(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< return _BOX_NAMES[sBox] end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.GetNames --============================== function Box.GetNames() if _BOX_NAMES then local tRet = {}; local x = 0; for sBox, nID in pairs(_BOX_NAMES) do x = x + 1; tRet[x] = sBox; end return tRet else return nil end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.GetOpenBoxes --============================== function Box.GetOpenBoxes() if _BOX_NAMES then local tRet = {}; local x = 0; for sBox, nID in pairs(_BOX_NAMES) do if _BOXES[Box.GetID(sBox)].Open == true then x = x + 1; tRet[x] = sBox; end end return tRet else return nil end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.GetScript --============================== function Box.GetScript(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then return _BOXES[Box.GetID(sBox)].Script else return "" end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --==============================!!! --Box.Initialize --============================== function Box.Initialize(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local nMaxBoxes = IRLUA_PLUGIN_CheckTypes(arg,1,{"number"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if nMaxBoxes > 0 then _BOX_MAX = nMaxBoxes; end for x = 1, _BOX_MAX do _BOX_CHECKLIST[x] = 0; end for x = 1, _BOX_MAX do _BOXES[x] = {}; _BOXES[x].Open = false; _BOXES[x].Interval = -1; _BOXES[x].Script = ""; end local sTimerText = [[function GlobalTimer.OnTimer (nID) if nID == 1 then loadstring(_BOXES[1].Script)(); ]]; for x = 2, _BOX_MAX do local sNextLine = [[ elseif nID == ]]..x..[[ then loadstring(_BOXES[]]..x..[[].Script)(); ]]; sTimerText = sTimerText..sNextLine end sTimerText = sTimerText..[[ end end]]; Application.Sleep((_BOX_MAX * 2)); loadstring(sTimerText)(); end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --==============================!!! --Box.IsOpen --============================== function Box.IsOpen(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then return _BOXES[Box.GetID(sBox)].Open else return false end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --==============================!!! --Box.IsFull --============================== function Box.IsFull(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if _BOX_NAMES[sBox] then return true else return false end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --==============================!!! --Box.Open --============================== function Box.Open(...) IRLUA_PLUGIN_CheckNumArgs(arg,1); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then local nID = Box.GetID(sBox); GlobalTimer.Start(nID, _BOXES[nID].Interval); end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --============================== --Box.SetBumpInterval --============================== function Box.SetBumpInterval(...) IRLUA_PLUGIN_CheckNumArgs(arg,2); local sBox = IRLUA_PLUGIN_CheckTypes(arg,1,{"string"}); local nInterval = IRLUA_PLUGIN_CheckTypes(arg,2,{"number"}); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if Box.IsFull(sBox) then if nInterval > 0 then _BOXES[Box.GetBoxID(sBox)].Interval = nInterval; end end end -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>