--[[ userfunction_call.lua v1.0 Call/chain/return to another waypoint file This implements a call/resturn stack for the waypoint files as an alternative to chaining waypoint files together. --]] local wtitle = true -- Show info in rom window title local wpstack = {} -- Hook "error" call usually used to finish scripts local old_error = error function error(msg, lvl) if type(lvl) == "number" and lvl == 0 and isCalled() then cprintf(cli.yellow, "Redirected error: %s [%d]\n", msg, lvl) WPFinished() -- Fails as it returns, error doesnt? else old_error(msg, lvl) end end -- Set script in window title local function setTitle(wp) if wtitle then local currAcc = RoMScript("LogID") local currChar = RoMScript("CHARACTER_SELECT.selectedIndex") setWindowName(getWin(), sprintf("%s lvl%d [%d:%d] %s", player.Name, player.Level, currAcc, currChar, wp)) end end --[[ Are we called from another script or not --]] function isCalled() return #wpstack > 0 end --[[ Execute a sequence of waypoint in order Ex: WPChain("dailies","events",__WPL.FileName) --]] function WPChain(...) for i=#args,1,-1 do table.insert(wpstack, arg[i]) end wp = table.remove(wpstack) setTitle(wp) loadPaths(wp) end --[[ Call a waypoint file and return to caller after --]] function WPCall(wp) WPChain(wp, __WPL.FileName) end --[[ Termination call for compliant waypoint files, this should handle Rock´s method of chaining for compatibility: i.e. argument: "end" to end script, "relog" to log next character, "charlist" to log next in 'charlist' and "waypointfilename" to load that waypointfile Note, these functions will only get executed if wpstack is empty --]] function WPFinished(When_Finished, charlist) if #wpstack > 0 then wp = table.remove(wpstack) setTitle(wp) loadPaths(wp) return wp elseif When_Finished == "relog" then ChangeChar() waitForLoadingScreen() yrest(3000) loadProfile() loadPaths(__WPL.FileName) elseif When_Finished == "charlist" then SetCharList(charlist) LoginNextChar() loadProfile() loadPaths(__WPL.FileName) elseif type(When_Finished) == "table" then SetCharList(When_Finished) LoginNextChar() loadProfile() loadPaths(__WPL.FileName) elseif When_Finished == "end" or When_Finished == nil then error("Ending script", 2) else local wpname = When_Finished if not string.find(wpname,".", 1, true) then wpname = wpname .. ".xml" end local filename = getExecutionPath() .. "/waypoints/" .. wpname local file, err = io.open(filename, "r") if file then file:close() loadPaths(When_Finished) else error(When_Finished, 2) end end return nil end -- Compatibility w. earlier version function WPReturn(action) return WPFinished(action) end