-
Notifications
You must be signed in to change notification settings - Fork 9
/
command-bank.xml
106 lines (96 loc) · 4.36 KB
/
command-bank.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?xml version="1.0" encoding="UTF-8"?>
<mod name="command-bank" version="1.1" author="slawkens" contact="[email protected]" enabled="yes">
<config name="command-bank-config"><![CDATA[
transferDisabledVocations = {0} -- disable non vocation characters
]]></config>
<talkaction words="!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
doPlayerPopupFYI(cid,
"Bank management manual.\n\n" ..
"!bank balance - show your account balance\n" ..
"!bank deposit 100 - deposit 100 gold\n" ..
"!bank withdraw 50 - withdraw 50 gold\n" ..
"!bank transfer 30 God - transfer 30 gold to player God\n\n" ..
"Tip: you can also use 'all' as amount.\n" ..
"!bank deposit all - deposit all gold you have\n" ..
"!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_STATUS_CONSOLE_BLUE, "Your account balance is " .. getPlayerBalance(cid) .. " gold.")
elseif(command == 'deposit') then
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "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_STATUS_CONSOLE_BLUE, amount .. " gold has been deposited.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough money to deposit.")
end
elseif(command == 'withdraw') then
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "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_STATUS_CONSOLE_BLUE, amount .. " gold has been withdrawn.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough money to withdraw.")
end
elseif(command == 'transfer') then
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Amount is required.")
return true
end
if(not t[3]) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "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_STATUS_CONSOLE_BLUE, "You cannot transfer money to yourself.")
elseif(isInArray(config.transferDisabledVocations, getPlayerVocation(cid))) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation cannot transfer money.")
elseif(not validAmount(amount) or getPlayerBalance(cid) < amount) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "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_STATUS_CONSOLE_BLUE, "This player does not exist on this world or have no vocation.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have transferred " .. amount .. " gold to \"" .. target .."\".")
end
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid command usage. Use '!bank' to view manual.")
end
return true
end
]]></talkaction>
</mod>