V
verdehile95
Guest
Why is it that when I kill a boss, I get an item with random attributes, and when I use an item that gives a random weapon, this weapon has no attributes? How to make weapons received from the chest also have these attributes?

i try with this code but don't work


LUA:
-- ID skrzyni
local CHEST_ID = 29866
local weapons = {
29869, --
29870, --
29871, --
29872, --
29873, --
29874, --
29875, --
29876 --
}
-- Szanse na unikatowe cechy zdefiniowane w RARITY_CHANCE
local RARITY_CHANCE = {
{ id = ITEM_RARITY_COMMON, chance = 40 },
{ id = ITEM_RARITY_RARE, chance = 15 },
{ id = ITEM_RARITY_EPIC, chance = 10 },
{ id = ITEM_RARITY_LEGENDARY, chance = 2 },
{ id = ITEM_RARITY_BRUTAL, chance = 1 },
}
local function getRandomRarity()
local totalChance = 0
for _, rarity in ipairs(RARITY_CHANCE) do
totalChance = totalChance + rarity.chance
end
local roll = math.random(1, totalChance)
local accumulated = 0
for _, rarity in ipairs(RARITY_CHANCE) do
accumulated = accumulated + rarity.chance
if roll <= accumulated then
return rarity.id
end
end
return ITEM_RARITY_COMMON -- Domyślnie common, jeśli coś pójdzie nie tak
end
local function applyRarityAttributes(item, rarityId)
local modifiers = {
[ITEM_RARITY_COMMON] = { amount = 0, factor = 0 },
[ITEM_RARITY_RARE] = { amount = 2, factor = 20 },
[ITEM_RARITY_EPIC] = { amount = 4, factor = 30 },
[ITEM_RARITY_LEGENDARY] = { amount = 6, factor = 50 },
[ITEM_RARITY_BRUTAL] = { amount = 7, factor = 80 },
}
local attributes = {
{ id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_PHYSICALDAMAGE}, min = 2, max = 4, chance = 5 },
{ id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_ENERGYDAMAGE}, min = 2, max = 4, chance = 5 },
{ id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_FIREDAMAGE}, min = 2, max = 4, chance = 5 },
{ id = TOOLTIP_ATTRIBUTE_INCREMENTS, type = {COMBAT_ENERGYDAMAGE, COMBAT_EARTHDAMAGE, COMBAT_FIREDAMAGE, COMBAT_DEATHDAMAGE, COMBAT_HOLYDAMAGE, COMBAT_ICEDAMAGE}, min = 1, max = 2, chance = 1 },
{ id = TOOLTIP_ATTRIBUTE_CRITICALHIT_CHANCE, min = 1, max = 2, chance = 1 },
}
for _, attr in ipairs(attributes) do
if math.random(1, 100) <= attr.chance then
local value = math.random(attr.min, attr.max)
item:setAttribute(attr.id, value)
end
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- Sprawdzenie, czy przedmiot używany to skrzynia
if item.itemid ~= CHEST_ID then
return false
end
-- Losowanie broni z listy
local randomIndex = math.random(1, #weapons)
local weaponId = weapons[randomIndex]
-- Losowanie rzadkości
local rarityId = getRandomRarity()
-- Tworzenie losowej broni w plecaku gracza
local newItem = player:addItem(weaponId, 1)
if newItem then
-- Nadanie unikatowych atrybutów na podstawie rzadkości
applyRarityAttributes(newItem, rarityId)
-- Usunięcie skrzyni po użyciu
player:removeItem(CHEST_ID, 1)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a unique weapon!")
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "Your inventory is full. Clear some space and try again.")
end
return true
end