· 7 years ago · Dec 06, 2018, 10:38 AM
1#include <amxmodx>
2#include <amxmisc>
3#include <fakemeta>
4#include <test>
5
6enum {
7 SAVE_NVAULT = 1,
8 SAVE_SQL
9}
10
11#define SAVE_TYPE SAVE_NVAULT
12
13#if SAVE_TYPE == SAVE_SQL
14 #include <sqlx>
15
16 new Handle:g_SqlX;
17 new const sql_table[] = "cod_bank"
18 new query_buff[1028];
19#else
20 #include <nvault>
21
22 new gVault;
23#endif
24
25new const version[] = "4.4";
26new const plugin[] = "COD:MW3";
27
28enum pcvar
29{ enable = 0, auto, start, account2, charge, interest, charge3, repitions }
30
31new pcvars[pcvar];
32new bankstorage[33], sessionstore[33];
33new special[33], bool:warning[33], bool:xploaded[33], bool:lock_cmd[33];
34new clockstore[33];
35
36new thinkobj, loop_count;
37
38public plugin_init()
39{
40 register_plugin(plugin, version, "Random1");
41
42 pcvars[enable] = register_cvar("cod_bank", "1");
43 pcvars[auto] = register_cvar("cod_bank_auto", "0");
44 pcvars[start] = register_cvar("cod_bank_blockstart", "0");
45 pcvars[account2] = register_cvar("cod_bank_upgradable", "1");
46 pcvars[charge] = register_cvar("cod_bank_cost", "1000");
47 pcvars[interest] = register_cvar("cod_bank_interest", "0.2");
48 pcvars[repitions] = register_cvar("cod_bank_clock", "60");
49 pcvars[charge3] = register_cvar("cod_bank_transfee", "0");
50
51 register_clcmd("say", "handle_say");
52 register_clcmd("say_team", "handle_say");
53 register_concmd("cod_bank_amount", "serverbank", ADMIN_RCON, "<name/steamid>");
54 register_concmd("cod_reset_bank", "prune_task", ADMIN_RCON, "<time> in days. time 0 = clean all");
55 register_concmd("cod_give_packs", "givex_cmd", ADMIN_RCON, "<steamid not name> <amount>, gives ammo packs even if person not in game");
56
57 #if SAVE_TYPE == SAVE_SQL
58 set_task(0.5, "sql_init");
59 register_logevent("logevent_round_end", 2, "1=Round_End");
60 #else
61 gVault = nvault_open("cod_bank_data");
62 #endif
63
64 thinkobj = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
65 if ( pev_valid(thinkobj) )
66 {
67 set_pev(thinkobj, pev_classname, "advertisement_loop");
68 set_pev(thinkobj, pev_nextthink, get_gametime() + 60.0);
69 register_forward(FM_Think, "onemin_think");
70 }
71}
72
73public plugin_natives()
74{
75 register_native("cod_get_all_ammopacks", "native_retrieve_all_ap", 1);
76 register_native("cod_get_bank_ammopacks", "native_retrieve_ap", 1);
77 register_native("cod_set_bank_ammopacks", "native_set_ap", 1);
78}
79
80#if SAVE_TYPE == SAVE_SQL
81public sql_init()
82{
83 g_SqlX = SQL_MakeStdTuple();
84
85 formatex(query_buff, charsmax(query_buff), "CREATE TABLE IF NOT EXISTS `%s` (\
86 USER_KEY VARCHAR(36) NOT NULL PRIMARY KEY, \
87 AMMOPACK DECIMAL( 10 ) UNSIGNED NOT NULL DEFAULT '0', \
88 ADVANCED TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, \
89 TIMECLOCK INT(10) NOT NULL DEFAULT 0, \
90 LAST_PLAY_DATE TIMESTAMP(10) NOT NULL \
91 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", sql_table)
92
93 SQL_ThreadQuery(g_SqlX, "handle_error", query_buff);
94}
95
96public logevent_round_end()
97{
98 for( new id = 1; id <= 32; id++ )
99 if ( is_user_connected(id) && !xploaded[id] )
100 retrieve_data(id);
101}
102#endif
103
104public prune_task(id,level,cid)
105{
106 if (!cmd_access(id,level,cid,1)) {
107 console_print(id,"You have no access to that command");
108 return;
109 }
110 new connum = read_argc()
111 if (connum > 2) {
112 console_print(id,"Too many arguments supplied.");
113 return;
114 }
115 if ( connum == 1 ) return; //person just typed command to see the description
116 //we check this because str_to_num will return 0 on an empty string thus doing the same thing as "cod_reset_bank 0" which does a full reset
117
118 new adminname[32];
119 get_user_name(id, adminname, 31);
120 new arg[10];
121 read_argv(1,arg,9);
122 new timeamnt = str_to_num(arg);
123 if ( timeamnt == 0 ) {
124#if SAVE_TYPE == SAVE_NVAULT
125 nvault_prune(gVault, 0, 0);
126#else
127 formatex(query_buff, charsmax(query_buff), "TRUNCATE TABLE `%s`", sql_table);
128
129 SQL_ThreadQuery(g_SqlX, "handle_error", query_buff)
130#endif
131 client_print(0, print_chat, "^x04[%s]^x03 The Bank's Been Robbed!, those dirty crooks stole all your money!", plugin);
132 log_to_file("cod_error.log", "[%s] bank has been reset(completly) by admin %s", plugin, adminname);
133 //for those who are in the server at the time of prune need to whipe out there stuff as well
134 for( new o = 1; o < 33; o++)
135 {
136 if ( !is_user_connected(o) || is_user_bot(o) ) continue;
137
138 special[o] = 0;
139 warning[o] = false;
140 bankstorage[o] = 0;
141 clockstore[o] = -1;
142 }
143 }
144 else {
145#if SAVE_TYPE == SAVE_NVAULT
146 nvault_prune(gVault, 0, get_systime() - (timeamnt * 86400));
147#else
148 formatex(query_buff, charsmax(query_buff), "DELETE FROM `%s` WHERE LAST_PLAY_DATE<(SYSDATE() - INTERVAL '%d' DAY)", sql_table, timeamnt);
149
150 SQL_ThreadQuery(g_SqlX, "handle_error", query_buff)
151#endif
152 log_to_file("cod_error.log", "[%s] bank has been pruned %d day%s by admin %s", plugin, timeamnt, timeamnt == 1 ? "" : "'s", adminname);
153 }
154}
155
156public givex_cmd(id,level,cid)
157{
158 if (!cmd_access(id,level,cid,1)) {
159 console_print(id,"You have no access to that command");
160 return;
161 }
162
163 if ( read_argc() > 3 ) return;
164
165 new arg1[32], arg2[10], amount;
166 read_argv(1, arg1, sizeof(arg1) - 1);
167 read_argv(2, arg2, sizeof(arg2) - 1);
168 if ( arg1[0] != 'S' && !isdigit(arg1[6]) )
169 {
170 server_print("[%s] please only use steamid and be sure to append the STEAM_0:", plugin);
171 return;
172 }
173 if ( !isdigit(arg2[0]) && !isdigit(arg2[1]) ) {
174 server_print("[%s] error argument2 = %s, should be a number", plugin, arg2);
175 return;
176 }
177
178 amount = str_to_num(arg2);
179 //first see if our player is not currently in server
180 new i, AuthID[32];
181 for( i = 1; i <= 32; i++ )
182 {
183 get_user_authid(i,AuthID,31);
184 if ( equal(AuthID, arg1) )
185 {
186 bankstorage[i] += amount;
187 server_print( "[%s] Succesfuly %s %d ammo packs %s %s. Account now has %d", plugin, amount > 0 ? "gave" : "took", amount, amount > 0 ? "to" : "from", arg1, bankstorage[i]);
188 log_to_file( "cod_banking.log", "[%s] Succesfuly %s %d ammo packs %s %s. Account now has %d", plugin, amount > 0 ? "gave" : "took", amount, amount > 0 ? "to" : "from", arg1, bankstorage[i]);
189 return;
190 }
191 }
192 //not in the server so have to check our nvault file now
193#if SAVE_TYPE == SAVE_NVAULT
194 new vaultkey[38], vaultdata[64];
195
196 formatex(vaultkey, 37, "__%s__", arg1);
197
198 nvault_get(gVault, vaultkey, vaultdata, 63);
199 if ( strlen(vaultdata) == 0 )
200 {
201 server_print( "[%s] player does not exsist within database, make sure your passing right steamid", plugin);
202 return;
203 }
204 new cashamnt[51], has2[4], clockamnt[10], buffer[3];
205 parse(vaultdata, cashamnt, 50, has2, 3, clockamnt, 9);
206
207 buffer[0] = str_to_num(cashamnt);
208 buffer[1] = str_to_num(has2);
209 buffer[2] = str_to_num(clockamnt);
210 server_print( "[%s] %s has %d ammo packs before applying %d from cod_give_packs command", plugin, arg1, buffer[0], amount);
211 //now apply the command
212 buffer[0] += amount;
213 if ( buffer[0] < 0 ) buffer[0] = 0;
214 formatex(vaultdata, 63, "%i %i %i", buffer[0], buffer[1], buffer[2]);
215
216 nvault_set(gVault, vaultkey, vaultdata);
217 server_print( "[%s] Succesfuly %s %d ammo packs %s %s. Account now has %d", plugin, amount > 0 ? "gave" : "took", amount, amount > 0 ? "to" : "from", arg1, buffer[0]);
218#else
219 new data[38]
220 data[0] = amount
221 formatex(data[1], charsmax(data)-1, arg1);
222
223 formatex(query_buff, charsmax(query_buff), "INSERT INTO `%s` SET USER_KEY='%s', AMMOPACK=%d ON DUPLICATE KEY UPDATE AMMOPACK=AMMOPACK+(%d)",
224 sql_table, arg1, amount, amount);
225
226 SQL_ThreadQuery(g_SqlX, "handle_error", query_buff, data, charsmax(data));
227#endif
228}
229
230public onemin_think(ent)
231{
232 if ( ent != thinkobj ) return FMRES_IGNORED;
233 if ( --loop_count <= 0 )
234 {
235 advertisement();
236 loop_count = 4;
237 }
238
239 if ( !get_pcvar_num(pcvars[account2]) ) return FMRES_IGNORED;
240
241 for ( new id = 1; id < 33; id++ )
242 {
243 if ( !is_user_alive(id) || is_user_bot(id) || lock_cmd[id] ) continue;
244
245 save_data(id);
246
247 if (special[id] ) {
248 clockstore[id]--
249 if ( clockstore[id] == 0 )
250 {
251 clockstore[id] = get_pcvar_num(pcvars[repitions]);
252 add_interest(id);
253 }
254 }
255 }
256 set_pev(ent, pev_nextthink, get_gametime() + 60.0);
257
258 return FMRES_HANDLED;
259}
260
261add_interest(id)
262{
263 new Float:temp = float( bankstorage[id] );
264 if ( temp <= 0.0 || temp > 100000.0 ) return;
265 temp *= get_pcvar_float(pcvars[interest]);
266 new temp2 = floatround(temp);
267 if ( temp2 < 0 || temp2 > get_pcvar_num(pcvars[charge]) )
268 return;
269
270 localchange(id, temp2);
271
272 client_print(0, print_chat,"^x04[%s]^x03 interest applied new balance is %d", plugin, bankstorage[id]);
273}
274
275advertisement()
276{
277 if ( !get_pcvar_num(pcvars[enable]) ) return;
278
279 client_print(0, print_chat, "^x04[%s]^x03 Enabled. Transaction fee's of %d apply", plugin, get_pcvar_num(pcvars[charge3]) );
280 client_print(0, print_chat,"^x04[%s]^x03 Currently Ammo packs are %s", plugin,
281 get_pcvar_num(pcvars[auto]) >= 1 ? "Saved automaticly during map change" : "Savable by typing ^"deposit <amount>^"." );
282 client_print(0, print_chat,"^x04[%s]^x03 %s", plugin,
283 get_pcvar_num(pcvars[auto]) >= 2 ? "Ammo packs are withdrawn when connecting" : "To retrieve your ammo packs type ^"withdraw <amount>^"" );
284 if ( get_pcvar_num(pcvars[account2]) )
285 {
286 new irepition = get_pcvar_num(pcvars[repitions]);
287 new timetype[8];
288 formatex(timetype, charsmax(timetype), "%s", irepition >= 60 ? "hours" : "minutes");
289 if ( irepition >= 60 )
290 irepition /= 60;
291
292 client_print(0, print_chat,"^x04[%s]^x03 Advance account's available, say ^"upgrade account^" for more details", plugin);
293 client_print(0, print_chat,"^x04[%s]^x03 An upgraded account will earn you %2.2f interest every %i %s", plugin, get_pcvar_float(pcvars[interest]), irepition, timetype);
294 }
295}
296public plugin_end() {
297 //one final save on all users before changing maps
298 for ( new id = 1; id < 33; id++ )
299 if ( is_user_connected(id) ) save_data(id);
300
301#if SAVE_TYPE == SAVE_NVAULT
302 nvault_close(gVault);
303#else
304 SQL_FreeHandle(g_SqlX);
305#endif
306}
307
308public handle_say(id)
309{
310 if ( !get_pcvar_num(pcvars[enable]) || lock_cmd[id] ) return PLUGIN_CONTINUE;
311
312 static text[70], arg1[32], arg2[32], arg3[6];
313 read_args(text, sizeof(text)-1);
314 remove_quotes(text);
315 arg1[0] = '^0';
316 arg2[0] = '^0';
317 arg3[0] = '^0';
318 parse(text, arg1, sizeof(arg1)-1, arg2, sizeof(arg2)-1, arg3, sizeof(arg3)-1);
319
320 if (arg3[0] == 0)
321 {
322 //strip forward slash if present
323 if ( equali(arg1, "/", 1) ) format(arg1, 31, arg1[1]);
324
325 if ( equali(arg1, "deposit", 7) || equali(arg1, "send", 4) || equali(arg1, "store", 5) || equali(arg1, "ubaci", 5) )
326 {
327 if ( isdigit(arg2[0]) || (arg2[0] == '-' && isdigit(arg2[1])) )
328 {
329 new value = str_to_num(arg2);
330 store_cash(id, value);
331 return PLUGIN_HANDLED;
332 }
333 else if ( equali(arg2, "all") )
334 {
335 store_cash(id, -1);
336 return PLUGIN_HANDLED;
337 }
338 else if ( arg2[0] == 0 )
339 client_print(0, print_chat,"^x04[%s]^x03 to deposit ammo packs in bank say deposit <amount to deposit>", plugin);
340
341 return PLUGIN_CONTINUE;
342 }
343 else if ( equali(arg1, "withdraw", 8) || equali(arg1, "take", 4) || equali(arg1, "retrieve", 8) || equali(arg1, "preuzmi", 7) || equali(arg1, "podigni", 7))
344 {
345 if ( isdigit(arg2[0]) || (arg2[0] == '-' && isdigit(arg2[1])) )
346 {
347 new value = str_to_num(arg2);
348 take_cash(id, value);
349 return PLUGIN_HANDLED;
350 }
351 else if ( equali(arg2, "all") )
352 {
353 take_cash(id, -1);
354 return PLUGIN_HANDLED;
355 }
356 else if ( arg2[0] == 0 )
357 client_print(0, print_chat,"^x04[%s]^x03 to withdraw ammo packs from bank say withdraw <amount to withdraw>", plugin);
358
359 return PLUGIN_CONTINUE;
360 }
361 else if ( equali(arg1, "mybank", 6) || equali(arg1, "account", 8) || equali(arg1, "bank", 4) || equali(arg1, "racun", 5) || equali(arg1, "stanje", 6))
362 {
363 if ( arg2[0] == 0 ) {
364 client_print(0, print_chat,"^x04[%s]^x03 Currently your [%s]account has %d ammo packs in it",plugin,special[id] ? "advanced" : "regular", bankstorage[id]);
365 return PLUGIN_HANDLED;
366 }
367 else {
368 new player = cmd_target(id,arg2,2);
369 if ( !player ) return PLUGIN_CONTINUE;
370 client_print(0, print_chat,"^x04[%s]^x03 %s has %d ammo packs", plugin, arg2, bankstorage[player]);
371 return PLUGIN_HANDLED;
372 }
373 }
374 else if ( equali(arg1, "upgrade", 7) && equali(arg2, "account", 7) || equali(arg1, "apgrejduj", 9) || equali(arg1, "pojacaj", 7))
375 {
376 if ( !warning[id] )
377 upgrade_account(id);
378
379 else
380 do_upgrade(id);
381 }
382 }
383 return PLUGIN_CONTINUE;
384}
385
386public serverbank(id,level,cid)
387{
388 if (!cmd_access(id,level,cid,1)) {
389 console_print(id,"You have no access to that command");
390 return;
391 }
392
393 new arg[35], player, playername[35], AuthID[35];
394 read_argv(1, arg, sizeof(arg) - 1);
395
396 if ( equali(arg, "all") )
397 {
398 for ( new i = 1; i < 33; i++ )
399 {
400 if ( !is_user_connected(i) ) continue;
401
402 get_user_name( i, playername, sizeof(playername) - 1 );
403 server_print("[%s] %s has %d ammo packs", plugin, playername, bankstorage[i]);
404 }
405 return;
406 }
407
408 player = 0
409 for( new i = 1; i <= 32; i++ )
410 {
411 if ( !is_user_connected(i) || is_user_bot(i) ) continue;
412
413 get_user_name( i, playername, charsmax(playername) );
414 get_user_authid( i, AuthID, charsmax(AuthID) );
415 if ( equal(AuthID, arg) || containi(playername, arg) )
416 {
417 player = i;
418 break;
419 }
420 }
421
422 if ( !player )
423 {
424 server_print("Error locating player");
425 return;
426 }
427 server_print("[%s] %s has %d ammo packs", plugin, arg, bankstorage[player]);
428}
429
430upgrade_account(id)
431{
432 if ( !get_pcvar_num(pcvars[account2]) ) return;
433
434 if ( special[id] )
435 {
436 client_print(0, print_chat,"^x04[%s]^x03 You already have an advanced account", plugin);
437 return;
438 }
439 else
440 {
441 client_print(0, print_chat, "^x04[%s]^x03 You have opted to upgrade your bank account type", plugin);
442 client_print(0, print_chat, "^x04[%s]^x03 An upgraded account will earn you %2.2f interest an hour", plugin, get_pcvar_float(pcvars[interest]));
443 new temp = bankstorage[id] + cod_get_user_gb(id);
444 if ( temp > get_pcvar_num(pcvars[charge]) )
445 {
446 client_print(0, print_chat, "^x04[%s]^x03 There is a %d starting fee", plugin, get_pcvar_num(pcvars[charge]) );
447 client_print(0, print_chat, "^x04[%s]^x03 If you accept these conditions simply retype ^"upgrade account^", and your account will be upgraded", plugin);
448 warning[id] = true;
449 }
450 else
451 client_print(0, print_chat, "^x04[%s]^x03 You do not have the required %d ammo packs to upgrade account yet", plugin, get_pcvar_num(pcvars[charge]) );
452 }
453}
454
455do_upgrade(id)
456{
457 if ( !get_pcvar_num(pcvars[account2]) ) return;
458
459 new temp2 = bankstorage[id] + cod_get_user_gb(id);
460 new temp = get_pcvar_num(pcvars[charge]);
461 if ( temp2 > temp )
462 {
463 if ( bankstorage[id] - 1 > temp )
464 localchange(id, -temp);
465 else
466 {
467 temp -= bankstorage[id] - 1
468 bankstorage[id] = 1;
469 cod_set_user_gb(id, cod_get_user_gb(id) - temp);
470 }
471 special[id] = 1;
472 clockstore[id] = 1; //time to start the clock
473 client_print(0, print_chat, "^x04[%s]^x03 You account has been upgraded", plugin);
474 }
475 else {
476 client_print(0, print_chat, "^x04[%s]^x03 You don't have the necessary amount of ammo packs to upgrade your account", plugin);
477 warning[id] = false;
478 }
479}
480
481public client_disconnect(id)
482{
483 if ( get_pcvar_num(pcvars[auto]) )
484 store_cash(id, -1);
485
486 if ( bankstorage[id] > 0 ) save_data(id);
487 lock_cmd[id] = true; //basically this prevents players attempting to dupe their ap by reconnecting
488}
489
490public client_putinserver(id)
491 set_task(1.0, "delayed_connect", id); //a small delay allows zp to load all its data before we mess with it
492
493public delayed_connect(id)
494{
495 warning[id] = false;
496 special[id] = 0;
497 xploaded[id] = false;
498 bankstorage[id] = 0;
499 sessionstore[id] = 0;
500 clockstore[id] = -1;
501 lock_cmd[id] = false; //now they have officially connected and we allow bank commands again
502
503 //attempt to retrive the data right away
504 retrieve_data(id);
505}
506
507store_cash(id, amnt)
508{
509 if ( !get_pcvar_num(pcvars[enable]) ) return;
510
511 new userpacks = cod_get_user_gb(id);
512 if ( amnt == -1 )
513 {
514 localchange(id, userpacks);
515 cod_set_user_gb(id, 0);
516 }
517 else if ( amnt > 0 )
518 {
519 if ( amnt > get_pcvar_num(pcvars[charge3]) )
520 {
521 deduction(id);
522 amnt -= get_pcvar_num(pcvars[charge3]);
523 }
524
525 if ( userpacks >= amnt )
526 {
527 localchange(id, amnt);
528 cod_set_user_gb(id, userpacks - amnt);
529 }
530 else
531 client_print(0, print_chat, "^x04[%s]^x03 Amount specified(%d) is greater than current ammo pack count(%d)", plugin,
532 amnt, userpacks);
533 }
534 else
535 take_cash(id, -amnt);
536}
537
538take_cash(id, amnt)
539{
540 if ( !get_pcvar_num(pcvars[enable]) ) return;
541
542 if ( amnt == 0 ) return; //otherwise a non terminal loop is possible
543
544 if ( amnt == -1 )
545 {
546 if ( special[id] )
547 {
548 cod_set_user_gb(id, bankstorage[id] - 1)
549 bankstorage[id] = 1;
550 }
551 else
552 {
553 cod_set_user_gb(id, cod_get_user_gb(id) + bankstorage[id])
554 bankstorage[id] = 0;
555 }
556 }
557 else if ( amnt > 0 )
558 {
559 if ( bankstorage[id] >= amnt )
560 {
561 deduction(id);
562
563 cod_set_user_gb(id, cod_get_user_gb(id) + amnt);
564 localchange(id, -amnt);
565 } else {
566 client_print(0, print_chat, "^x04[%s]^x03 Amount specified(%d) is greater than whats in bank(%d)", plugin, amnt, bankstorage[id]);
567 }
568 }
569 else store_cash(id, -amnt);
570}
571
572localchange(id, amount, mainload = 0)
573{
574 new playerAP = bankstorage[id]
575 new newTotal = playerAP + amount
576
577 if ( amount > 0 && newTotal < playerAP ) {
578 // Max possible signed 32bit int
579 bankstorage[id] = 2147483647
580 }
581 else if ( amount < 0 && (newTotal < -1000000 || newTotal > playerAP) ) {
582 bankstorage[id] = -1000000
583 }
584 else {
585 bankstorage[id] = newTotal
586 }
587 if ( mainload )
588 sessionstore[id] += amount;
589}
590
591deduction(id)
592{
593 new temp = bankstorage[id] + cod_get_user_gb(id) - 1;
594 new temp2 = get_pcvar_num(pcvars[charge3]);
595 if ( temp >= temp2 )
596 {
597 if ( bankstorage[id] - 1 > temp2 )
598 localchange(id, -temp2);
599
600 else
601 {
602 temp2 -= ( bankstorage[id] - 1 );
603 cod_set_user_gb(id, cod_get_user_gb(id) - temp2);
604 bankstorage[id] = 1;
605 }
606 }
607}
608
609#if SAVE_TYPE == SAVE_NVAULT
610
611save_data(id)
612{
613 if ( !xploaded[id] ) {
614 retrieve_data(id);
615 return;
616 }
617
618 new AuthID[35];
619 get_user_authid(id, AuthID, charsmax(AuthID));
620 if ( !strlen(AuthID) ) return;
621
622 new vaultdata[64], temp;
623
624 temp = special[id] ? 1 : 0;
625
626 formatex( vaultdata, 511, "%i %i %i", bankstorage[id], temp, clockstore[id] );
627
628 nvault_set(gVault, AuthID, vaultdata);
629}
630
631retrieve_data(id)
632{
633 if ( xploaded[id] || !is_user_connected(id) ) return;
634
635 new AuthID[35];
636 get_user_authid(id, AuthID, charsmax(AuthID));
637 if ( !strlen(AuthID) ) return;
638
639 new vaultdata[64];
640
641 nvault_get(gVault, AuthID, vaultdata, 63);
642
643 new cashamnt[51], has2[4], clockamnt[10];
644 parse(vaultdata, cashamnt, charsmax(cashamnt), has2, charsmax(has2), clockamnt, charsmax(clockamnt));
645
646 localchange(id, str_to_num(cashamnt), 1);
647 special[id] = ( str_to_num(has2) == 1 );
648 clockstore[id] = str_to_num(clockamnt);
649 xploaded[id] = true;
650
651 // If they have an account don't allow zombie mod to give them 5 ammo packs at beggining
652 if ( get_pcvar_num(pcvars[start]) && bankstorage[id] > 0 )
653 cod_set_user_gb(id, 0);
654
655 if ( get_pcvar_num(pcvars[auto]) == 2 )
656 take_cash(id, -1);
657}
658
659#else
660
661save_data(id)
662{
663 if ( !xploaded[id] ) {
664 retrieve_data(id);
665 return;
666 }
667 new AuthID[35];
668 get_user_authid(id, AuthID, charsmax(AuthID));
669 if ( !strlen(AuthID) || bankstorage[id] <= 0 ) return;
670
671 formatex(query_buff, charsmax(query_buff), "INSERT INTO `%s` SET USER_KEY='%s', AMMOPACK=%d, ADVANCED=%d, TIMECLOCK=%d, LAST_PLAY_DATE=SYSDATE() ON DUPLICATE KEY UPDATE AMMOPACK=AMMOPACK+(%d), ADVANCED=%d, TIMECLOCK=%d, LAST_PLAY_DATE=SYSDATE()",
672 sql_table, AuthID, bankstorage[id], special[id] ? 1 : 0, clockstore[id], sessionstore[id], special[id] ? 1 : 0, clockstore[id]);
673
674 SQL_ThreadQuery(g_SqlX, "handle_error", query_buff);
675}
676public handle_error(failstate, Handle:query, error[], errnum, data[], size)
677{
678 if (failstate)
679 {
680 server_print("[%s] SQL error: '%s'", plugin, error);
681 log_to_file("cod_error.log", "[%s] SQL error: '%s'", plugin, error);
682 return;
683 }
684 if ( size > 36 ) {
685 new authid[35], amount;
686 amount = data[0];
687 copy(authid, charsmax(authid), data[1]);
688 server_print( "[%s] Succesfuly %s %d ammo packs %s %s.", plugin, amount > 0 ? "gave" : "took", amount, amount > 0 ? "to" : "from", authid);
689 log_to_file( "cod_banking.log", "[%s] Succesfuly %s %d ammo packs %s %s.", plugin, amount > 0 ? "gave" : "took", amount, amount > 0 ? "to" : "from", authid);
690 }
691}
692
693retrieve_data(id)
694{
695 new buffer[38], AuthID[35];
696 get_user_authid(id, AuthID, charsmax(AuthID));
697 if ( !strlen(AuthID) ) return;
698
699 formatex(query_buff, charsmax(query_buff), "SELECT AMMOPACK,ADVANCED,TIMECLOCK FROM `%s` WHERE USER_KEY='%s'", sql_table, AuthID);
700
701 buffer[0] = id;
702 copy(buffer[1], charsmax(buffer)-1, AuthID);
703
704 SQL_ThreadQuery(g_SqlX, "handle_retrieve", query_buff, buffer, charsmax(buffer));
705}
706public handle_retrieve(failstate, Handle:hrquery, error[], errnum, data[], size)
707{
708 new id = data[0];
709 if ( xploaded[id] || !is_user_connected(id) ) return;
710
711 new AuthExpected[35], AuthCalled[35];
712 get_user_authid(id, AuthExpected, 34);
713 copy(AuthCalled, 34, data[1]);
714 if ( !equali(AuthExpected, AuthCalled) )
715 {
716 log_to_file("cod_error.log", "[%s] Load Glitch, expected = %s, passed = %s", plugin, AuthExpected, AuthCalled);
717 return;
718 }
719 if (failstate)
720 {
721 log_to_file("cod_error.log", "[%s] SQL error: '%s'", plugin, error);
722 return;
723 }
724 else
725 {
726 if ( !SQL_NumResults(hrquery) )
727 console_print(id, "[%s] No save data located", plugin);
728
729 else
730 {
731 new ipacks = 0;
732 ipacks = SQL_ReadResult(hrquery, 0);
733
734 special[id] = SQL_ReadResult(hrquery, 1) >= 1 ? 1 : 0;
735 clockstore[id] = SQL_ReadResult(hrquery, 2);
736
737 if( special[id] && !clockstore[id] )
738 clockstore[id] = get_pcvar_num(pcvars[repitions]); //in case an error occured durig saving process before
739
740 localchange(id, ipacks, 1);
741 console_print(id, "[%s] account has been loaded from save table", plugin);
742
743 // If they have an account don't allow zombie mod to give them 5 ammo packs at beggining
744 if ( get_pcvar_num(pcvars[start]) && bankstorage[id] > 0 )
745 cod_set_user_gb(id, 0);
746 }
747 xploaded[id] = true;
748 }
749
750 if ( get_pcvar_num(pcvars[auto]) == 2 )
751 take_cash(id, -1);
752}
753
754#endif
755
756public native_retrieve_all_ap(id)
757 return cod_get_user_gb(id) + bankstorage[id];
758
759public native_retrieve_ap(id)
760 return bankstorage[id];
761
762public native_set_ap(id, amount, bool:addto)
763{
764 if ( !is_user_connected(id) ) return;
765
766 bankstorage[id] = addto ? bankstorage[id] + amount : amount;
767}