Kownikuzyt
Member
- Joined
- Feb 11, 2020
- Messages
- 170
- Solutions
- 1
- Reaction score
- 8
Hello, I would like this script to detect and change money. It is possible?
I am using the TFS 1.1 engine.
I am using the TFS 1.1 engine.
XML:
<action itemid="11773" script="goldconverter.lua" />
Lua:
local config = {
[ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
[ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
[ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local coin = config[target.itemid]
if not coin then
return false
end
local charges = item:getCharges()
if coin.changeTo and target.type == 100 then
target:remove()
player:addItem(coin.changeTo, 1)
item:transform(item:getId(), charges -1)
elseif coin.changeBack then
target:transform(target.itemid, target.type - 1)
player:addItem(coin.changeBack, 100)
item:transform(item:getId(), charges -1)
else
return false
end
if charges == 0 then
item:remove()
end
return true
end