Skip to content

Commit

Permalink
more fixes on: #285
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Jul 1, 2017
1 parent 73d39ef commit 7a8c4de
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
39 changes: 39 additions & 0 deletions path_10_9/data/npc/lib/npcsystem/customModules.lua
Expand Up @@ -190,3 +190,42 @@ function VoiceModule:callbackOnThink()
end
return true
end

function Player.removeMoneyNpc(self, amount)
amount = tonumber(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
30 changes: 15 additions & 15 deletions path_10_9/data/npc/lib/npcsystem/modules.lua
Expand Up @@ -80,7 +80,7 @@ if Modules == nil then
npcHandler:say("You are already promoted!", cid)
elseif player:getLevel() < parameters.level then
npcHandler:say("I am sorry, but I can only promote you once you have reached level " .. parameters.level .. ".", cid)
elseif not player:removeMoney(parameters.cost) then
elseif not player:removeMoneyNpc(parameters.cost) then
npcHandler:say("You do not have enough money!", cid)
else
npcHandler:say(parameters.text, cid)
Expand Down Expand Up @@ -110,7 +110,7 @@ if Modules == nil then
npcHandler:say("You already know this spell.", cid)
elseif not player:canLearnSpell(parameters.spellName) then
npcHandler:say("You cannot learn this spell.", cid)
elseif not player:removeMoney(parameters.price) then
elseif not player:removeMoneyNpc(parameters.price) then
npcHandler:say("You do not have enough money, this spell costs " .. parameters.price .. " gold.", cid)
else
npcHandler:say("You have learned " .. parameters.spellName .. ".", cid)
Expand All @@ -137,7 +137,7 @@ if Modules == nil then
if player:isPremium() or not parameters.premium then
if player:hasBlessing(parameters.bless) then
npcHandler:say("Gods have already blessed you with this blessing!", cid)
elseif not player:removeMoney(parameters.cost) then
elseif not player:removeMoneyNpc(parameters.cost) then
npcHandler:say("You don't have enough money for blessing.", cid)
else
player:addBlessing(parameters.bless)
Expand Down Expand Up @@ -166,7 +166,7 @@ if Modules == nil then
npcHandler:say("First get rid of those blood stains! You are not going to ruin my vehicle!", cid)
elseif parameters.level and player:getLevel() < parameters.level then
npcHandler:say("You must reach level " .. parameters.level .. " before I can let you go there.", cid)
elseif not player:removeMoney(parameters.cost) then
elseif not player:removeMoneyNpc(parameters.cost) then
npcHandler:say("You don't have enough money.", cid)
else
npcHandler:say(parameters.msg or "Set the sails!", cid)
Expand Down Expand Up @@ -442,7 +442,7 @@ if Modules == nil then

local player = Player(cid)
if player:isPremium() or not shop_premium[cid] then
if not player:removeMoney(cost) then
if not player:removeMoneyNpc(cost) then
npcHandler:say("You do not have enough money!", cid)
elseif player:isPzLocked(cid) then
npcHandler:say("Get out of there with this blood.", cid)
Expand Down Expand Up @@ -489,7 +489,7 @@ if Modules == nil then

local player = Player(cid)
if player:isPremium() or not parameters.premium then
if player:removeMoney(cost) then
if player:removeMoneyNpc(cost) then
local position = player:getPosition()
player:teleportTo(destination)

Expand Down Expand Up @@ -791,13 +791,13 @@ if Modules == nil then
if names ~= nil and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE then
for i, name in pairs(names) do
local parameters = {
itemid = itemid,
cost = cost,
eventType = SHOPMODULE_BUY_ITEM,
module = self,
realName = realName or ItemType(itemid):getName(),
subType = itemSubType or 1
}
itemid = itemid,
cost = cost,
eventType = SHOPMODULE_BUY_ITEM,
module = self,
realName = realName or ItemType(itemid):getName(),
subType = itemSubType or 1
}

keywords = {}
keywords[#keywords + 1] = "buy"
Expand Down Expand Up @@ -936,7 +936,7 @@ if Modules == nil then
[TAG_ITEMNAME] = shopItem.name
}

if getPlayerMoney(cid) < totalCost then
if getPlayerMoney(cid) + player:getBankBalance() < totalCost then
local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
msg = self.npcHandler:parseMessage(msg, parseInfo)
doPlayerSendCancel(cid, msg)
Expand Down Expand Up @@ -1074,7 +1074,7 @@ if Modules == nil then
end
elseif shop_eventtype[cid] == SHOPMODULE_BUY_ITEM then
local cost = shop_cost[cid] * shop_amount[cid]
if getPlayerMoney(cid) < cost then
if getPlayerMoney(cid) + player:getBankBalance() < cost then
local msg = module.npcHandler:getMessage(MESSAGE_MISSINGMONEY)
msg = module.npcHandler:parseMessage(msg, parseInfo)
module.npcHandler:say(msg, cid)
Expand Down

0 comments on commit 7a8c4de

Please sign in to comment.