#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <cstrike>
#include <fun>
/* ================= INFO ================= */
#define PLUGIN "Bank ~ Rendszer"
#define VERSION "1.0"
#define AUTHOR "Csabika20034"
#define MAXPLAYERS 32
#define HUD_UPDATE_TIME 5.0
#define LOAN_AUTOPAY_TIME 2592000 //
#define VIP_MONTH_PRICE 250
#define VIP_FOREVER_PRICE 500
#define VIP_MONTH_TIME 2592000 // 30 nap = 1 hó
/* ===== WEAPON PRICES ===== */
#define AK47_PRICE 300
#define M4A1_PRICE 300
#define AWP_PRICE 500
#define DEAGLE_PRICE 200
#define USP_PRICE 150
#define HE_PRICE 100
#define FLASH_PRICE 80
#define SMOKE_PRICE 80
/* ===== SQL ===== */
new const SQLINFO[][] =
{
"Kiszolgáló",
"Felhasználó",
"Jelszó",
"Adatbázis név"
}
new Handle:g_SqlTuple
/* ===== ADATOK ===== */
new credits[33]
new loan[33]
new loan_start[33]
new vip_type[33] // 0=none | 1=month | 2=forever
new vip_expire[33]
new steamid[33][35]
new pending_loan[33]
/* ================= INIT ================= */
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /bank", "bank_menu")
register_clcmd("say_team /bank", "bank_menu")
register_clcmd("say", "hook_say")
register_clcmd("say_team", "hook_say")
register_event("DeathMsg","eDeathMsg","a")
set_task(60.0, "loan_check", _, _, _, "b")
set_task(HUD_UPDATE_TIME, "hud_update", _, _, _, "b")
}
/* ================= SQL ================= */
public plugin_cfg()
{
g_SqlTuple = SQL_MakeDbTuple(
SQLINFO[0], SQLINFO[1], SQLINFO[2], SQLINFO[3]
)
static q[512]
formatex(q, charsmax(q),
"CREATE TABLE IF NOT EXISTS \\\`Banksystem\\\` (\
\\\`steamid\\\` VARCHAR(35) PRIMARY KEY,\
\\\`Credit\\\` INT,\
\\\`Loan\\\` INT,\
\\\`LoanStart\\\` INT,\
\\\`VipType\\\` INT,\
\\\`VipExpire\\\` INT);")
SQL_ThreadQuery(g_SqlTuple, "QueryIgnore", q)
}
public QueryIgnore(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:Time)
{
if(FailState != TQUERY_SUCCESS)
log_amx("SQL ERROR: %s", Error)
}
/* ================= PLAYER ================= */
public client_putinserver(id)
{
if(is_user_bot(id)) return
get_user_authid(id, steamid[id], charsmax(steamid[]))
Load(id)
}
public client_disconnected(id)
{
if(!is_user_bot(id))
Update(id)
}
/* ================= LOAD / SAVE ================= */
public Load(id)
{
static q[256]
new Data[1]; Data[0] = id
formatex(q, charsmax(q),
"SELECT * FROM \\\`Banksystem\\\` WHERE steamid=^"%s^";",
steamid[id])
SQL_ThreadQuery(g_SqlTuple, "QueryLoad", q, Data, 1)
}
public QueryLoad(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:Time)
{
if(FailState != TQUERY_SUCCESS) return
new id = Data[0]
if(SQL_NumRows(Query))
{
credits[id] = SQL_ReadResult(Query, 1)
loan[id] = SQL_ReadResult(Query, 2)
loan_start[id] = SQL_ReadResult(Query, 3)
vip_type[id] = SQL_ReadResult(Query, 4)
vip_expire[id] = SQL_ReadResult(Query, 5)
}
else
{
Save(id)
}
}
public Save(id)
{
static q[256]
formatex(q, charsmax(q),
"INSERT INTO \\\`Banksystem\\\` VALUES (^"%s^",0,0,0,0,0);",
steamid[id])
SQL_ThreadQuery(g_SqlTuple, "QueryIgnore", q)
}
public Update(id)
{
static q[256]
formatex(q, charsmax(q),
"UPDATE \\\`Banksystem\\\` SET Credit=%d,Loan=%d,LoanStart=%d,VipType=%d,VipExpire=%d \
WHERE steamid=^"%s^";",
credits[id], loan[id], loan_start[id],
vip_type[id], vip_expire[id], steamid[id])
SQL_ThreadQuery(g_SqlTuple, "QueryIgnore", q)
}
/* ================= CREDIT ON KILL ================= */
public eDeathMsg()
{
new killer = read_data(1)
new victim = read_data(2)
if(killer == victim || !is_user_connected(killer)) return
new credit = random_num(5,15)
credits[killer] += credit
client_print_color(killer, killer,
"^4[Server Name] ^1 Kaptál ^4%d^1 kreditet ölésért!", credit)
}
/* ================= BANK MENU ================= */
public bank_menu(id)
{
new m = menu_create("\yBANK MENÜ", "bank_handler")
menu_additem(m, "Kölcsön felvétele")
menu_additem(m, "Tartozás törlesztése")
menu_additem(m, "VIP bolt")
menu_additem(m, "Fegyver bolt")
menu_display(id, m)
}
public bank_handler(id, menu, item)
{
if(item == MENU_EXIT) return
switch(item)
{
case 0: loan_menu(id)
case 1: repay_loan(id)
case 2: vip_menu(id)
case 3: weapon_shop_menu(id)
}
}
/* ================= WEAPON SHOP ================= */
public weapon_shop_menu(id)
{
if(!is_user_alive(id))
{
client_print_color(id, print_team_default, "^4[Server Name]^1 Halottként nem vásárolhatsz!")
return
}
new m = menu_create("\yFEGYVER BOLT", "weapon_shop_handler")
menu_additem(m, "\rAK47 \y \r300 \wkredit")
menu_additem(m, "\rM4A1 \y \r300 \wkredit")
menu_additem(m, "\rAWP \y \r500 \wkredit")
menu_additem(m, "\rDeagle \y \r200 \wkredit")
menu_additem(m, "\rUSP \y \r150 \wkredit")
menu_additem(m, "\rHE Gránát \y \r100 \wkredit")
menu_additem(m, "\rVillanó \y \r80 \wkredit")
menu_additem(m, "\rFüst \y \r80 \wkredit")
menu_display(id, m)
}
public weapon_shop_handler(id, menu, item)
{
if(item == MENU_EXIT) return
new price
new weapon[32]
switch(item)
{
case 0: { price = AK47_PRICE; copy(weapon,31,"weapon_ak47"); }
case 1: { price = M4A1_PRICE; copy(weapon,31,"weapon_m4a1"); }
case 2: { price = AWP_PRICE; copy(weapon,31,"weapon_awp"); }
case 3: { price = DEAGLE_PRICE; copy(weapon,31,"weapon_deagle"); }
case 4: { price = USP_PRICE; copy(weapon,31,"weapon_usp"); }
case 5: { price = HE_PRICE; copy(weapon,31,"weapon_hegrenade"); }
case 6: { price = FLASH_PRICE; copy(weapon,31,"weapon_flashbang"); }
case 7: { price = SMOKE_PRICE; copy(weapon,31,"weapon_smokegrenade"); }
}
if(credits[id] < price)
{
client_print_color(id, print_team_default,"^4[Server Name] ^1Nincs elég^3kredited!")
return
}
credits[id] -= price
give_item(id, weapon)
client_print_color(id, print_team_default,"^4[Server Name]^1 Vásárlás sikeres! Maradt kredit:^3 %d", credits[id])
}
/* ================= LOAN ================= */
stock get_interest_percent(amount)
{
if(amount <= 300) return 10
if(amount <= 600) return 15
return 20
}
public loan_menu(id)
{
if(loan[id] > 0)
{
client_print_color(id, print_team_default, "^4[Server Name]^1 Már van aktív tartozásod, törlesztés után azonnal újra felvehetsz ^3hitelt!")
return
}
new m = menu_create("\yKÖLCSÖN", "loan_select")
menu_additem(m, "\r300 \wkredit")
menu_additem(m, "\r600 \wkredit")
menu_additem(m, "\r1000 \wkredit")
menu_display(id, m)
}
public loan_select(id, menu, item)
{
if(item == MENU_EXIT) return
pending_loan[id] = (item == 0) ? 300 : (item == 1) ? 600 : 1000
loan_confirm_menu(id)
}
public loan_confirm_menu(id)
{
new a = pending_loan[id]
new i = get_interest_percent(a)
new r = a + (a * i / 100)
new title[256]
format(title, charsmax(title),
"\yKölcsön megerősítés^nÖsszeg: %d^nKamat: %d%%^nVisszafizetés: %d",
a, i, r)
new m = menu_create(title, "loan_confirm_handler")
menu_additem(m, "Igen")
menu_additem(m, "Nem")
menu_display(id, m)
}
public loan_confirm_handler(id, menu, item)
{
if(item != 0) return
new a = pending_loan[id]
new i = get_interest_percent(a)
credits[id] += a
loan[id] = a + (a * i / 100)
loan_start[id] = get_systime()
client_print_color(id, print_team_default, "^4[Server Name]^1 Kölcsön felvéve!")
}
public repay_loan(id)
{
if(loan[id] <= 0) return
if(credits[id] < loan[id])
{
client_print_color(id, print_team_default, "^4[Server Name]^1 Nincs elég ^1kredit!")
return
}
credits[id] -= loan[id]
loan[id] = 0
client_print_color(id, print_team_default, "^4[Server Name] ^1Tartozás törlesztve!")
}
/* ================= AUTO LOAN ================= */
public loan_check()
{
for(new id=1; id<=32; id++)
{
if(!is_user_connected(id) || loan[id] <= 0) continue
if(get_systime() - loan_start[id] >= LOAN_AUTOPAY_TIME)
{
credits[id] = max(0, credits[id] - loan[id])
loan[id] = 0
client_print_color(id, print_team_default, "^4[Server Name] ^1 Tartozás ^3automatikusan ^1levonva!")
}
}
}
/* ================= VIP ================= */
public vip_menu(id)
{
new m = menu_create("\yVIP BOLT", "vip_handler")
menu_additem(m, "\rVIP \y1 \whónap - 250 kredit")
menu_additem(m, "\rVIP \yörök \w- 500 kredit")
menu_display(id, m)
}
public vip_handler(id, menu, item)
{
if(item == MENU_EXIT) return
if(item == 0 && credits[id] >= VIP_MONTH_PRICE)
{
credits[id] -= VIP_MONTH_PRICE
vip_type[id] = 1
vip_expire[id] = get_systime() + VIP_MONTH_TIME
client_print_color(id, print_team_default, "^4[Server Name]^3 1 ^1hónapos ^4VIP ^1aktiválva!")
}
else if(item == 1 && credits[id] >= VIP_FOREVER_PRICE)
{
credits[id] -= VIP_FOREVER_PRICE
vip_type[id] = 2
vip_expire[id] = 0
client_print_color(id, print_team_default, "^4[Server Name] ^1ÖRÖK ^3VIP ^1aktiválva!")
}
else
{
client_print_color(id, print_team_default, "^4[Server Name] Nincs elég ^3kredit!")
}
}
/* ================= CHAT ================= */
public hook_say(id)
{
new msg[192]
read_args(msg, charsmax(msg))
remove_quotes(msg)
if(!msg[0]) return PLUGIN_HANDLED
if(vip_type[id] == 1 && vip_expire[id] < get_systime())
{
vip_type[id] = 0
vip_expire[id] = 0
client_print_color(id, print_team_default, "^4[Server Name] ^3VIP ^1lejárt!")
}
new name[32]
get_user_name(id, name, charsmax(name))
if(vip_type[id] > 0)
client_print_color(0, id, "^4[VIP]^3 %s^1: %s", name, msg)
else
client_print_color(0, id, "^3%s^1: %s", name, msg)
return PLUGIN_HANDLED
}
/* ================= HUD ================= */
public hud_update()
{
for(new id=1; id<=32; id++)
{
if(!is_user_connected(id)) continue
set_hudmessage(0,255,0,0.02,0.90,0,0.0,HUD_UPDATE_TIME,0.0,0.0)
show_hudmessage(id,
"Kredit: %d^nTartozás: %d",
credits[id], loan[id])
}
}
/* ================= END ================= */
public plugin_end()
{
SQL_FreeHandle(g_SqlTuple)
}