As you can see, you start the interpolation from 0. Write down the current balance of money before you start the interpolation and start from there.
You can use e.g. a ticks to see if the amount of money has changed
local fromMoney, toMoney, visibleMoney = 0,0,0;
local moneyCheckTick,moneyAnimTick = getTickCount();
if (moneyCheckTick and not moneyAnimTick) then
if (getTickCount() - moneyCheckTick > 1000) then -- check every 1 s
local money = getPlayerMoney(localPlayer);
if (visibleMoney ~= money) then
moneyAnimTick = getTickCount();
fromMoney, toMoney = visibleMoney, money;
end
moneyCheckTick = getTickCount();
end
end
if (moneyAnimTick) then
local progress = (getTickCount() - moneyAnimTick) / 1000;
visibleMoney = interpolateBetween(fromMoney, 0, 0, toMoney, 0, 0, progress, 'Linear');
if (progress > 1) then
moneyAnimTick = nil;
end
end
-- dxDrawText for visibleMoney variable
Sorry for the broken indentation in the code, but the code editor on the forum is strange and I don't know why it happens.