#include <amxmodx>
#include <amxmisc>
#include <reapi>
//#define CHAT_INFO // закомментировать если не нужно информирование в чат
//#define REWARD // закомментировать если не нужно выдавать дополнительную денежную награду за удачное разминирование
#if defined REWARD
#define MONEY 100 // сумма награды
#endif
new g_iEntity;
new bool:maphasdefuser = false;
new color[4][] = {"\rкрасный", "\yжелтый", "\wбелый", "\dсерый"};
public plugin_init(){
register_plugin( "Lucky Defuser", "1.0", "iPlague" ); // Ayk написал плагин Instant defuse, взял его за основу.
if(get_member_game(m_bMapHasBombTarget) == false){
pause("ad");
return;
}
RegisterHookChain( RG_CGrenade_DefuseBombStart, "DefuseBombStart_Pre", false );
RegisterHookChain(RG_CSGameRules_RestartRound, "event_round_start", false)
register_menucmd(register_menuid("DEFUSE_Menu"), (1<<0|1<<1|1<<2|1<<3|1<<5|1<<9), "HANDLER_DEFUSE");
}
public event_round_start(){
maphasdefuser = false;
close_menu();
}
public close_menu(){
new players[32], numberofplayers;
get_players_ex(players, numberofplayers, GetPlayers_ExcludeBots|GetPlayers_ExcludeHLTV);
for(new i=0; i < numberofplayers; i++)
show_menu(players[i], 0, "^n", 1);
maphasdefuser = false;
}
public DEFUSE_Menu(id){
maphasdefuser = true;
static pos, szMenu[512], keys; pos = 0;
keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<5)|(1<<9);
pos += formatex( szMenu[pos], charsmax(szMenu)-pos, "[LD] Какой провод перерезать?!^n");
for(new i=0; i<4;i++)
pos += formatex( szMenu[pos], charsmax(szMenu)-pos, "\w[%d] %s^n",i+1, color[i]);
pos += formatex( szMenu[pos], charsmax(szMenu)-pos, "^n\w[6] \rР\yИ\wС\dК^n^n^n^n\w[0] Закрыть");
return show_menu(id, keys, szMenu, -1, "DEFUSE_Menu");
}
public HANDLER_DEFUSE(id, key){
maphasdefuser = false;
switch(key){
case 0..3, 5:{
if(get_member_game(m_bTargetBombed) == true || rg_is_bomb_planted() == false){
#if defined CHAT_INFO
ChatColor(id,"[^4LD^1] Ошибочка вышла!");
#endif
return PLUGIN_HANDLED;
}
new name[32]; get_user_name(id,name,31);
if(random(100) < 100){
rg_send_bartime(id, 0);
//===========================================// не придумал верного способа =/
set_member_game(m_bBombDefused, true);
set_member_game(m_bTargetBombed, false);
set_member_game(m_iRoundWinStatus, 1); // 1 == CTs won last round
set_entvar(g_iEntity, var_flags, FL_KILLME);
rg_update_teamscores(1, 0, true);
rg_round_end(3.5, WINSTATUS_CTS, ROUND_BOMB_DEFUSED);
//===========================================//
#if defined CHAT_INFO
ChatColor(0,"[^4LD^1] %s обезвредил бомбу на последних секундах!", name);
#endif
#if defined REWARD
rg_add_account(id, MONEY, AS_ADD, true);
#endif
return PLUGIN_HANDLED;
}
else{
rg_send_bartime(id, 0);
set_member(g_iEntity, m_Grenade_flC4Blow, get_gametime());
#if defined CHAT_INFO
ChatColor(0,"[^4LD^1] %s не угадал с цветом :(", name);
#endif
return PLUGIN_HANDLED;
}
}
case 9: return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
public DefuseBombStart_Pre( const iEntity, const iPlayer ){
g_iEntity = iEntity;
new Float:fDefuseTime = get_member(iPlayer, m_bHasDefuser) ? 5.0 : 10.0;
new bool:bHasTime = (Float:get_member(iEntity, m_Grenade_flC4Blow) - get_gametime() > fDefuseTime);
if(!bHasTime && !maphasdefuser)
DEFUSE_Menu(iPlayer)
}
stock ChatColor(const id, const szMessage[], any:...){
static msg[191];
vformat(msg, 190, szMessage, 3);
replace_all(msg, 190, "!g", "^4");
replace_all(msg, 190, "!y", "^1");
replace_all(msg, 190, "!t", "^3");
format(msg, 190, "^x01%s", msg);
msg[190] = '^0';
if(id && is_user_connected(id)) {
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, id);
write_byte(id);
write_string(msg);
message_end();
}
else{
for(new i = 1; i <= get_maxplayers(); i++){
if(!is_user_connected(i))
continue;
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, i);
write_byte(i);
write_string(msg);
message_end();
}
}
return 1;
}