Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Gonna test it? leave message and error > Discord: CheezPuff#7720 */
- #include <amxmodx>
- #include <fakemeta>
- #include <fvault>
- #include <engine>
- #define PLUGIN "Server Bank System"
- #define VERSION "1.3"
- #define AUTHOR "Ariel"
- #define MAX_PLAYERS 32
- #define VAULT_NAME "serv_bank"
- #define NPC_VAULT "serv_bank_npc"
- #define NPC_MODEL "models/bank_npc.mdl"
- new g_playerBalance[MAX_PLAYERS + 1];
- new g_playerCash[MAX_PLAYERS + 1];
- new g_npcEnt;
- public plugin_init() {
- register_plugin(PLUGIN, VERSION, AUTHOR);
- register_clcmd("say /bank", "cmd_OpenBankMenu");
- register_clcmd("say /setnpc", "cmd_SetNPC");
- register_touch("bank_npc", "player", "TouchBankNPC");
- // Load NPC position
- set_task(1.0, "load_npc");
- }
- public plugin_precache() {
- precache_model(NPC_MODEL);
- }
- public load_npc() {
- new map_name[32];
- get_mapname(map_name, charsmax(map_name));
- new data[64];
- if (fvault_get_data(NPC_VAULT, map_name, data, charsmax(data))) {
- new Float:origin[3];
- new x[16], y[16], z[16];
- new parsed = parse(data, x, charsmax(x), y, charsmax(y), z, charsmax(z));
- if (parsed == 3) {
- origin[0] = str_to_float(x);
- origin[1] = str_to_float(y);
- origin[2] = str_to_float(z);
- create_npc(origin);
- }
- }
- }
- public create_npc(Float:origin[3]) {
- if (g_npcEnt && pev_valid(g_npcEnt)) {
- engfunc(EngFunc_RemoveEntity, g_npcEnt);
- }
- g_npcEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
- if (g_npcEnt) {
- engfunc(EngFunc_SetModel, g_npcEnt, NPC_MODEL);
- engfunc(EngFunc_SetOrigin, g_npcEnt, origin);
- set_pev(g_npcEnt, pev_classname, "bank_npc");
- set_pev(g_npcEnt, pev_solid, SOLID_BBOX);
- set_pev(g_npcEnt, pev_movetype, MOVETYPE_NONE);
- engfunc(EngFunc_SetSize, g_npcEnt, Float:{-16.0, -16.0, 0.0}, Float:{16.0, 16.0, 72.0});
- }
- }
- public cmd_SetNPC(id) {
- if (!(get_user_flags(id) & ADMIN_RCON)) {
- client_print(id, print_chat, "[Bank] You don't have access to this command.");
- return PLUGIN_HANDLED;
- }
- new Float:origin[3];
- pev(id, pev_origin, origin);
- create_npc(origin);
- // Save NPC position
- new map_name[32];
- get_mapname(map_name, charsmax(map_name));
- new data[64];
- formatex(data, charsmax(data), "%.1f %.1f %.1f", origin[0], origin[1], origin[2]);
- fvault_set_data(NPC_VAULT, map_name, data);
- client_print(id, print_chat, "[Bank] NPC has been placed at your location.");
- return PLUGIN_HANDLED;
- }
- public TouchBankNPC(ent, id) {
- if (is_user_alive(id)) {
- cmd_OpenBankMenu(id);
- }
- }
- public cmd_OpenBankMenu(id) {
- new menu = menu_create("\yBank Menu", "HandleBankMenu");
- new balanceText[64];
- formatex(balanceText, charsmax(balanceText), "\wYour Balance: \y$%d", g_playerBalance[id]);
- menu_addtext(menu, balanceText, 0);
- menu_additem(menu, "\wDeposit", "1");
- menu_additem(menu, "\wWithdraw", "2");
- menu_display(id, menu, 0);
- return PLUGIN_HANDLED;
- }
- public HandleBankMenu(id, menu, item) {
- if (item == MENU_EXIT) {
- menu_destroy(menu);
- return PLUGIN_HANDLED;
- }
- switch (item) {
- case 0: {
- client_cmd(id, "messagemode Deposit_Amount");
- }
- case 1: {
- client_cmd(id, "messagemode Withdraw_Amount");
- }
- }
- menu_destroy(menu);
- return PLUGIN_HANDLED;
- }
- public client_command(id) {
- new cmd[32], amount[32];
- read_argv(0, cmd, charsmax(cmd));
- read_argv(1, amount, charsmax(amount));
- if (equal(cmd, "Deposit_Amount")) {
- handle_deposit(id, str_to_num(amount));
- } else if (equal(cmd, "Withdraw_Amount")) {
- handle_withdraw(id, str_to_num(amount));
- }
- return PLUGIN_CONTINUE;
- }
- public handle_deposit(id, amount) {
- if (amount <= 0) {
- client_print(id, print_chat, "[Bank] Invalid amount.");
- return;
- }
- if (g_playerCash[id] < amount) {
- client_print(id, print_chat, "[Bank] You don't have enough cash.");
- return;
- }
- g_playerCash[id] -= amount;
- g_playerBalance[id] += amount;
- client_print(id, print_chat, "[Bank] You've deposited $%d. New balance: $%d", amount, g_playerBalance[id]);
- save_player_balance(id);
- }
- public handle_withdraw(id, amount) {
- if (amount <= 0) {
- client_print(id, print_chat, "[Bank] Invalid amount.");
- return;
- }
- if (g_playerBalance[id] < amount) {
- client_print(id, print_chat, "[Bank] Insufficient balance.");
- return;
- }
- g_playerBalance[id] -= amount;
- g_playerCash[id] += amount;
- client_print(id, print_chat, "[Bank] You've withdrawn $%d. New balance: $%d", amount, g_playerBalance[id]);
- save_player_balance(id);
- }
- public client_putinserver(id) {
- // Load player's balance
- new authid[32], data[16];
- get_user_authid(id, authid, charsmax(authid));
- fvault_get_data(VAULT_NAME, authid, data, charsmax(data));
- g_playerBalance[id] = str_to_num(data);
- }
- public client_disconnected(id) {
- save_player_balance(id);
- }
- public save_player_balance(id) {
- new authid[32], balanceStr[16];
- get_user_authid(id, authid, charsmax(authid));
- num_to_str(g_playerBalance[id], balanceStr, charsmax(balanceStr));
- fvault_set_data(VAULT_NAME, authid, balanceStr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement