Untitled Diff
9 removals
80 lines
96 additions
167 lines
#include <amxmodx>
#include <amxmodx>
#include <engine>
#include <engine>
#include <reapi>
#include <reapi>
#include <csx>
new pcv_DropTime, pcv_GiveOwner;
#if AMXX_VERSION_NUM < 183
#include <dhudmessage>
#endif
new const szPluginInfo[][] = {"[ReAPI] C4 Control", "1.1", "ApXuTekToR"};
new pcv_DropTime;
new bool:g_BombDroped = false;
new bool:g_BombDroped = false;
new g_szIcons[][] = { "bombticking", "bombticking1" };
new g_mShowTimer, g_mRoundTime;
new g_mStatusIcon;
new g_pcvTimer, g_iTimer;
new bool:g_bRoundEnd;
public plugin_init() {
public plugin_init() {
register_plugin("[ReAPI] C4 Drop", "0.9", "a2 & F@nt0M");
register_plugin(szPluginInfo[0], szPluginInfo[1], szPluginInfo[2]);
RegisterHookChain(RG_CWeaponBox_SetModel, "CWeaponBox_SetModel", true);
RegisterHookChain(RG_CWeaponBox_SetModel, "CWeaponBox_SetModel", true);
RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "CBasePlayer_AddPlayerItem", true);
RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "CBasePlayer_AddPlayerItem", true);
register_event("HLTV", "eventRoundStart", "a", "1=0", "2=0");
register_logevent("eventRoundEnd", 2, "1=Round_End");
register_event("BombDrop", "eventBombPlanted", "a", "4=1");
pcv_DropTime = register_cvar("c4_drop_time", "10.0");
pcv_DropTime = register_cvar("c4_drop_time", "10.0");
pcv_GiveOwner = register_cvar("c4_give_owner", "-1.0");
g_mShowTimer= get_user_msgid("ShowTimer");
g_mRoundTime= get_user_msgid("RoundTime");
g_mStatusIcon= get_user_msgid("StatusIcon");
g_pcvTimer = get_cvar_pointer("mp_c4timer");
g_iTimer = get_pcvar_num(g_pcvTimer);
}
}
public CWeaponBox_SetModel(const ent) {
public CWeaponBox_SetModel(const ent) {
if (is_nullent(ent) || !isWeaponBoxC4(ent)) {
if (is_nullent(ent) || !isWeaponBoxC4(ent)) {
return HC_CONTINUE;
return HC_CONTINUE;
}
}
new player = get_entvar(ent, var_owner);
new player = get_entvar(ent, var_owner);
if (!is_user_alive(player)) {
if (!is_user_alive(player)) {
return HC_CONTINUE;
return HC_CONTINUE;
}
}
g_BombDroped = true;
g_BombDroped = true;
new data[1];
new data[1];
data[0] = ent;
data[0] = ent;
set_task(get_pcvar_float(pcv_DropTime), "TaskBomb", 100, data, sizeof data);
set_task(get_pcvar_float(pcv_DropTime), "TaskBomb", 100, data, sizeof data);
return HC_CONTINUE;
return HC_CONTINUE;
}
}
public CBasePlayer_AddPlayerItem(const id, const item) {
public CBasePlayer_AddPlayerItem(const id, const item) {
if (g_BombDroped && !is_nullent(item) && ItemID:get_member(item, m_iId) == ITEM_C4) {
if (g_BombDroped && !is_nullent(item) && ItemID:get_member(item, m_iId) == ITEM_C4) {
g_BombDroped = false;
g_BombDroped = false;
remove_task(100);
remove_task(100);
}
}
}
}
public TaskBomb(data[1]) {
public TaskBomb(data[1]) {
if (!g_BombDroped || !is_entity(data[0])) {
if (!g_BombDroped || !is_entity(data[0])) {
return;
return;
}
}
new player;
new player;
new Float:giveOwnerTime = get_pcvar_float(pcv_GiveOwner);
if (-1.0 < 0.0 || (-1.0 > 0.0 && (get_gametime() - get_member_game(m_fRoundStartTime)) < -1.0)) {
if (giveOwnerTime < 0.0 || (giveOwnerTime > 0.0 && (get_gametime() - get_member_game(m_fRoundStartTime)) < giveOwnerTime)) {
player = get_entvar(data[0], var_owner);
player = get_entvar(data[0], var_owner);
if (is_user_alive(player)) {
if (is_user_alive(player)) {
fake_touch(data[0], player);
fake_touch(data[0], player);
return;
return;
}
}
}
}
new players[MAX_PLAYERS], num;
new players[MAX_PLAYERS], num;
for (player = 1; player <= MaxClients; player++) {
for (player = 1; player <= MaxClients; player++) {
if (is_user_alive(player) && TeamName:get_member(player, m_iTeam) == TEAM_TERRORIST) {
if (is_user_alive(player) && TeamName:get_member(player, m_iTeam) == TEAM_TERRORIST) {
players[num++] = player;
players[num++] = player;
}
}
}
}
if (num > 0) {
if (num > 0) {
player = (num == 1) ? players[0] : random(num - 1);
player = (num == 1) ? players[0] : random(num - 1);
fake_touch(data[0], player);
fake_touch(data[0], player);
}
}
}
}
bool:isWeaponBoxC4(const ent) {
bool:isWeaponBoxC4(const ent) {
for (new i = 0, weapon; i < MAX_ITEM_TYPES; i++) {
for (new i = 0, weapon; i < MAX_ITEM_TYPES; i++) {
weapon = get_member(ent, m_WeaponBox_rgpPlayerItems, i);
weapon = get_member(ent, m_WeaponBox_rgpPlayerItems, i);
if (is_nullent(weapon)) {
if (is_nullent(weapon)) {
continue;
continue;
}
}
new WeaponIdType:wid = get_member(weapon, m_iId);
new WeaponIdType:wid = get_member(weapon, m_iId);
if (wid == WEAPON_C4) {
if (wid == WEAPON_C4) {
return true;
return true;
}
}
}
}
return false;
return false;
}
}
public eventRoundStart()
{
g_iTimer = get_pcvar_num(g_pcvTimer);
g_bRoundEnd = false;
}
public eventRoundEnd()
g_bRoundEnd = true;
public eventBombPlanted()
{
if(g_iTimer)
{
if(!g_bRoundEnd)
set_task(1.0, "ShowTimer");
}
else log_error(AMX_ERR_NATIVE, "cvar mp_c4timer not read!");
}
public bomb_planted(planter)
{
new planter_name[32];
get_user_name(planter, planter_name, charsmax(planter_name));
set_dhudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.25, 1, 6.0, 6.0, 0.1, 1.5);
show_dhudmessage(0, "Игрок [ %s ] установил бомбу!^nПоторопитесь!", planter_name);
}
public bomb_defused(defuser)
{
remove_task(8038);
new defuser_name[32];
get_user_name(defuser, defuser_name, charsmax(defuser_name));
set_dhudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), -1.0, 0.25, 1, 6.0, 6.0, 0.1, 1.5);
show_dhudmessage(0, "Игрок [ %s ] успел разминировать бомбу!^nПоздравляем!", defuser_name);
}
public ShowTimer()
{
message_begin(MSG_BROADCAST, g_mShowTimer);
message_end();
message_begin(MSG_BROADCAST, g_mRoundTime);
write_short(g_iTimer);
message_end();
static icon; icon = !icon;
new pl[32], pnum;
get_players(pl, pnum, "ac");
for(new i; i < pnum; i++)
{
message_begin(MSG_ONE, g_mStatusIcon, .player = pl[i]);
write_byte(2);
write_string(g_szIcons[icon]);
write_byte(0);
write_byte(160);
write_byte(0);
message_end();
}
}