#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#define VERSION "3.0"
new bank[33]
//new configfile[200]
new authid[33][32]
new pcvar
public plugin_init()
{
register_plugin("Simple CS Bank",VERSION,"GHW_Chronic")
pcvar = register_cvar("bank_save","0")
//new configsdir[200]
//get_configsdir(configsdir,199)
//format(configfile,199,"%s/bank.ini",configsdir)
register_dictionary("Bank.txt")
}
public client_putinserver(id)
{
if(!is_user_bot(id)) set_task(5.0,"client_authorized2",id)
}
public client_authorized2(id)
{
bank[id] = 0
if(get_pcvar_num(pcvar))
set_task(10.0,"read_file2",id)
set_task(0.1,"cpt",id,"",0,"b")
}
public client_disconnect(id)
{
if(!is_user_bot(id) && get_pcvar_num(pcvar))
save_money(id)
}
public cpt(id)
{
if(is_user_alive(id))
{
if(cs_get_user_money(id)>200000)
{
bank[id]+= cs_get_user_money(id) - 200000
cs_set_user_money(id,200000)
}
if(cs_get_user_money(id)<10)
{
if(bank[id] < 10 - cs_get_user_money(id))
{
cs_set_user_money(id,cs_get_user_money(id)+bank[id])
bank[id]=0
}
else
{
bank[id]-= 10 - cs_get_user_money(id)
cs_set_user_money(id,10)
}
}
// set_hudmessage(0, 255, 0, 0.7, 0.87, 0, 6.0, 0.1, 0.1, 0.2, next_hudchannel(id) )
// show_hudmessage(id,"%L",id,"MSG_BANK",bank[id])
}
}
public read_file2(id)
{
if(is_user_connected(id) )
{
get_user_authid(id,authid[id],31)
new read[32]
//new filepointer = fopen(configfile,"r")
//while(fgets(filepointer,read,31))
{
replace(read,31,"^n","")
if(equali(read,authid[id]))
{
//fgets(filepointer,read,31)
if(cs_get_user_money(id)<10)
{
if(cs_get_user_money(id) + str_to_num(read)<=10)
{
cs_set_user_money(id,cs_get_user_money(id) + str_to_num(read))
}
if(cs_get_user_money(id) + str_to_num(read)>10)
{
bank[id] += (str_to_num(read) + cs_get_user_money(id)) - 10
cs_set_user_money(id,10)
}
}
else
{
bank[id] += str_to_num(read)
}
return;
}
}
//fclose(filepointer)
}
}
public save_money(id)
{
new string[32]
format(string,31,"%d",bank[id])
new i, line
//new filepointer = fopen(configfile,"r")
//if(filepointer)
{
new read[32]
//while(fgets(filepointer,read,31))
{
replace(read,31,"^n","")
server_print("%d. %s",i,read)
if(equali(read,authid[id]))
{
line=1
return;
}
i++
}
}
//fclose(filepointer)
//if(!line) write_file(configfile,authid[id],i)
//write_file(configfile,string,i+1)
}