Код
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <dhudmessage>
#include <sqlx>
#define PLUGIN "Donate"
#define VERSION "1.0"
#define AUTHOR "Eazy*"
#pragma tabsize 0
new keysmenu = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
new cvar_showhudmsg
new donate[32]
new g_Block[66][16]
new SayText
new Host[] = "86.57.246.29"
new User[] = "hgm_nikitka"
new Pass[] = "l1gKUS1tbG"
new Db[] = "hgm_nikitka"
new Handle:g_SqlTuple
new g_Error[512]
public plugin_init() {
register_plugin("Donate", "1.0", "Eazy*")
register_concmd("say /donate", "a_shop")
register_menu("Menu 1", keysmenu, "SHop")
RegisterHam(Ham_Killed, "player", "killed")
cvar_showhudmsg = register_cvar("show_hudmsg", "0"); //1 - on 0 - off
SayText = get_user_msgid("SayText");
register_menu("Menu 2", keysmenu, "func_menu")
register_clcmd("amx_donate", "server_menu" )
}
public killed(victim, attacker, corpse) //смерть
{
if(get_user_flags(attacker) & ADMIN_LEVEL_H)
{
donate[attacker]++
}
}
public client_putinserver(id)
{
if(get_pcvar_num(cvar_showhudmsg))
set_task(1.0, "task_hudmsg", id, _, _, "b")
Load_MySql(id)
}
public task_hudmsg(id)
{
set_dhudmessage(255, 255, 0, -1.0, 0.80, 0, 6.0, 0.1)
show_dhudmessage(id, "Магазин доната: /donate^nБаланс: %d",donate[id])
}
public MySql_Init()
{
// we tell the API that this is the information we want to connect to,
// just not yet. basically it's like storing it in global variables
g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
// ok, we're ready to connect
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
if(SqlConnection == Empty_Handle)
// stop the plugin with an error message
set_fail_state(g_Error)
new Handle:Queries
// we must now prepare some random queries
Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS tutorial (steamid varchar(32),donate INT(11))")
if(!SQL_Execute(Queries))
{
// if there were any problems the plugin will set itself to bad load.
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
set_fail_state(g_Error)
}
// Free the querie
SQL_FreeHandle(Queries)
// you free everything with SQL_FreeHandle
SQL_FreeHandle(SqlConnection)
}
public plugin_end()
{
// free the tuple - note that this does not close the connection,
// since it wasn't connected in the first place
SQL_FreeHandle(g_SqlTuple)
}
public Load_MySql(id)
{
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
new Data[1]
Data[0] = id
//we will now select from the table `tutorial` where the steamid match
format(szTemp,charsmax(szTemp),"SELECT * FROM `tutorial` WHERE (`tutorial`.`steamid` = '%s')", szSteamId)
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}
public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
if(FailState == TQUERY_CONNECT_FAILED)
{
log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
}
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Load Query failed. [%d] %s", Errcode, Error)
}
new id
id = Data[0]
if(SQL_NumResults(Query) < 1)
{
//.if there are no results found
new szSteamId[32]
get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
// if its still pending we can't do anything with it
if (equal(szSteamId,"ID_PENDING"))
return PLUGIN_HANDLED
new szTemp[512]
// now we will insturt the values into our table.
format(szTemp,charsmax(szTemp),"INSERT INTO `tutorial` ( `steamid` , `donate`)VALUES ('%s','0');",szSteamId)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}
else
{
// if there are results found
donate[id] = SQL_ReadResult(Query, 1)
}
return PLUGIN_HANDLED
}
public Save_MySql(id)
{
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
// Here we will update the user hes information in the database where the steamid matches.
format(szTemp,charsmax(szTemp),"UPDATE `tutorial` SET `donate` = '%i' WHERE `tutorial`.`steamid` = '%s';",donate[id], szSteamId)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}
public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
SQL_FreeHandle(Query)
return PLUGIN_HANDLED
}
public client_disconnect(id)
{
Save_MySql(id)
}
public a_shop(id)
{
static menu[500], len
len = 0
new name[32]
get_user_name(id, name, 31)
if (cs_get_user_team(id) == CS_TEAM_T || cs_get_user_team(id) == CS_TEAM_CT)
{
len += formatex(menu[len], charsmax(menu) - len, "\wМагазин доната^n\wПривет \r%s^n\wВаш баланс: \r%d^n^n",name,donate[id])
if(donate[id] < 5)
len += formatex(menu[len], charsmax(menu) - len, "\d1. Обменять 5 доната на 5000$^n")
else
len += formatex(menu[len], charsmax(menu) - len, "\r1. \wОбменять 5 доната на 5000$^n")
if(donate[id] < 5)
len += formatex(menu[len], charsmax(menu) - len, "\d2. Обменять 5000$ на 5 доната^n")
else
len += formatex(menu[len], charsmax(menu) - len, "\r2. \wОбменять 5000$ на 5 доната^n")
if(donate[id] < 100)
len += formatex(menu[len], charsmax(menu) - len, "\d3. Купить VIP^n^n")
else
len += formatex(menu[len], charsmax(menu) - len, "\r3. \wКупить \rVIP^n^n")
len += formatex(menu[len], charsmax(menu) - len, "\r0. \wВыход^n")
show_menu(id, keysmenu, menu, -1, "Menu 1")
}
return PLUGIN_HANDLED
}
public SHop(id, key)
{
switch(key)
{
case 0:
{
if(donate[id] >= 5)
{
new MyMoney[32]
MyMoney[id] = cs_get_user_money(id)
cs_set_user_money(id,MyMoney[id] + 5000)
print_col_chat(id, "^1[^4Магазин доната^1] Вы ^4успешно^1 обменяли^3 5 доната ^1на^3 5000$^1.")
donate[id] = donate[id] - 5
}
else
{
print_col_chat(id, "^1[^4Магазин доната^1] У Вас ^3недостаточно ^1монет.")
}
}
case 1:
{
if(donate[id] >= 5)
{
new MyMoney[32]
MyMoney[id] = cs_get_user_money(id)
cs_set_user_money(id,MyMoney[id] + 5000)
print_col_chat(id, "^1[^4Магазин доната^1] Вы ^4успешно^1 обменяли^3 5 доната ^1на^3 5000$^1.")
donate[id] = donate[id] - 5
}
else
{
print_col_chat(id, "^1[^4Магазин доната^1] У Вас ^3недостаточно ^1монет.")
}
}
case 2:
{
if(donate[id] >= 100)
{
//new MyMoney[32]
//MyMoney[id] = cs_get_user_money(id)
//cs_set_user_money(id,MyMoney[id] - 5000)
new name[32], authid[32], ip[16];
get_user_name(id, name, charsmax(name));
get_user_authid(id, authid, charsmax(authid));
get_user_ip(id, ip, charsmax(ip), 1);
donate[id] = donate[id] - 100
show_motd(id, "donate(vip).txt", "Информация");
log_to_file("donate(vip).log", "| Ник: %s | Steam ID: %s | IP: %s | Услуга: Заказ VIP на неделю.", name, authid, ip);
print_col_chat(0, "^4* ^1Игрок^3 %s ^1заказал ^4VIP^1 на неделю через '^3Магазин Доната^1'.", name)
}
else
{
print_col_chat(id, "^1[^4Магазин доната^1] У Вас ^3недостаточно ^1монет.")
}
}
}
}
public server_menu(id)
{
new name[32]
get_user_name(id, name, 31)
static menu[650], len
len = 0
len += formatex(menu[len], charsmax(menu) - len, "\wРедактор доната^n\wПривет, \r%s^n^n", name)
len += formatex(menu[len], charsmax(menu) - len, "\r1. \wВыдать [\r10\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r2. \wВыдать [\r20\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r3. \wВыдать [\r30\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r4. \wВыдать [\r40\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r5. \wВыдать [\r50\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r6. \wВыдать [\r60\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r7. \wВыдать [\r70\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r8. \wВыдать [\r80\w] доната^n")
len += formatex(menu[len], charsmax(menu) - len, "\r9. \wВыдать [\r90\w] доната^n^n")
len += formatex(menu[len], charsmax(menu) - len, "\r0. \wВыход")
show_menu(id, keysmenu, menu, -1, "Menu 2")
return PLUGIN_HANDLED
}
public func_menu(id, key)
{
switch(key)
{
case 0:
{
g_Block[id][0] = true
MenuPlayer(id)
}
case 1:
{
g_Block[id][1] = true
MenuPlayer(id)
}
case 2:
{
g_Block[id][2] = true
MenuPlayer(id)
}
case 3:
{
g_Block[id][3] = true
MenuPlayer(id)
}
case 4:
{
g_Block[id][4] = true
MenuPlayer(id)
}
case 5:
{
g_Block[id][5] = true
MenuPlayer(id)
}
case 6:
{
g_Block[id][6] = true
MenuPlayer(id)
}
case 7:
{
g_Block[id][7] = true
MenuPlayer(id)
}
case 8:
{
g_Block[id][8] = true
MenuPlayer(id)
}
}
return PLUGIN_HANDLED
}
public MenuPlayer(id)
{
new i_Menu = menu_create("\wВыберите игрока^n", "menu_handle")
new s_Players[32], i_Num, i_Player
new s_Name[32], s_Player[10], text[128]
get_players(s_Players, i_Num)
for (new i; i < i_Num; i++)
{
i_Player = s_Players[i]
get_user_name(i_Player, s_Name, charsmax(s_Name))
num_to_str(i_Player, s_Player, charsmax(s_Player))
formatex(text, charsmax(text), "%s", s_Name)
menu_additem(i_Menu, text, s_Player, 0)
}
menu_setprop(i_Menu, MPROP_EXITNAME, "Выход")
menu_setprop(i_Menu, MPROP_NEXTNAME, "Далее")
menu_setprop(i_Menu, MPROP_BACKNAME, "Назад")
menu_display(id, i_Menu, 0)
}
public menu_handle(id, menu, item)
{
if (item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new s_Data[6], s_Name[64], i_Access, i_Callback
menu_item_getinfo(menu, item, i_Access, s_Data, charsmax(s_Data), s_Name, charsmax(s_Name), i_Callback)
new i_Player = str_to_num(s_Data)
new name[32], name2[32]
get_user_name(id, name, 31)
get_user_name(i_Player, name2, 31)
if(!is_user_connected(id))
{
print_col_chat(id, "^4* ^1Данный игрок ^3отключился^1 от сервера.")
menu_destroy(menu)
return PLUGIN_HANDLED
}
if(g_Block[id][0])
{
donate[id] = donate[id] + 10
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 10 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][1])
{
donate[id] = donate[id] + 20
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 20 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][2])
{
donate[id] = donate[id] + 30
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 30 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][3])
{
donate[id] = donate[id] + 40
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 40 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][4])
{
donate[id] = donate[id] + 50
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 50 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][5])
{
donate[id] = donate[id] + 60
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 60 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][6])
{
donate[id] = donate[id] + 70
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 70 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][7])
{
donate[id] = donate[id] + 80
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 80 монет^1 игроку ^3%s^1.", name, name2)
}
if(g_Block[id][8])
{
donate[id] = donate[id] + 90
print_col_chat(0, "^4* ^1Администратор ^3%s^1 выдал^4 90 монет^1 игроку ^3%s^1.", name, name2)
}
menu_destroy(menu)
return PLUGIN_HANDLED
}
stock print_col_chat(const id, const input[], any:...)
{
new count = 1, players[32];
static msg[191];
vformat(msg, 190, input, 3);
replace_all(msg, 190, "!g", "^4");
replace_all(msg, 190, "!y", "^1");
replace_all(msg, 190, "!t", "^3");
if (id) players[0] = id; else get_players(players, count, "ch");
{
for ( new i = 0; i < count; i++ )
{
if ( is_user_connected(players[i]) )
{
message_begin(MSG_ONE_UNRELIABLE, SayText, _, players[i]);
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
}