Hey guys , I've been racking my brain with this LUA for auto combining skill cards . I can get everything working besides the actual combination when clicking the +1 to +2 combine option . Auth emu doesnt spit any issues , so i've tried racking Chatgpt's brain but no luck doing it's suggestions. Working with modified version of Revos 9.5.2 database
function get_module_name()
return "Skill_cardcombine"
end
function mapTable(inputTable, transformation)
local resultTable = {}
if type(inputTable) == "table" then
for i, value in ipairs(inputTable) do
table.insert(resultTable, transformation(value))
end
else
print("Input is not a table.")
end
return resultTable
end
sellCards = { 1, 2, 3, 4, 5 }
sellCards2 = mapTable(sellCards, function(e) return e * 10 + 2 end)
sellCards3 = mapTable(sellCards, function(e) return e * 10 + 3 end)
sellCards4 = mapTable(sellCards, function(e) return e * 10 + 4 end)
function inTable(tbl, item)
for , value in ipairs(tbl) do
if value == item then
return true
end
end
return false
end
function Skill_card_combine_contact()
dlg_title("Combine your skillcards")
dlg_text("Combine your skillcards in bulk!")
dlg_menu("Combine with normal cubes!", 'combine_with_normal_cubes_menu()')
dlg_menu("Combine with special cubes!", 'combine_with_special_cubes_menu()')
dlg_show()
end
function combine_with_normal_cubes_menu()
dlg_title("Combine your skillcards")
dlg_text("Combine your skillcards in bulk!")
dlg_menu("+1 to +2", 'attemptCombine(70)')
dlg_menu("+2 to +3", 'attemptCombine(60)')
dlg_menu("+3 to +4", 'attemptCombine(50)')
dlg_menu("+4 to +5", 'attemptCombine(40)')
dlg_show()
end
function combine_with_special_cubes_menu()
dlg_title("Combine your skillcards")
dlg_text("Combine your skillcards in bulk!")
dlg_menu("+1 to +2", 'combine_with_special_cubes(1)')
dlg_menu("+2 to +3", 'combine_with_special_cubes(2)')
dlg_menu("+3 to +4", 'combine_with_special_cubes(3)')
dlg_menu("+4 to +5", 'combine_with_special_cubes(4)')
dlg_show()
end
function attemptCombine(rate)
local count, tableChoice
if rate == 70 then
count = table.getn(sellCards)
tableChoice = sellCards
elseif rate == 60 then
count = table.getn(sellCards2)
tableChoice = sellCards2
elseif rate == 50 then
count = table.getn(sellCards3)
tableChoice = sellCards3
elseif rate == 40 then
count = table.getn(sellCards4)
tableChoice = sellCards4
end
for i = 1, count do
combine(tableChoice[i], rate)
end
end
function combine(id, rate)
local handles = get_item_handle_list(id)
local handleCount = table.getn(handles)
local success = 0
local is_card = inTable(sellCards,id) or inTable(sellCards2, id) or inTable(sellCards3, id) or inTable(sellCards4, id)
if handleCount > 1 then
local remainder = handleCount % 2
local totalOperations = (handleCount - remainder) / 2
for i = 1, totalOperations * 2, 2 do
local rng = math.random(0, 100)
delete_item(handles[i])
delete_item(handles[i + 1])
if rng <= rate then
if rate == 70 then
insert_item((id*10) + 1)
success = success + 1
elseif rate == 60 then
insert_item(id + 1)
success = success + 1
elseif rate == 50 then
insert_item(id +1 )
success = success + 1
elseif rate == 40 then
insert_item(id + 1)
success = success + 1
end
end
end
end
return success
end
return "Skill_cardcombine"
end
function mapTable(inputTable, transformation)
local resultTable = {}
if type(inputTable) == "table" then
for i, value in ipairs(inputTable) do
table.insert(resultTable, transformation(value))
end
else
print("Input is not a table.")
end
return resultTable
end
sellCards = { 1, 2, 3, 4, 5 }
sellCards2 = mapTable(sellCards, function(e) return e * 10 + 2 end)
sellCards3 = mapTable(sellCards, function(e) return e * 10 + 3 end)
sellCards4 = mapTable(sellCards, function(e) return e * 10 + 4 end)
function inTable(tbl, item)
for , value in ipairs(tbl) do
if value == item then
return true
end
end
return false
end
function Skill_card_combine_contact()
dlg_title("Combine your skillcards")
dlg_text("Combine your skillcards in bulk!")
dlg_menu("Combine with normal cubes!", 'combine_with_normal_cubes_menu()')
dlg_menu("Combine with special cubes!", 'combine_with_special_cubes_menu()')
dlg_show()
end
function combine_with_normal_cubes_menu()
dlg_title("Combine your skillcards")
dlg_text("Combine your skillcards in bulk!")
dlg_menu("+1 to +2", 'attemptCombine(70)')
dlg_menu("+2 to +3", 'attemptCombine(60)')
dlg_menu("+3 to +4", 'attemptCombine(50)')
dlg_menu("+4 to +5", 'attemptCombine(40)')
dlg_show()
end
function combine_with_special_cubes_menu()
dlg_title("Combine your skillcards")
dlg_text("Combine your skillcards in bulk!")
dlg_menu("+1 to +2", 'combine_with_special_cubes(1)')
dlg_menu("+2 to +3", 'combine_with_special_cubes(2)')
dlg_menu("+3 to +4", 'combine_with_special_cubes(3)')
dlg_menu("+4 to +5", 'combine_with_special_cubes(4)')
dlg_show()
end
function attemptCombine(rate)
local count, tableChoice
if rate == 70 then
count = table.getn(sellCards)
tableChoice = sellCards
elseif rate == 60 then
count = table.getn(sellCards2)
tableChoice = sellCards2
elseif rate == 50 then
count = table.getn(sellCards3)
tableChoice = sellCards3
elseif rate == 40 then
count = table.getn(sellCards4)
tableChoice = sellCards4
end
for i = 1, count do
combine(tableChoice[i], rate)
end
end
function combine(id, rate)
local handles = get_item_handle_list(id)
local handleCount = table.getn(handles)
local success = 0
local is_card = inTable(sellCards,id) or inTable(sellCards2, id) or inTable(sellCards3, id) or inTable(sellCards4, id)
if handleCount > 1 then
local remainder = handleCount % 2
local totalOperations = (handleCount - remainder) / 2
for i = 1, totalOperations * 2, 2 do
local rng = math.random(0, 100)
delete_item(handles[i])
delete_item(handles[i + 1])
if rng <= rate then
if rate == 70 then
insert_item((id*10) + 1)
success = success + 1
elseif rate == 60 then
insert_item(id + 1)
success = success + 1
elseif rate == 50 then
insert_item(id +1 )
success = success + 1
elseif rate == 40 then
insert_item(id + 1)
success = success + 1
end
end
end
end
return success
end