OTcreator
Active Member
- Joined
- Feb 14, 2022
- Messages
- 426
- Solutions
- 1
- Reaction score
- 44
Hi!
What to change to buy potions for more backpacks and not just the main one, while keeping it so they don't fall to the ground when there's no room in all the slots?
What to change to buy potions for more backpacks and not just the main one, while keeping it so they don't fall to the ground when there's no room in all the slots?
Lua:
local potions = {
[5001] = {id = 7618, charges = 100, value = 4500}, -- HP
[5002] = {id = 7588, charges = 100, value = 10000}, -- SHP
[5003] = {id = 7591, charges = 100, value = 19000}, -- GHP
[5004] = {id = 7620, charges = 100, value = 5000}, -- MP
[5005] = {id = 7589, charges = 100, value = 8000}, -- SMP
[5006] = {id = 7590, charges = 100, value = 12000}, -- GMP
[5007] = {id = 8472, charges = 100, value = 19000}, -- SP
[5008] = {id = 8473, charges = 100, value = 31000}, -- UHP
[5009] = {id = 2273, charges = 100, value = 5000}, -- UH
[5010] = {id = 2268, charges = 100, value = 10800} -- SD
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local potion = potions[item.uid]
if not potion then
return false
end
local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
if not backpack or backpack:getEmptySlots(false) < 1 then
player:sendCancelMessage("Your main backpack is full. Transfer your belongings to another container.")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
return true
end
local potionId = ItemType(potion.id)
local itemWeight = potionId:getWeight() * potion.charges
if player:getFreeCapacity() >= itemWeight then
if not player:removeTotalMoney(potion.value) then
player:sendCancelMessage("You don't have ".. potion.value .." gold coins to buy ".. potion.charges .."x ".. potionId:getName() ..".")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
else
player:sendCancelMessage("You are bought ".. potion.charges .."x ".. potionId:getName() .." for ".. potion.value .." gold coins.")
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
player:addItem(potion.id, potion.charges)
end
else
player:sendCancelMessage("Sorry, you don't have capacity.")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
item:transform(item.itemid == 1945 and 1946 or 1945)
return true
end