introduce gold converting ring

This commit is contained in:
ErikasKontenis
2020-05-07 23:23:40 +03:00
parent 5e979da462
commit 871bdac620
13 changed files with 95 additions and 21 deletions

View File

@@ -233,6 +233,9 @@
<action itemid="4863" script="misc/butterfly_conservation_kit.lua" />
<action itemid="5467" script="misc/fire_bug.lua" />
<action itemid="5938" script="misc/ceirons_waterskin.lua" />
<action itemid="3031" script="misc/changegold.lua" />
<action itemid="3035" script="misc/changegold.lua" />
<action itemid="3043" script="misc/changegold.lua" />
<!-- Chests -->
<action itemid="2479" script="misc/chests.lua" />

View File

@@ -0,0 +1,35 @@
local config = {
[3031] = {changeTo = 3035},
[3035] = {changeBack = 3031, changeTo = 3043},
[3043] = {changeBack = 3035}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local ring = player:getSlotItem(CONST_SLOT_RING)
if ring == nil or ring:getId() ~= 3007 then
return false
end
local ringCharges = ring:getAttribute(ITEM_ATTRIBUTE_CHARGES)
local coin = config[item:getId()]
if coin.changeTo and item.type == 100 then
item:remove()
player:addItem(coin.changeTo, 1)
if ringCharges > 1 then
ring:setAttribute(ITEM_ATTRIBUTE_CHARGES,(ringCharges-1))
else
ring:remove(1)
end
elseif coin.changeBack then
item:remove(1)
player:addItem(coin.changeBack, 100)
if ringCharges > 1 then
ring:setAttribute(ITEM_ATTRIBUTE_CHARGES,(ringCharges-1))
else
ring:remove(1)
end
else
return false
end
return true
end