Hi i have this script, when player have calculated money it works greate, but if he have much more, than it 'steal' double count money...
Lua:
local lever_id = 1945 -- id of lever before pulled
local pulled_id = 1946 -- id of lever after pulled
local shop = {
[2066] = {id = 7589, cost = 10000, count = 100},
[2067] = {id = 7588, cost = 10000, count = 100},
[2068] = {id = 7591, cost = 15000, count = 100},
[2069] = {id = 7590, cost = 15000, count = 100},
[2070] = {id = 26029, cost = 20000, count = 100},
[2071] = {id = 8473, cost = 15000, count = 100},
[2075] = {id = 26031, cost = 25000, count = 100},
[2072] = {id = 8472, cost = 15000, count = 100},
[2073] = {id = 26030, cost = 20000, count = 100},
[2074] = {id = 26654, cost = 1000000, count = 5},
[2075] = {id = 26031, cost = 30000, count = 100},
[2076] = {id = 38993, cost = 4000, count = 1},
[2077] = {id = 26184, cost = 4000, count = 1},
[2078] = {id = 26183, cost = 4000, count = 1},
[2079] = {id = 26182, cost = 4000, count = 1},
[2080] = {id = 18402, cost = 4000, count = 750},
[2081] = {id = 35150, cost = 4000, count = 1},
[2082] = {id = 7888, cost = 4000, count = 200},
[2083] = {id = 7890, cost = 4000, count = 200},
[2084] = {id = 2168, cost = 4000, count = 1},
[2085] = {id = 26187, cost = 4000, count = 1},
[2086] = {id = 26185, cost = 4000, count = 1},
[2087] = {id = 26189, cost = 4000, count = 1},
[2088] = {id = 37470, cost = 4000, count = 1},
[2089] = {id = 2167, cost = 4000, count = 1},
[2090] = {id = 18528, cost = 4000, count = 1},
}
local leverShopTransformItems = Action()
function leverShopTransformItems.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local ShopItem = shop[item.uid]
local itemType = ItemType(ShopItem.id)
if item.itemid ~= pulled_id then
if ShopItem then
if(not player:removeMoney(ShopItem.cost)) then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You need '..ShopItem.cost..' to buy '.. itemType:getName() .. '.')
return false
end
item:transform(pulled_id)
player:addItem(ShopItem.id, ShopItem.count)
player:removeMoney(ShopItem.cost)
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought a '.. itemType:getName() .. '.')
player:getPosition():sendMagicEffect(13)
end
else
item:transform(lever_id)
return true
end
end
for index, value in pairs(shop) do
leverShopTransformItems:uid(index)
end
leverShopTransformItems:register()