ConAn Edujawa
Member
- Joined
- Feb 23, 2015
- Messages
- 457
- Reaction score
- 17
Is there any way to make NPC remove money from the bank if the player doesn't have money in the backpack.?
0.3.7
0.3.7
I want that too, my bank comand its in on a MOD, same version of author:Just for reference, this doesn't require a source edit.
You need to edit your npc lib files wherever money is checked/removed.
Use your banker npc's lua file as a reference for how to check & remove money from the balance.
<talkaction words="!bank;/bank" event="script"><![CDATA[
domodlib('command-bank-config')
local config = {
transferDisabledVocations = transferDisabledVocations
}
local function validAmount(amount)
return (isNumber(amount) and amount > 0 and amount < 4294967296)
end
local function getAmount(amount, cid, f)
return (amount == 'all' and f(cid) or tonumber(amount))
end
local function getPlayerVocationByName(name)
local result = db.getResult("SELECT `vocation` FROM `players` WHERE `name` = " .. db.escapeString(name))
if(result:getID() == -1) then
return false
end
local value = result:getDataString("vocation")
result:free()
return value
end
function onSay(cid, words, param, channel)
if(param == '') then
doPlayerSendTextMessage(cid,19,
"Bank management manual.\n\n" ..
"!bank or /bank balance - show your account balance\n" ..
"!bank or /bank deposit 100 - deposit 100 gold\n" ..
"!bank or /bank withdraw 50 - withdraw 50 gold\n" ..
"!bank or /bank transfer 30 God - transfer 30 gold to player God\n\n" ..
"Tip: you can also use 'all' as amount.\n" ..
"!bank or /bank deposit all - deposit all gold you have\n" ..
"!bank or /bank withdraw all - withdraw all gold from your bank account"
)
return true
end
local t = string.explode(param, " ", 2)
local command = t[1]:lower()
if(command == 'balance') then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Your account balance is " .. getPlayerBalance(cid) .. " gold.")
elseif(command == 'deposit') then
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Amount is required.")
return true
end
local amount = getAmount(t[2], cid, getPlayerMoney)
if(validAmount(amount) and getPlayerMoney(cid) >= amount and doPlayerDepositMoney(cid, amount)) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,amount .. " gold has been deposited.")
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Not enough money to deposit.")
end
elseif(command == 'withdraw') then
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Amount is required.")
return true
end
local amount = getAmount(t[2], cid, getPlayerBalance)
if(validAmount(amount) and getPlayerBalance(cid) >= amount and doPlayerWithdrawMoney(cid, amount)) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,amount .. " gold has been withdrawn.")
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Not enough money to withdraw.")
end
elseif(command == 'transfer') then
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Amount is required.")
return true
end
if(not t[3]) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Player name to transfer is required.")
return true
end
local amount, target = tonumber(t[2]), t[3]
if(getPlayerGUID(cid) == getPlayerGUIDByName(target)) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"You cannot transfer money to yourself.")
elseif(isInArray(config.transferDisabledVocations, getPlayerVocation(cid))) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Your vocation cannot transfer money.")
elseif(not validAmount(amount) or getPlayerBalance(cid) < amount) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Not enough money to transfer.")
else
local targetVocation = getPlayerVocationByName(target)
if(not playerExists(target) or not targetVocation or isInArray(config.transferDisabledVocations, targetVocation) or not doPlayerTransferMoneyTo(cid, target, amount)) then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"This player does not exist on this world or have no vocation.")
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"You have transferred " .. amount .. " gold to \"" .. target .."\".")
end
end
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Invalid command usage. Use '!bank' to view manual.")
end
return true
end
]]></talkaction>
function doPlayerWithdrawMoney(cid, amount)
if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
return false
end
local balance = getPlayerBalance(cid)
if(amount > balance or not doPlayerAddMoney(cid, amount)) then
return false
end
doPlayerSetBalance(cid, balance - amount)
return true
end
function doPlayerDepositMoney(cid, amount)
if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
return false
end
if(not doPlayerRemoveMoney(cid, amount)) then
return false
end
doPlayerSetBalance(cid, getPlayerBalance(cid) + amount)
return true
end