ZP Bank
ZP Bank
ZP Bank
initiallly this plugin started off with just the auto save feature making it just a
plain save system
but it was decided that making it more like a bank would be more interesting and
slowly it was converted
to include commands etc while leaving the original auto save function in place.
Later advanced bank accounts
with interest where added as was sql support.
say commands
deposit, send, store <amount/all> //deposites stated amount in
bank account
server commands
zp_give_packs <steamid not name> <amount> //gives ammo packs even if person not in
game
zp_bank_amount <name/steamid> //same as bank say command, but
works from server console
zp_reset_bank <time> //will prune database by time
based in days. time 0 = clean all
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <zombieplague>
enum {
SAVE_NVAULT = 1,
SAVE_SQL
}
new Handle:g_SqlX;
new const sql_table[] = "zp_bank"
new query_buff[1028];
#else
#include <nvault>
new gVault;
#endif
enum pcvar
{ enable = 0, auto, start, account2, charge, interest, charge3, repitions }
new pcvars[pcvar];
new bankstorage[33], sessionstore[33];
new special[33], bool:warning[33], bool:xploaded[33], bool:lock_cmd[33];
new clockstore[33];
public plugin_init()
{
register_plugin(plugin, version, "Random1");
register_clcmd("say", "handle_say");
register_clcmd("say_team", "handle_say");
register_concmd("zp_bank_amount", "serverbank", ADMIN_RCON,
"<name/steamid>");
register_concmd("zp_reset_bank", "prune_task", ADMIN_RCON, "<time> in days.
time 0 = clean all");
register_concmd("zp_give_packs", "givex_cmd", ADMIN_RCON, "<steamid not name>
<amount>, gives ammo packs even if person not in game");
public plugin_natives()
{
register_native("zp_get_all_ammopacks", "native_retrieve_all_ap", 1);
register_native("zp_get_bank_ammopacks", "native_retrieve_ap", 1);
register_native("zp_set_bank_ammopacks", "native_set_ap", 1);
}
public logevent_round_end()
{
for( new id = 1; id <= 32; id++ )
if ( is_user_connected(id) && !xploaded[id] )
retrieve_data(id);
}
#endif
public prune_task(id,level,cid)
{
if (!cmd_access(id,level,cid,1)) {
console_print(id,"You have no access to that command");
return;
}
new connum = read_argc()
if (connum > 2) {
console_print(id,"Too many arguments supplied.");
return;
}
if ( connum == 1 ) return; //person just typed command to see the
description
//we check this because str_to_num will return 0 on an empty string thus
doing the same thing as "zp_reset_bank 0" which does a full reset
new adminname[32];
get_user_name(id, adminname, 31);
new arg[10];
read_argv(1,arg,9);
new timeamnt = str_to_num(arg);
if ( timeamnt == 0 ) {
#if SAVE_TYPE == SAVE_NVAULT
nvault_prune(gVault, 0, 0);
#else
formatex(query_buff, charsmax(query_buff), "TRUNCATE TABLE `%s`",
sql_table);
special[o] = 0;
warning[o] = false;
bankstorage[o] = 0;
clockstore[o] = -1;
}
}
else {
#if SAVE_TYPE == SAVE_NVAULT
nvault_prune(gVault, 0, get_systime() - (timeamnt * 86400));
#else
formatex(query_buff, charsmax(query_buff), "DELETE FROM `%s` WHERE
LAST_PLAY_DATE<(SYSDATE() - INTERVAL '%d' DAY)", sql_table, timeamnt);
public givex_cmd(id,level,cid)
{
if (!cmd_access(id,level,cid,1)) {
console_print(id,"You have no access to that command");
return;
}
amount = str_to_num(arg2);
//first see if our player is not currently in server
new i, AuthID[32];
for( i = 1; i <= 32; i++ )
{
get_user_authid(i,AuthID,31);
if ( equal(AuthID, arg1) )
{
bankstorage[i] += amount;
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]);
log_to_file( "zp_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]);
return;
}
}
//not in the server so have to check our nvault file now
#if SAVE_TYPE == SAVE_NVAULT
new vaultkey[38], vaultdata[64];
buffer[0] = str_to_num(cashamnt);
buffer[1] = str_to_num(has2);
buffer[2] = str_to_num(clockamnt);
server_print( "[%s] %s has %d ammo packs before applying %d from
zp_give_packs command", plugin, arg1, buffer[0], amount);
//now apply the command
buffer[0] += amount;
if ( buffer[0] < 0 ) buffer[0] = 0;
formatex(vaultdata, 63, "%i %i %i", buffer[0], buffer[1], buffer[2]);
public onemin_think(ent)
{
if ( ent != thinkobj ) return FMRES_IGNORED;
if ( --loop_count <= 0 )
{
advertisement();
loop_count = 4;
}
save_data(id);
if (special[id] ) {
clockstore[id]--
if ( clockstore[id] == 0 )
{
clockstore[id] = get_pcvar_num(pcvars[repitions]);
add_interest(id);
}
}
}
set_pev(ent, pev_nextthink, get_gametime() + 60.0);
return FMRES_HANDLED;
}
add_interest(id)
{
new Float:temp = float( bankstorage[id] );
if ( temp <= 0.0 || temp > 100000.0 ) return;
temp *= get_pcvar_float(pcvars[interest]);
new temp2 = floatround(temp);
if ( temp2 < 0 || temp2 > get_pcvar_num(pcvars[charge]) )
return;
localchange(id, temp2);
public handle_say(id)
{
if ( !get_pcvar_num(pcvars[enable]) || lock_cmd[id] ) return PLUGIN_CONTINUE;
if (arg3[0] == 0)
{
//strip forward slash if present
if ( equali(arg1, "/", 1) ) format(arg1, 31, arg1[1]);
return PLUGIN_CONTINUE;
}
else if ( equali(arg1, "withdraw", 8) || equali(arg1, "take", 4) ||
equali(arg1, "retrieve", 8) )
{
if ( isdigit(arg2[0]) || (arg2[0] == '-' && isdigit(arg2[1])) )
{
new value = str_to_num(arg2);
take_cash(id, value);
return PLUGIN_HANDLED;
}
else if ( equali(arg2, "all") )
{
take_cash(id, -1);
return PLUGIN_HANDLED;
}
else if ( arg2[0] == 0 )
zp_colored_print(id, "^x04[%s]^x03 to withdraw ammo packs
from bank say withdraw <amount to withdraw>", plugin);
return PLUGIN_CONTINUE;
}
else if ( equali(arg1, "mybank", 6) || equali(arg1, "account", 7) ||
equali(arg1, "bank", 4) )
{
if ( arg2[0] == 0 ) {
zp_colored_print(id, "^x04[%s]^x03 Currently your
[%s]account has %d ammo packs in it",plugin,special[id] ? "advanced" : "regular",
bankstorage[id]);
return PLUGIN_HANDLED;
}
else {
new player = cmd_target(id,arg2,2);
if ( !player ) return PLUGIN_CONTINUE;
zp_colored_print(id, "^x04[%s]^x03 %s has %d ammo packs",
plugin, arg2, bankstorage[player]);
return PLUGIN_HANDLED;
}
}
else if ( equali(arg1, "upgrade", 7) && equali(arg2, "account", 7) )
{
if ( !warning[id] )
upgrade_account(id);
else
do_upgrade(id);
}
}
return PLUGIN_CONTINUE;
}
public serverbank(id,level,cid)
{
if (!cmd_access(id,level,cid,1)) {
console_print(id,"You have no access to that command");
return;
}
if ( equali(arg, "all") )
{
for ( new i = 1; i < 33; i++ )
{
if ( !is_user_connected(i) ) continue;
player = 0
for( new i = 1; i <= 32; i++ )
{
if ( !is_user_connected(i) || is_user_bot(i) ) continue;
if ( !player )
{
server_print("Error locating player");
return;
}
server_print("[%s] %s has %d ammo packs", plugin, arg, bankstorage[player]);
}
upgrade_account(id)
{
if ( !get_pcvar_num(pcvars[account2]) ) return;
if ( special[id] )
{
zp_colored_print(id, "^x04[%s]^x03 You already have an advanced
account", plugin);
return;
}
else
{
zp_colored_print(id, "^x04[%s]^x03 You have opted to upgrade your bank
account type", plugin);
zp_colored_print(id, "^x04[%s]^x03 An upgraded account will earn you
%2.2f interest an hour", plugin, get_pcvar_float(pcvars[interest]));
new temp = bankstorage[id] + zp_get_user_ammo_packs(id);
if ( temp > get_pcvar_num(pcvars[charge]) )
{
zp_colored_print(id, "^x04[%s]^x03 There is a %d starting fee",
plugin, get_pcvar_num(pcvars[charge]) );
zp_colored_print(id, "^x04[%s]^x03 If you accept these conditions
simply retype ^"upgrade account^", and your account will be upgraded", plugin);
warning[id] = true;
}
else
zp_colored_print(id, "^x04[%s]^x03 You do not have the required
%d ammo packs to upgrade account yet", plugin, get_pcvar_num(pcvars[charge]) );
}
}
do_upgrade(id)
{
if ( !get_pcvar_num(pcvars[account2]) ) return;
public client_disconnect(id)
{
if ( get_pcvar_num(pcvars[auto]) )
store_cash(id, -1);
if ( bankstorage[id] > 0 ) save_data(id);
lock_cmd[id] = true; //basically this prevents players attempting to dupe
their ap by reconnecting
}
public client_putinserver(id)
set_task(1.0, "delayed_connect", id); //a small delay allows zp to load
all its data before we mess with it
public delayed_connect(id)
{
warning[id] = false;
special[id] = 0;
xploaded[id] = false;
bankstorage[id] = 0;
sessionstore[id] = 0;
clockstore[id] = -1;
lock_cmd[id] = false; //now they have officially connected and we allow
bank commands again
store_cash(id, amnt)
{
if ( !get_pcvar_num(pcvars[enable]) ) return;
take_cash(id, amnt)
{
if ( !get_pcvar_num(pcvars[enable]) ) return;
if ( amnt == 0 ) return; //otherwise a non terminal loop is possible
if ( amnt == -1 )
{
if ( special[id] )
{
zp_set_user_ammo_packs(id, bankstorage[id] - 1)
bankstorage[id] = 1;
}
else
{
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) +
bankstorage[id])
bankstorage[id] = 0;
}
}
else if ( amnt > 0 )
{
if ( bankstorage[id] >= amnt )
{
deduction(id);
deduction(id)
{
new temp = bankstorage[id] + zp_get_user_ammo_packs(id) - 1;
new temp2 = get_pcvar_num(pcvars[charge3]);
if ( temp >= temp2 )
{
if ( bankstorage[id] - 1 > temp2 )
localchange(id, -temp2);
else
{
temp2 -= ( bankstorage[id] - 1 );
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) - temp2);
bankstorage[id] = 1;
}
}
}
save_data(id)
{
if ( !xploaded[id] ) {
retrieve_data(id);
return;
}
new AuthID[35];
get_user_authid(id, AuthID, charsmax(AuthID));
if ( !strlen(AuthID) ) return;
temp = special[id] ? 1 : 0;
retrieve_data(id)
{
if ( xploaded[id] || !is_user_connected(id) ) return;
new AuthID[35];
get_user_authid(id, AuthID, charsmax(AuthID));
if ( !strlen(AuthID) ) return;
new vaultdata[64];
// If they have an account don't allow zombie mod to give them 5 ammo packs
at beggining
if ( get_pcvar_num(pcvars[start]) && bankstorage[id] > 0 )
zp_set_user_ammo_packs(id, 0);
if ( get_pcvar_num(pcvars[auto]) == 2 )
take_cash(id, -1);
}
#else
save_data(id)
{
if ( !xploaded[id] ) {
retrieve_data(id);
return;
}
new AuthID[35];
get_user_authid(id, AuthID, charsmax(AuthID));
if ( !strlen(AuthID) || bankstorage[id] <= 0 ) return;
retrieve_data(id)
{
new buffer[38], AuthID[35];
get_user_authid(id, AuthID, charsmax(AuthID));
if ( !strlen(AuthID) ) return;
buffer[0] = id;
copy(buffer[1], charsmax(buffer)-1, AuthID);
else
{
new ipacks = 0;
ipacks = SQL_ReadResult(hrquery, 0);
if ( get_pcvar_num(pcvars[auto]) == 2 )
take_cash(id, -1);
}
#endif
// Send to everyone
if (!target)
{
new player
for (player = 1; player <= 33; player++)
{
// Not connected
if ( !is_user_connected(player) || is_user_bot(player) )
continue;
// Send it
message_begin(MSG_ONE_UNRELIABLE, g_msgSayText, _, player)
write_byte(player)
write_string(buffer)
message_end()
// Send it
message_begin(MSG_ONE, g_msgSayText, _, target)
write_byte(target)
write_string(buffer)
message_end()
}
}
public native_retrieve_all_ap(id)
return zp_get_user_ammo_packs(id) + bankstorage[id];
public native_retrieve_ap(id)
return bankstorage[id];