script improvement help - solved
Posted: Fri May 24, 2013 2:20 pm
Hello folks,
If somebody could help me - what I need is to improve one script (or rewrite it). Problem is with stackable objects (money). What I need is, when stack of money is inserted (like for example 20 stacked golds), I need mouth take just defined number of it (lets say 5), so the player do not have insert coins one by one. Curently I am using following script, which counts how many objects is inserted, but if you insert more then I need, it "swallows" whole stack. So perhaps some limitations or something like that ?
function insertfivesilver() -- when 5 silver golds is inserted, it activate counter_1, which will do something
for i in mouth_for_coins_1:containedItems() do
if i.name == "gor_coin_silver" then
local x = i:getStackSize()
local y = 0
while y < x do
counter_1:decrement()
y = y + 1
end
i:destroy()
playSound("consume_food")
end
end
end
thanks for any advice.
EDIT: thanks to Marco Mastropaolo, script solved.
In case somebody is interested here it is
If somebody could help me - what I need is to improve one script (or rewrite it). Problem is with stackable objects (money). What I need is, when stack of money is inserted (like for example 20 stacked golds), I need mouth take just defined number of it (lets say 5), so the player do not have insert coins one by one. Curently I am using following script, which counts how many objects is inserted, but if you insert more then I need, it "swallows" whole stack. So perhaps some limitations or something like that ?
function insertfivesilver() -- when 5 silver golds is inserted, it activate counter_1, which will do something
for i in mouth_for_coins_1:containedItems() do
if i.name == "gor_coin_silver" then
local x = i:getStackSize()
local y = 0
while y < x do
counter_1:decrement()
y = y + 1
end
i:destroy()
playSound("consume_food")
end
end
end
thanks for any advice.
EDIT: thanks to Marco Mastropaolo, script solved.
In case somebody is interested here it is
Code: Select all
g_SilverToInsert = 5;
function insertSilver()
for i in mouth_for_coins_1:containedItems() do
if i.name == "gor_coin_silver" then
local amount = i:getStackSize()
if (amount > g_SilverToInsert) then
local change = amount - g_SilverToInsert;
g_SilverToInsert = 0;
i:setStackSize(change);
else
g_SilverToInsert = g_SilverToInsert - amount;
i:destroy();
end
playSound("consume_food")
end
end
end