• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

NPC is not subtracting money when buying potions

Sleet

Member
Joined
Sep 3, 2016
Messages
107
Solutions
2
Reaction score
7
I don't know how to explain this in the most detailed form, but let's try it.
In my server if you have an 'x' ammount of money, you can buy infinite potions as long as they cost lower than or exactly 'x'.

An example of that is given when somebody is going to buy a potion and he has 200gp. When he buys the potion, he stays with 200gp even though in the .xml file of the npc it is saying that the potion costs 190gp.

It only happens with some items, like potions or sudden death runes, the others are fine.

Does anyone know how to fix it?
 
Solution
Let's hope that's the case.

i might use the bank scripts for my TFS too. so it's a win-win for both of us :D

As I predicted, this code would force you to have money on the player to buy something.
It works, but the bank money becomes useless, you will have to withdraw money before buying anything.
However, thanks to you, I found a great solution! I replaced my whole npc lib folder for this one: lib.rar
I seem to have found the solution. However, I will update this post in order to know exactly what was the file that was causing this problem, thank you very much Karain!

Update:

Here we go guys, thanks to Karain I have solved this problem.

All you have to do is add the following code in the end of your customModules.lua...
Thank you for your answer.
Unfortunately my problem will now be to fix every single npc trader that exists on a global map.
I don't want to be rude but, are you positive that the XML files can't work?

Just to make sure, please post your modules.lua from your npc/lib/npcsystem/ folder. that file handles all the sales and npc parameters
 
Just to make sure, please post your modules.lua from your npc/lib/npcsystem/ folder. that file handles all the sales and npc parameters

Here you go!

http://www.mediafire.com/file/vrqy3vz3nhwpa1m/modules.lua
(There is a server error on OTLand, it is not allowing me to upload the file)

Edit:

I see that from a different modules.lua file that the parameters player:removeMoney (on my file) are replaced by player:removeMoneyNpc (on the other file), does that make any difference?
 
Last edited:
try changing

at line 1050:
Code:
if player:getMoney() + player:getBankBalance() < totalCost then
to
Code:
if player:getMoney() < totalCost then

and at line 1189:
Code:
if Player(cid):getMoney() + player:getBankBalance() < cost then
to
Code:
if Player(cid):getMoney() < cost then

these are the only 2 bank related lines...
 
try changing

at line 1050:
Code:
if player:getMoney() + player:getBankBalance() < totalCost then
to
Code:
if player:getMoney() < totalCost then

and at line 1189:
Code:
if Player(cid):getMoney() + player:getBankBalance() < cost then
to
Code:
if Player(cid):getMoney() < cost then

these are the only 2 bank related lines...

I see it, I will try to, but I believe that this is going to disable the bank money.
 
Let's hope that's the case.

i might use the bank scripts for my TFS too. so it's a win-win for both of us :D

As I predicted, this code would force you to have money on the player to buy something.
It works, but the bank money becomes useless, you will have to withdraw money before buying anything.
However, thanks to you, I found a great solution! I replaced my whole npc lib folder for this one: lib.rar
I seem to have found the solution. However, I will update this post in order to know exactly what was the file that was causing this problem, thank you very much Karain!

Update:

Here we go guys, thanks to Karain I have solved this problem.

All you have to do is add the following code in the end of your customModules.lua file in data/npc/lib/npcsystem

Lua:
function Player.removeMoneyNpc(self, amount)
                local moneyCount = self:getMoney()
                local bankCount = self:getBankBalance()
                if amount > moneyCount + bankCount then
                    return false
                end
                self:removeMoney(math.min(amount, moneyCount))
                if amount > moneyCount then
                    self:setBankBalance(bankCount - math.max(amount - moneyCount, 0))
                    if moneyCount == 0 then
                        self:sendTextMessage(MESSAGE_INFO_DESCR, ("Paid %d gold from bank account. Your account balance is now %d gold."):format(amount, self:getBankBalance()))
                    else
                        self:sendTextMessage(MESSAGE_INFO_DESCR, ("Paid %d from inventory and %d gold from bank account. Your account balance is now %d gold."):format(moneyCount, amount - moneyCount, self:getBankBalance()))
                    end
                end
                return true
            end
            local function getPlayerMoney(cid)
                local player = Player(cid)
                if player then
                    return player:getMoney() + player:getBankBalance()
                end
                return 0
            end
            local function doPlayerRemoveMoney(cid, amount)
                local player = Player(cid)
                if player then
                    return player:removeMoneyNpc(amount)
                end
                return false
            end

And also, you will have to replace every "player:removeMoney" to "player:removeMoneyNpc" on your modules.lua file located in data/npc/lib/npcsystem.

Or you can simply download and replace the files attached to this post :)
 

Attachments

Last edited:
Solution
Back
Top