#include <amxmodx>
#include <cstrike>
#include <gamecms5>
#include <gamecms_achievs>
new szPluginInfo[][] = { "CMS Achevs Reward", "3.0", "ApXuTekToR" };
new szLogFileName[] = "CMSAchevs_Reward.log" // Название лог файла
// === Native's === //
// RBS
native ar_set_user_addxp(id, addxp);
native ar_add_user_anew(admin, player, anew);
native bonusmenu_add_user_points(id, points);
// AES
native aes_set_player_exp(player, Float:exp, bool:no_forward = false, bool:force = false);
native Float:aes_get_player_exp(player);
native aes_set_player_bonus(player,bonus,bool:force = false);
native aes_get_player_bonus(player);
#define aes_add_player_bonus_f(%0,%1) aes_set_player_bonus(%0,aes_get_player_bonus(%0) + %1)
#define aes_add_player_exp_f(%0,%1) aes_set_player_exp(%0,aes_get_player_exp(%0) + %1)
// CMS
native cmsranks_set_user_addxp(id, value);
native cmsranks_add_user_anew(id, value);
// === Native's === //
enum E_Cvars
{
Logging,
ChatInfo,
CvarFlags[16],
CvarAccess[16],
RewardMode,
RewardCount[32],
AddFlags[16],
IgnoreFlags[16],
BonusMenuRBS
}
new Cvar[E_Cvars], CheckPlugin;
enum E_Count
{
GameMoney,
GameExp,
GameBonus,
Float:RealMoney,
FlagsAccess,
} new g_Count[E_Count];
public plugin_natives()
set_native_filter("native_filter");
public native_filter(const name[], index, trap)
return trap ? PLUGIN_CONTINUE : PLUGIN_HANDLED;
public plugin_init()
{
register_plugin(szPluginInfo[0], szPluginInfo[1], szPluginInfo[2]);
register_dictionary("CMSAchevs_Reward.txt");
}
public plugin_cfg()
{
if(is_plugin_loaded("GameCMS_Achievs_Core") == INVALID_PLUGIN_ID)
{
log_amx("GameCMS_Achievs_Core is not loaded...");
pause("ad");
return;
}
if(is_plugin_loaded("Advanced Experience System") != -1)
CheckPlugin = 1;
else if(is_plugin_loaded("army_ranks_ultimate.amxx") != -1)
CheckPlugin = 2;
else if(is_plugin_loaded("CMSStats_Ranks") != -1)
CheckPlugin = 3;
else log_amx("[WARNING] Rank system is not running.");
new cfgFilePath[PLATFORM_MAX_PATH];
new const fileName[64] = "/gamecms/CMSAchevs_Reward.cfg";
get_localinfo("amxx_configsdir", cfgFilePath, charsmax(cfgFilePath));
add(cfgFilePath, charsmax(cfgFilePath), fileName);
if(file_exists(cfgFilePath)) {
server_cmd("exec %s", cfgFilePath);
server_exec();
initCvars();
} else {
server_print("[Error] [Config file not found (%s)] [Plugin stopped]", cfgFilePath);
set_fail_state("[Config file not found (%s)]", cfgFilePath);
}
}
initCvars() {
register_cvar("CMSAchevs_Logging", "0" );
register_cvar("CMSAchevs_ChatInfo", "1" );
register_cvar("CMSAchevs_RewardMode", "2" );
register_cvar("CMSAchevs_RewardCount", "500 10 2 1 1" );
register_cvar("CMSAchevs_AddFlags", "t" );
register_cvar("CMSAchevs_IgnoreFlags", "z" );
register_cvar("CMSAchevs_BonusMenuRBS", "0" );
get_cvar_string("CMSAchevs_RewardCount", Cvar[RewardCount], charsmax(Cvar[RewardCount]));
get_cvar_string("CMSAchevs_AddFlags", Cvar[AddFlags], charsmax(Cvar[AddFlags]));
get_cvar_string("CMSAchevs_IgnoreFlags", Cvar[IgnoreFlags], charsmax(Cvar[IgnoreFlags]));
Cvar[Logging] = get_cvar_num("CMSAchevs_Logging");
Cvar[ChatInfo] = get_cvar_num("CMSAchevs_ChatInfo");
Cvar[RewardMode] = get_cvar_num("CMSAchevs_RewardMode");
Cvar[BonusMenuRBS] = get_cvar_num("CMSAchevs_BonusMenuRBS");
if(Cvar[RewardCount])
{
new gm[9], ge[9], gb[9], rm[9], fa[3];
parse(Cvar[RewardCount],
gm, charsmax(gm),
ge, charsmax(ge),
gb, charsmax(gb),
rm, charsmax(rm),
fa, charsmax(fa)
)
g_Count[GameMoney] = str_to_num(gm);
g_Count[GameExp] = str_to_num(ge);
g_Count[GameBonus] = str_to_num(gb);
g_Count[RealMoney] = str_to_float(rm);
g_Count[FlagsAccess] = str_to_num(fa);
}
}
public OnAchievesCompleted(iClient) {
if(cmsapi_is_user_member(iClient) == 0) {
return PLUGIN_HANDLED;
}
new items;
if(Cvar[RewardMode] == 5)
items = random_num(0, 4);
else items = Cvar[RewardMode];
Rewarding(iClient, items);
return PLUGIN_HANDLED;
}
Rewarding(iClient, items)
{
new szMessage[32];
switch (items) {
case 0: {
if(!g_Count[GameExp])
return;
PlayerGivePlayerEXP(iClient, g_Count[GameExp]);
if(Cvar[ChatInfo]) formatex(szMessage, charsmax(szMessage), "%d %L", g_Count[GameExp], LANG_PLAYER, "CHAT_EXP");
if(Cvar[Logging] == 1) log_to_file(szLogFileName, "item: Exp | Geve: %d", g_Count[GameExp]);
}
case 1: {
if(!g_Count[GameBonus])
return;
PlayerGivePlayerAnew(iClient, g_Count[GameBonus]);
if(Cvar[ChatInfo]) formatex(szMessage, charsmax(szMessage), "%d %L", g_Count[GameBonus], LANG_PLAYER, "CHAT_BONUS");
if(Cvar[Logging] == 1) log_to_file(szLogFileName, "item: Anew | Geve: %d", g_Count[GameBonus]);
}
case 2: {
if(!g_Count[GameMoney])
return;
cs_set_user_money(iClient, cs_get_user_money(iClient) + g_Count[GameMoney]);
if(Cvar[ChatInfo]) formatex(szMessage, charsmax(szMessage), "%d %L", g_Count[GameMoney], LANG_PLAYER, "CHAT_GAMEMONEY");
if(Cvar[Logging] == 1) log_to_file(szLogFileName, "item: Game Money | Geve: %d", g_Count[GameMoney]);
}
case 3: {
if(!g_Count[RealMoney])
return;
cmsapi_add_user_money(iClient, g_Count[RealMoney]);
if(Cvar[ChatInfo]) formatex(szMessage, charsmax(szMessage), "%.2f %L", g_Count[RealMoney], LANG_PLAYER, "CHAT_REALMONEY");
if(Cvar[Logging] == 1) log_to_file(szLogFileName, "item: Game Money | Geve: %d", g_Count[RealMoney]);
}
case 4: {
if(!g_Count[FlagsAccess])
return;
if(Cvar[IgnoreFlags] && checkAccess(iClient, Cvar[IgnoreFlags]))
Rewarding(iClient, random_num(0, 3));
cmsapi_set_user_flags(iClient, Cvar[AddFlags], -1, "Привилегия за достижение", true);
if(Cvar[Logging] == 1) log_to_file(szLogFileName, "item: Flags | Geve: %s", Cvar[AddFlags]);
}
}
if(Cvar[ChatInfo]) {
if(items == 4)
{
client_print_color(iClient, 0, "%L", LANG_PLAYER, "CHAT_MESSAGE_2", iClient);
client_print_color(iClient, 0, "%L", LANG_PLAYER, "CHAT_MESSAGE_3");
} else client_print_color(iClient, 0, "%L", LANG_PLAYER, "CHAT_MESSAGE_1", iClient, szMessage);
}
}
stock PlayerGivePlayerEXP(index, count)
{
switch(CheckPlugin)
{
case 0: log_amx("[WARNING] [PlayerGivePlayerEXP] Rank system is not running.");
case 1: aes_add_player_exp_f(index, count);
case 2: ar_set_user_addxp(index, count);
case 3: cmsranks_set_user_addxp(index, count);
}
}
stock PlayerGivePlayerAnew(index, count)
{
switch(CheckPlugin)
{
case 0: log_amx("[WARNING] [PlayerGivePlayerAnew] Rank system is not running.");
case 1: aes_add_player_bonus_f(index, count);
case 2:
{
if(Cvar[BonusMenuRBS]) bonusmenu_add_user_points(index, count);
else ar_add_user_anew(-1, index, count);
}
case 3: cmsranks_add_user_anew(index, count);
}
}
checkAccess(id, const flags[])
{
return (get_user_flags(id) & read_flags(flags));
}