Advertisement
CheezPuff

[Free] Global Bank [By CheezPuff) not tested

Jul 11th, 2024 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Gonna test it? leave message and error > Discord: CheezPuff#7720 */
  2. #include <amxmodx>
  3. #include <fakemeta>
  4. #include <fvault>
  5. #include <engine>
  6.  
  7. #define PLUGIN "Server Bank System"
  8. #define VERSION "1.3"
  9. #define AUTHOR "Ariel"
  10.  
  11. #define MAX_PLAYERS 32
  12. #define VAULT_NAME "serv_bank"
  13. #define NPC_VAULT "serv_bank_npc"
  14. #define NPC_MODEL "models/bank_npc.mdl"
  15.  
  16. new g_playerBalance[MAX_PLAYERS + 1];
  17. new g_playerCash[MAX_PLAYERS + 1];
  18. new g_npcEnt;
  19.  
  20. public plugin_init() {
  21.     register_plugin(PLUGIN, VERSION, AUTHOR);
  22.    
  23.     register_clcmd("say /bank", "cmd_OpenBankMenu");
  24.     register_clcmd("say /setnpc", "cmd_SetNPC");
  25.    
  26.     register_touch("bank_npc", "player", "TouchBankNPC");
  27.    
  28.     // Load NPC position
  29.     set_task(1.0, "load_npc");
  30. }
  31.  
  32. public plugin_precache() {
  33.     precache_model(NPC_MODEL);
  34. }
  35.  
  36. public load_npc() {
  37.     new map_name[32];
  38.     get_mapname(map_name, charsmax(map_name));
  39.    
  40.     new data[64];
  41.     if (fvault_get_data(NPC_VAULT, map_name, data, charsmax(data))) {
  42.         new Float:origin[3];
  43.         new x[16], y[16], z[16];
  44.         new parsed = parse(data, x, charsmax(x), y, charsmax(y), z, charsmax(z));
  45.         if (parsed == 3) {
  46.             origin[0] = str_to_float(x);
  47.             origin[1] = str_to_float(y);
  48.             origin[2] = str_to_float(z);
  49.             create_npc(origin);
  50.         }
  51.     }
  52. }
  53.  
  54. public create_npc(Float:origin[3]) {
  55.     if (g_npcEnt && pev_valid(g_npcEnt)) {
  56.         engfunc(EngFunc_RemoveEntity, g_npcEnt);
  57.     }
  58.    
  59.     g_npcEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
  60.     if (g_npcEnt) {
  61.         engfunc(EngFunc_SetModel, g_npcEnt, NPC_MODEL);
  62.         engfunc(EngFunc_SetOrigin, g_npcEnt, origin);
  63.         set_pev(g_npcEnt, pev_classname, "bank_npc");
  64.         set_pev(g_npcEnt, pev_solid, SOLID_BBOX);
  65.         set_pev(g_npcEnt, pev_movetype, MOVETYPE_NONE);
  66.         engfunc(EngFunc_SetSize, g_npcEnt, Float:{-16.0, -16.0, 0.0}, Float:{16.0, 16.0, 72.0});
  67.     }
  68. }
  69.  
  70. public cmd_SetNPC(id) {
  71.     if (!(get_user_flags(id) & ADMIN_RCON)) {
  72.         client_print(id, print_chat, "[Bank] You don't have access to this command.");
  73.         return PLUGIN_HANDLED;
  74.     }
  75.    
  76.     new Float:origin[3];
  77.     pev(id, pev_origin, origin);
  78.    
  79.     create_npc(origin);
  80.    
  81.     // Save NPC position
  82.     new map_name[32];
  83.     get_mapname(map_name, charsmax(map_name));
  84.    
  85.     new data[64];
  86.     formatex(data, charsmax(data), "%.1f %.1f %.1f", origin[0], origin[1], origin[2]);
  87.     fvault_set_data(NPC_VAULT, map_name, data);
  88.    
  89.     client_print(id, print_chat, "[Bank] NPC has been placed at your location.");
  90.     return PLUGIN_HANDLED;
  91. }
  92.  
  93. public TouchBankNPC(ent, id) {
  94.     if (is_user_alive(id)) {
  95.         cmd_OpenBankMenu(id);
  96.     }
  97. }
  98.  
  99. public cmd_OpenBankMenu(id) {
  100.     new menu = menu_create("\yBank Menu", "HandleBankMenu");
  101.    
  102.     new balanceText[64];
  103.     formatex(balanceText, charsmax(balanceText), "\wYour Balance: \y$%d", g_playerBalance[id]);
  104.     menu_addtext(menu, balanceText, 0);
  105.    
  106.     menu_additem(menu, "\wDeposit", "1");
  107.     menu_additem(menu, "\wWithdraw", "2");
  108.    
  109.     menu_display(id, menu, 0);
  110.     return PLUGIN_HANDLED;
  111. }
  112.  
  113. public HandleBankMenu(id, menu, item) {
  114.     if (item == MENU_EXIT) {
  115.         menu_destroy(menu);
  116.         return PLUGIN_HANDLED;
  117.     }
  118.    
  119.     switch (item) {
  120.         case 0: {
  121.             client_cmd(id, "messagemode Deposit_Amount");
  122.         }
  123.         case 1: {
  124.             client_cmd(id, "messagemode Withdraw_Amount");
  125.         }
  126.     }
  127.    
  128.     menu_destroy(menu);
  129.     return PLUGIN_HANDLED;
  130. }
  131.  
  132. public client_command(id) {
  133.     new cmd[32], amount[32];
  134.     read_argv(0, cmd, charsmax(cmd));
  135.     read_argv(1, amount, charsmax(amount));
  136.    
  137.     if (equal(cmd, "Deposit_Amount")) {
  138.         handle_deposit(id, str_to_num(amount));
  139.     } else if (equal(cmd, "Withdraw_Amount")) {
  140.         handle_withdraw(id, str_to_num(amount));
  141.     }
  142.    
  143.     return PLUGIN_CONTINUE;
  144. }
  145.  
  146. public handle_deposit(id, amount) {
  147.     if (amount <= 0) {
  148.         client_print(id, print_chat, "[Bank] Invalid amount.");
  149.         return;
  150.     }
  151.    
  152.     if (g_playerCash[id] < amount) {
  153.         client_print(id, print_chat, "[Bank] You don't have enough cash.");
  154.         return;
  155.     }
  156.    
  157.     g_playerCash[id] -= amount;
  158.     g_playerBalance[id] += amount;
  159.    
  160.     client_print(id, print_chat, "[Bank] You've deposited $%d. New balance: $%d", amount, g_playerBalance[id]);
  161.     save_player_balance(id);
  162. }
  163.  
  164. public handle_withdraw(id, amount) {
  165.     if (amount <= 0) {
  166.         client_print(id, print_chat, "[Bank] Invalid amount.");
  167.         return;
  168.     }
  169.    
  170.     if (g_playerBalance[id] < amount) {
  171.         client_print(id, print_chat, "[Bank] Insufficient balance.");
  172.         return;
  173.     }
  174.    
  175.     g_playerBalance[id] -= amount;
  176.     g_playerCash[id] += amount;
  177.    
  178.     client_print(id, print_chat, "[Bank] You've withdrawn $%d. New balance: $%d", amount, g_playerBalance[id]);
  179.     save_player_balance(id);
  180. }
  181.  
  182. public client_putinserver(id) {
  183.     // Load player's balance
  184.     new authid[32], data[16];
  185.     get_user_authid(id, authid, charsmax(authid));
  186.     fvault_get_data(VAULT_NAME, authid, data, charsmax(data));
  187.     g_playerBalance[id] = str_to_num(data);
  188. }
  189.  
  190. public client_disconnected(id) {
  191.     save_player_balance(id);
  192. }
  193.  
  194. public save_player_balance(id) {
  195.     new authid[32], balanceStr[16];
  196.     get_user_authid(id, authid, charsmax(authid));
  197.     num_to_str(g_playerBalance[id], balanceStr, charsmax(balanceStr));
  198.     fvault_set_data(VAULT_NAME, authid, balanceStr);
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement