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.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376. | #include <amxmodx>
#include <amxmisc>
#include <zombieplague>
#define USING_SQL
#if defined USING_SQL
#include <sqlx>
#else
#include <nvault>
#endif
stock const ZP_BANK_FMT[] = "^x04[ZP-BANK]^x01 %L"
new g_iAmmoPacks[33]
new g_iSessionMovement[33]
new g_szAuth[33][36]
new cvAnnounceTime
new cvBankMax
#if defined USING_SQL
new g_szSQLTable[64], Handle:g_hSQLTuple, g_szQuery[128]
LoadClient(id, szAuth[])
{
formatex(g_szQuery, charsmax(g_szQuery),
"SELECT amount FROM `%s` WHERE auth='%s'",
g_szSQLTable, szAuth)
new cData[37]
cData[0] = id
copy(cData[1], charsmax(cData)-1, szAuth)
SQL_ThreadQuery(g_hSQLTuple, "LoadClient_QueryHandler", g_szQuery, cData, strlen(cData[1]))
}
public LoadClient_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
{
if(iFailState != TQUERY_SUCCESS)
{
log_amx("LoadClient(): SQL Error #%d - %s", iErrnum, szError)
return
}
new id = cData[0]
static szAuth[36]
copy(szAuth, charsmax(szAuth), cData[1])
new iAmmoPacks = 0
if(SQL_NumResults(hQuery))
iAmmoPacks = SQL_ReadResult(hQuery, 0)
//SQL_QueryAndIgnore("INSERT INTO `%s` SET auth='%s'", g_szSQLTable, szAuth)
g_iAmmoPacks[id] = iAmmoPacks
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_LOAD", iAmmoPacks, szAuth)
}
SaveClient(id, szAuth[])
{
new iDifference = g_iSessionMovement[id]
formatex(g_szQuery, charsmax(g_szQuery),
"INSERT INTO `%s` SET auth='%s', amount=%d ON DUPLICATE KEY UPDATE amount=amount+(%d)",
g_szSQLTable, szAuth, iDifference, iDifference)
SQL_ThreadQuery(g_hSQLTuple, "SaveClient_QueryHandler", g_szQuery)
}
public SaveClient_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, iData[], iSize, Float:fQueueTime)
{
if(iFailState != TQUERY_SUCCESS)
log_amx("SaveClient(): SQL Error #%d - %s", iErrnum, szError)
}
#else
new g_hVault
LoadClient(id, szAuth[])
{
static szValue[32], iTimestamp
new iValue = 0
if(nvault_lookup(g_hVault, szAuth, szValue, charsmax(szValue), iTimestamp) && is_str_num(szValue))
iValue = (g_iAmmoPacks[id] = str_to_num(szValue))
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_LOAD", iValue, szAuth)
}
SaveClient(id, szAuth[])
{
static szValue[32]
num_to_str(g_iAmmoPacks[id] + g_iSessionMovement[id], szValue, charsmax(szValue))
nvault_set(g_hVault, szAuth, szValue)
}
#endif
public plugin_init()
{
register_plugin("[ZP] Ammo Bank", "1.0", "danielkza")
register_clcmd("say", "Command_Say")
register_dictionary("zp_bank.txt")
cvAnnounceTime = register_cvar("zp_bank_announce_time", "180")
cvBankMax = register_cvar("zp_bank_max", "2000000")
Task_Announce()
#if defined USING_SQL
new configsDir[64]
get_configsdir(configsDir, 63)
// Declare standard SQL cvars so we don't depend on admin.amxx
register_cvar("amx_sql_host", "127.0.0.1")
register_cvar("amx_sql_user", "root")
register_cvar("amx_sql_pass", "")
register_cvar("amx_sql_db", "amx")
register_cvar("amx_sql_type", "mysql")
new cvTable = register_cvar("zp_bank_table", "zp_bank")
// Execute SQL configs. You must put zp_bank_table in there
server_cmd("exec %s/sql.cfg", configsDir)
server_exec()
get_pcvar_string(cvTable, g_szSQLTable, charsmax(g_szSQLTable))
g_hSQLTuple = SQL_MakeStdTuple()
new iError, szError[256]
new Handle:hSQLConnection = SQL_Connect(g_hSQLTuple, iError, szError, charsmax(szError))
if(hSQLConnection != Empty_Handle)
{
SQL_QueryAndIgnore(hSQLConnection,
"CREATE TABLE IF NOT EXISTS `%s` (\
auth VARCHAR(36) NOT NULL PRIMARY KEY, \
amount INT(10) UNSIGNED NOT NULL DEFAULT 0 \
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
g_szSQLTable )
SQL_FreeHandle(hSQLConnection)
}
else
log_amx("plugin_init(): SQL Error #%d - %s", iError, szError)
#else
g_hVault = nvault_open("zp_bank")
if(g_hVault == INVALID_HANDLE)
set_fail_state("Can't create/load vault 'zp_bank'")
#endif
}
public plugin_end()
{
// Client's should have already been saved by now (client_disconnect is called before plugin_end).
// But it costs nothing to be sure.
new iPlayers[32], iNum
get_players(iPlayers, iNum)
new iPlayer
for(new i=0; i < iNum;i++)
{
iPlayer = iPlayers[i]
SaveClient(iPlayer, g_szAuth[iPlayer])
}
#if defined USING_SQL
SQL_FreeHandle(g_hSQLTuple)
#else
nvault_close(g_hVault)
#endif
}
public client_putinserver(id)
{
static szAuth[36]
get_user_authid(id, szAuth, charsmax(szAuth))
copy(g_szAuth[id], charsmax(g_szAuth[]), szAuth)
LoadClient(id, szAuth)
}
public client_disconnect(id)
{
SaveClient(id, g_szAuth[id])
g_szAuth[id][0] = 0
g_iAmmoPacks[id] = 0
g_iSessionMovement[id] = 0
}
new msgSayText = -1
stock bool:SayText(const receiver, sender, const msg[], any:...)
{
if(msgSayText == -1)
msgSayText = get_user_msgid("SayText")
if(msgSayText)
{
if(!sender)
sender = receiver
static buffer[512]
vformat(buffer,charsmax(buffer),msg,4)
if(receiver)
message_begin(MSG_ONE_UNRELIABLE,msgSayText,_,receiver)
else
message_begin(MSG_BROADCAST,msgSayText)
write_byte(sender)
write_string(buffer)
message_end()
return true
}
return false
}
public Task_Announce()
{
static iPlayers[32], iNum, iPlayer
get_players(iPlayers, iNum)
for(new i=0; i < iNum;i++)
{
iPlayer = iPlayers[i]
//SayText(iPlayer, iPlayer, ZP_BANK_FMT, LANG_PLAYER, "ZP_BANK_ANNOUNCE")
print_chatColor(iPlayer, "\g[ZP-BANK]\n Wpisz: \t/wplac <suma>\n by zlozyc depozyt, \t/wybierz <suma>\n by wybrac AP, \t/bank\n by sprawdzic stan rachunku.")
}
set_task(get_pcvar_float(cvAnnounceTime), "Task_Announce")
}
enum
{
CMD_DEPOSIT = 1,
CMD_WITHDRAW,
CMD_INFO,
CMD_HELP
}
public Command_Say(id)
{
static szArgs[32]
read_args(szArgs, charsmax(szArgs))
remove_quotes(szArgs)
static szArg1[32], szArg2[32]
parse(szArgs, szArg1, charsmax(szArg1), szArg2, charsmax(szArg2))
new iCommand = 0
if(equali(szArg1, "/depozyt"))
iCommand = CMD_DEPOSIT
else if(equali(szArg1, "/wplac"))
iCommand = CMD_DEPOSIT
else if(equali(szArg1, "/wybierz"))
iCommand = CMD_WITHDRAW
else if(equali(szArg1, "/wyplac"))
iCommand = CMD_WITHDRAW
else if(equali(szArg1, "/bank"))
iCommand = CMD_INFO
else if(equali(szArg1, "/bankhelp"))
iCommand = CMD_HELP
if(iCommand)
{
if(iCommand == CMD_INFO)
Command_Info(id)
else if(iCommand == CMD_HELP)
Command_Help(id)
else
{
new iValue = str_to_num(szArg2)
if(iValue <= 0)
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_INVALID_AMOUNT")
else if(iCommand == CMD_DEPOSIT)
Command_Deposit(id, iValue)
else
Command_Withdraw(id, iValue)
}
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
Command_Info(id)
{
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_LOAD", g_iAmmoPacks[id] + g_iSessionMovement[id], g_szAuth[id])
}
Command_Help(id)
{
client_cmd(id, "say Bank umozliwia bezpieczne przechowywanie ammopackow na koncie.")
client_cmd(id, "say /bank - sprawdza rachunek; /wybierz <wartosc> - wybiera z rachunku; /depozyt <wartosc> - wplaca^n/transfer <wartosc> <#userid/nick/steamid> - przelew")
}
Command_Deposit(id, iDeposit)
{
new iCurrentAmount = zp_get_user_ammo_packs(id)
if(!iCurrentAmount)
{
SayText(id, id, ZP_BANK_FMT, "ZP_BANK_NO_AMMO")
return
}
if(iDeposit > iCurrentAmount)
iDeposit = iCurrentAmount
new iCurrent = g_iAmmoPacks[id] + g_iSessionMovement[id]
new iSum = iCurrent + iDeposit
new iBankMax = get_pcvar_num(cvBankMax)
if(iBankMax && iSum > iBankMax)
{
iDeposit = iBankMax - iCurrent
iSum = iBankMax
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_MAX", iBankMax)
}
if(iDeposit)
{
g_iSessionMovement[id] += iDeposit
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_DEPOSIT", iDeposit, iSum) //
zp_set_user_ammo_packs(id, iCurrentAmount - iDeposit)
}
}
Command_Withdraw(id, iWithdraw)
{
new iDeposited = g_iAmmoPacks[id] + g_iSessionMovement[id]
if(!iDeposited)
{
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_EMPTY")
return
}
if(iWithdraw > iDeposited)
iWithdraw = iDeposited
g_iSessionMovement[id] -= iWithdraw
SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_WITHDRAW", iWithdraw, iDeposited - iWithdraw)
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + iWithdraw)
}
stock print_chatColor(const id,const input[], any:...)
{
new msg[191], players[32], count = 1;
vformat(msg,190,input,3);
replace_all(msg,190,"\g","^4");// green
replace_all(msg,190,"\n","^1");// normal
replace_all(msg,190,"\t","^3");// team
if (id) players[0] = id; else get_players(players,count,"ch");
for (new i=0;i<count;i++)
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE,get_user_msgid("SayText"),_,players[i]);
write_byte(players[i]);
write_string(msg);
message_end();
}
}
|