--==<< Rock5's LoginNextChar Functions >>==-- --==<< By Rock5 Version 1.40 >>==-- --==<< >>==-- --==<< Requirements: 'fastLogin Revisited' v3.0 >>==-- --==<< >>==-- --==<< www.solarstrike.net/phpBB3/viewtopic.php?f=27&t=1245 >>==-- local charList = {} function SetCharList(_table) --[[ Example SetCharList({ {account=1, chars= {1,2,6}}, {account=2, chars= {1,3}}, {account=4, chars= {}}, }) Or for groups of accounts SetCharList({{ {account=1, chars= {1,2,6}}, {account=2, chars= {1,3}}, }, { {account=4, chars= {}}, }}) --]] -- Error check account lists local function checklist(_ltable) local errorcheck = false if type(_ltable) ~= "table" then errorcheck = true end for k,v in pairs(_ltable) do if type(v) ~= "table" then errorcheck = true break end if v.chars == nil then _ltable[k].chars = {} end if type(v.account) ~= "number" and type(v.chars ~= "table") then errorcheck = true break end for __,vv in pairs(v.chars) do if type(vv) ~= "number" then errorcheck = true break end end if errorcheck then break end end if errorcheck then error("SetCharList(); Invalid argument.") end end if _table[1].account ~= nil then -- Just a list checklist(_table) else for k,v in pairs (_table) do checklist(v) end end charList = table.copy(_table) end function ChangeChar(char, acc, chan) if char == "current" then char = RoMScript("CHARACTER_SELECT.selectedIndex") acc = nil end if char == nil then printf("Changing to next character") else printf("Changing to character %d", char) end if acc == nil or char == nil then printf(" on the same account") else printf(" account %s", tostring(acc)) end if chan then printf(" channel %d", chan) end printf(".\n") if type(acc) == "string" then acc = "\""..acc.."\"" end if type(chan) == "string" then chan = "\""..chan.."\"" end SlashCommand("/script ChangeChar("..(char or "nil")..","..(acc or "nil")..","..(chan or "nil")..")") end function LoginNextChar() local currAcc = RoMScript("LogID") local currChar = RoMScript("CHARACTER_SELECT.selectedIndex") local numChars = RoMScript("fastLoginNumChars") -- Character list defined? if #charList == 0 then error("LoginNextChar(); No character list defined. Use \"SetCharList(_table)\" to define list before using \"LoginNextChar()\"") end -- If groups of lists then find which list local lcharList if charList[1].account ~= nil then -- Just a list lcharList = charList else for k,group in pairs(charList) do for i,account in pairs(group) do if account.account == currAcc then lcharList = group break end end end end -- Find current char in list local found = false local nextAcc, nextChar printf("Current acc/char %d,%d\n",currAcc,currChar) for __, acc in pairs(lcharList) do print("checking account " ..acc.account) -- Current account found now look for current character. if #acc.chars ~= 0 then print("chars in list") for __, char in pairs(acc.chars) do print("checking char "..char) if found == true then nextAcc = acc.account nextChar = char printf("next char is acc %d, char %d\n",nextAcc,nextChar) break end if currAcc == acc.account and currChar == char then print("match found") -- next character is the one we want to load found = true end end else -- No chars specified for this account. Do all. print("no chars in list") if found == true then nextAcc = acc.account nextChar = 1 printf("next char is acc %d, char %d\n",nextAcc,nextChar) break end if currAcc == acc.account then if currChar < numChars then nextAcc = acc.account nextChar = currChar + 1 printf("next char on same acc, char %d\n",nextChar) break else print("match found") found = true end end end if nextAcc ~= nil then break end end if nextAcc == nil then -- Last character print("Last player finished.") player:logout() end ChangeChar(nextChar, nextAcc) yrest(2000) waitForLoadingScreen() yrest(5000) player:update() end function SetChannelForLogin(_value) RoMScript("} UserSelectedChannel = \"" .. _value .. "\" a={"); end function PrintCharList() if charList[1].account ~= nil then -- Just a list for k,v in pairs(charList) do printf("account = %d\tchars = ",v.account) print(unpack(v.chars)) end else for k,group in pairs(charList) do print("Account group "..k) for k,v in pairs(group) do printf("\taccount = %d\tchars = ",v.account) print(unpack(v.chars)) end end end end