It's a bit more work to support Toorum mode, where only 1 character is enabled, but I guess you could do the following;
Code: Select all
function getRandomChampion()
local validIndices = {}
for i = 1,4 do
if ( party:getChampion(i):getEnabled() and party:getChampion(i):isAlive() ) then
table.insert(validIndices, i);
end
end
if ( validIndices > 0 ) then
return validIndices[math.random(1, #validIndices)];
end
return nil;
end
Untested, so might have syntax mistakes, but this should work even with disabled characters / in toorum mode. The above also ensures the selected character is alive. Remove 'and party:getChampion(i):isAlive()' above to remove this constraint.
You could use the above to do the following...
Code: Select all
local champion = getRandomChampion();
if ( champion ~= nil ) then champion:setEnabled(false); end