[Relese] Decompose Items Script

01/28/2024 05:23 yosiemelo#1
Hello dear Players and Developers,

I often see players on servers asking for an automatic decompose feature for their equipment, and often they don't receive it. So, I decided to meet you halfway and wrote such a script. I believe it is a good base for learning. I recommend delving into it and either editing this script or writing your own new one. I hope it helps someone! :D



Code:
function get_module_name()
	return "YSM_Decompose.lua"
end

-----------Script written by YoSiem for educational purposes.------------------------------------------
-----------Please do not remove the credits; respect the author's contribution.-------------------------
-----------This script is shared for learning and is a courtesy of YoSiem.------------------------------


-- Insert item IDs here
local itemIDs_table = {210510101, 210510102, 210510103, 210510104}  -- There are actually over 11,000 items; only 4 are included here for readability
local decompose_data = {  -- Data from Epic 9.6
    [2] = { --Rank
        [0] = {min = 1, max = 1},   --Grade | minimal result count | maximal result count
        [1] = {min = 1, max = 2},
        [2] = {min = 2, max = 4},
        [3] = {min = 4, max = 7}
    },
    [3] = {
        [0] = {min = 2, max = 2},
        [1] = {min = 2, max = 3},
        [2] = {min = 3, max = 5},
        [3] = {min = 4, max = 8}
    },
    [4] = {
        [0] = {min = 2, max = 4},
        [1] = {min = 3, max = 5},
        [2] = {min = 4, max = 7},
        [3] = {min = 5, max = 10}
    },
    [5] = {
        [0] = {min = 4, max = 7},
        [1] = {min = 4, max = 8},
        [2] = {min = 5, max = 10},
        [3] = {min = 7, max = 13}
    },
    [6] = {
        [0] = {min = 6, max = 11},
        [1] = {min = 6, max = 12},
        [2] = {min = 7, max = 14},
        [3] = {min = 9, max = 17}
    },
    [7] = {
        [0] = {min = 8, max = 15},
        [1] = {min = 8, max = 16},
        [2] = {min = 9, max = 18},
        [3] = {min = 11, max = 21},
        [4] = {min = 13, max = 25},
        [5] = {min = 15, max = 30},
        [6] = {min = 18, max = 36},
        [7] = {min = 22, max = 43},
        [8] = {min = 22, max = 43},
        [9] = {min = 22, max = 43}
    }
}

local function get_min_max(item_rank, item_grade)
    if decompose_data[item_rank] and decompose_data[item_rank][item_grade] then
        local data = decompose_data[item_rank][item_grade]
        return data.min, data.max
    else
        return nil, nil
    end
end

local function getRandomResultCount(item_rank, item_grade)
    local min, max = get_min_max(item_rank, item_grade)
    if min and max then
        return math.random(min, max)
    end
	cprint("Invalid ItemRank: "..item_rank.. " or item_grade: "..item_grade)
    return nil
end


local function decomposeItem(itemHandle, itemID)
    delete_item(itemHandle, 1)
    av('gold', -5100)
    local item_grade = get_item_grade(itemHandle)
    local item_rank = get_item_rank(itemHandle)
    for _ = 1, getRandomResultCount(item_rank, item_grade) do
        insert_item(-3000942, 1)
    end
end

local function is_item_worn(table, item_handle)
    for _, handle in pairs(table) do
        if handle == item_handle then
            return true
        end
    end
    
    return false
end

function DecomposeDuraEquipment()
    local itemHandle_table
    local enchant
    local count
    local wear_item = {
        [0] = get_wear_item_handle(0),      --WEAR_WEAPON		              
        [1] = get_wear_item_handle(1),      --WEAR_SHIELD		
        [2] = get_wear_item_handle(2),      --WEAR_ARMOR		
        [3] = get_wear_item_handle(3),      --WEAR_HELM		
        [4] = get_wear_item_handle(4),      --WEAR_GLOVE		
        [5] = get_wear_item_handle(5),      --WEAR_BOOTS		
        [6] = get_wear_item_handle(6),      --WEAR_BELT		
        [8] = get_wear_item_handle(8),      --WEAR_ARMULET			
        [9] = get_wear_item_handle(9),      --WEAR_RING		
        [10] = get_wear_item_handle(10),    --WEAR_SECOND_RING
        [11] = get_wear_item_handle(11),    --WEAR_EAR		
        [26] = get_wear_item_handle(26)     --WEAR_SECOND_EAR
    }
	
	
    for i,itemID in ipairs(itemIDs_table) do
        count = 0
        itemHandle_table = get_item_handle_list(itemID) or {}

        for _, itemHandle in ipairs(itemHandle_table) do

            enchant = get_item_enhance(itemHandle)
            if enchant > 0 or is_item_worn(wear_item, itemHandle) or gv('gold') < 5100 then
                --dont destroy
            else
			    decomposeItem(itemHandle, itemID)
                count = count + 1
			end
        end
		if count > 0 then
			message(sconv("You have decomposed #@count@# pieces of #@name@#", "#@name@#","@"..get_item_name_id(itemID), "#@count@#", count))
		end

    end

end
Download Link below :P

01/29/2024 06:27 doctorxanny#2
Bitte geben Sie Ihren gesamten Dateicode kostenlos an. Es wird sowieso niemand kaufen.