#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#define PLUGIN "Cigarette"
#define VERSION "1.0"
#define AUTHOR "anakin_cstrike"
#define gravity 0.3
new
toggle,toggle_cost,toggle_hp,toggle_armor,
toggle_max,toggle_dur,toggle_bzone,toggle_speed,
toggle_effects,toggle_ehp,toggle_eint,
p_cost,p_hp,p_armor,p_max,p_dur,p_speed,
bool:g_Smoking[33],bool:g_Smoked[33],
g_Cigarette[33],g_Timer;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_PlayerPreThink,"fw_prethink");
register_event("CurWeapon", "hook_curwpn", "be", "1=1", "2!29");
register_event("ResetHUD","hook_reset","be");
register_event("Damage", "hook_damage", "b", "2!0", "3=0", "4!0");
register_event("DeathMsg","hook_death","a");
register_clcmd("say /cigarette","buy_cigarette");
register_clcmd("say /smoke","smoke_cigarette");
toggle = register_cvar("cigarette","1");
toggle_cost = register_cvar("cigarette_cost","1500");
toggle_hp = register_cvar("cigarette_hp","100");
toggle_armor = register_cvar("cigarette_armor","50");
toggle_max = register_cvar("cigarette_max","5");
toggle_speed = register_cvar("cigarette_speed","350");
toggle_dur = register_cvar("cigarette_smokeduration","10");
toggle_bzone = register_cvar("cigarette_buyzone","1");
toggle_effects = register_cvar("cigarette_effects","1");
toggle_ehp = register_cvar("cigarette_removehp","5");
toggle_eint = register_cvar("cigarette_removeinterval","3");
p_cost = get_pcvar_num(toggle_cost);
p_hp = get_pcvar_num(toggle_hp);
p_armor = get_pcvar_num(toggle_armor);
p_max = get_pcvar_num(toggle_max);
p_dur = get_pcvar_num(toggle_dur);
p_speed = get_pcvar_num(toggle_speed);
g_Timer = p_dur;
}
public client_disconnect(id)
{
g_Cigarette[id] = 0;
g_Smoking[id] = false;
g_Smoked[id] = false;
}
public client_connect(id)
{
g_Cigarette[id] = 0;
g_Smoking[id] = false;
g_Smoked[id] = false;
}
public buy_cigarette(id)
{
if(get_pcvar_num(toggle) != 1)
return PLUGIN_HANDLED;
if(!is_user_alive(id))
{
print(id,"You must be alive to buy a cigarette!");
return PLUGIN_HANDLED;
}
if(!cs_get_user_buyzone(id) && get_pcvar_num(toggle_bzone) == 1)
{
print(id,"You must be in buyzone to buy a cigarette!");
return PLUGIN_HANDLED;
}
new money = cs_get_user_money(id);
if(money < p_cost)
{
print(id,"Not enough money, you need $%d",p_cost);
center(id,"#Cstrike_TitlesTXT_Not_Enough_Money");
return PLUGIN_HANDLED;
}
if(g_Cigarette[id] >= p_max)
{
print(id,"You have already bought %d cigarettes",p_max);
center(id,"#Cstrike_TitlesTXT_Cannot_Carry_Anymore");
return PLUGIN_HANDLED;
}
cs_set_user_money(id,money - 1500,1);
g_Cigarette[id]++;
print(id,"You've bought a cigarette for $%d",p_cost);
return PLUGIN_CONTINUE;
}
public smoke_cigarette(id)
{
if(get_pcvar_num(toggle) != 1)
return PLUGIN_HANDLED;
if(!is_user_alive(id))
return PLUGIN_HANDLED;
if(!g_Cigarette[id])
{
print(id,"You have no cigarette to smoke!");
return PLUGIN_HANDLED;
}
if(g_Smoking[id])
{
print(id,"You are already smoking!");
return PLUGIN_HANDLED;
}
if(g_Smoked[id])
{
print(id,"You have already smoked a cigarette!");
return PLUGIN_HANDLED;
}
g_Smoking[id] = true;
message_begin(MSG_ONE,get_user_msgid("BarTime"),_,id);
write_short(p_dur);
message_end();
set_task(1.0,"countdown",id+123,_,_,"b");
set_task(float(p_dur),"smoking_over",id);
return PLUGIN_HANDLED;
}
public smoking_over(id)
{
if(!is_user_connected(id))
return PLUGIN_CONTINUE;
g_Smoking[id] = false;
g_Smoked[id] = true;
--g_Cigarette[id];
if(is_user_alive(id))
{
Render(id,kRenderFxGlowShell,165,165,165,kRenderNormal,15);
message_begin(MSG_ONE,get_user_msgid("SetFOV"),{0,0,0},id);
write_byte(170);
message_end();
set_pev(id,pev_armorvalue,float(p_armor));
HP(id,float(get_user_health(id)+p_hp));
Gravity(id,gravity);
Speed(id,float(p_speed));
if(get_pcvar_num(toggle_effects) == 1)
set_task(float(get_pcvar_num(toggle_eint)),"smoke_effects",id+54321,_,_,"b");
}
return PLUGIN_CONTINUE;
}
public smoke_effects(task)
{
new index = task-54321;
new hp = get_user_health(index);
new total = hp - get_pcvar_num(toggle_ehp);
if(total <= 0)
{
user_kill(index);
g_Smoked[index] = false;
Render(index,kRenderFxNone,0,0,0,kRenderNormal,255);
Gravity(index,1.0);
Speed(index,280.0);
} else
is_user_alive(index) ? HP(index,float(total)) : remove_task(index);
}
public hook_death()
{
new v = read_data(2);
g_Smoked[v] = false;
g_Smoking[v] = false;
if(task_exists(v+54321))
remove_task(v+54321);
Gravity(v,1.0);
Speed(v,280.0);
Render(v,kRenderFxNone,0,0,0,kRenderNormal,255);
}
public hook_reset(id)
{
if(task_exists(id+54321))
remove_task(id+54321);
message_begin(MSG_ONE,get_user_msgid("SetFOV"),{0,0,0},id);
write_byte(0);
message_end();
Render(id,kRenderFxNone,0,0,0,kRenderNormal,255);
g_Timer = p_dur;
}
public hook_curwpn(id)
{
if(!is_user_alive(id))
return PLUGIN_CONTINUE;
if(g_Smoking[id])
engclient_cmd(id,"weapon_knife");
return PLUGIN_CONTINUE;
}
public countdown(task)
{
new id = task - 123;
set_hudmessage(255, 255, 255, 0.02, 0.20, 0, 6.0, 2.0);
show_hudmessage(id, "Smoking: %d",g_Timer);
g_Timer--;
if(g_Timer <= 0)
{
if(task_exists(id+123))
remove_task(id+123);
g_Smoking[id] = false;
set_hudmessage(255, 255, 255, 0.02, 0.20, 0, 6.0, 3.0);
show_hudmessage(id, "Cigarette smoked!");
return;
}
}
public fw_prethink(id)
{
if(!is_user_alive(id))
return FMRES_IGNORED;
if(g_Smoking[id])
{
engclient_cmd(id,"weapon_knife");
Fade(id,165,165,165,75);
}
return FMRES_IGNORED;
}
public hook_damage(victim)
{
if(get_pcvar_num(toggle) != 1)
return PLUGIN_CONTINUE;
new attacker = get_user_attacker(victim);
if(get_user_team(attacker) == get_user_team(victim))
return PLUGIN_CONTINUE;
if(!g_Smoked[attacker])
return PLUGIN_CONTINUE;
if(g_Smoked[victim])
return PLUGIN_CONTINUE;
Fade(victim,165,165,165,75);
return PLUGIN_CONTINUE;
}
Render(index, fx=kRenderFxNone, r=255, g=255, b=255,render=kRenderNormal,amount=16)
{
set_pev(index, pev_renderfx, fx);
new Float:RenderColor[3];
RenderColor[0] = float(r);
RenderColor[1] = float(g);
RenderColor[2] = float(b);
set_pev(index, pev_rendercolor, RenderColor);
set_pev(index, pev_rendermode, render);
set_pev(index, pev_renderamt, float(amount));
return 1;
}
Fade(index,red,green,blue,alpha)
{
message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},index);
write_short(1<<10);
write_short(1<<10);
write_short(1<<12);
write_byte(red);
write_byte(green);
write_byte(blue);
write_byte(alpha);
message_end();
}
HP(index,Float:hp) set_pev(index,pev_health,hp);
Speed(index,Float:maxspeed) set_pev(index,pev_maxspeed,maxspeed);
Gravity(index,Float:grav) set_pev(index,pev_gravity,grav);
print(index,const message[],{Float,Sql,Result,_}:...)
{
new Buffer[128],Buffer2[128];
formatex(Buffer2,sizeof Buffer2 - 1,"%s",message);
vformat(Buffer, sizeof Buffer - 1, Buffer2, 3);
if(!is_user_connected(index)) return 0;
message_begin(MSG_ONE,get_user_msgid("SayText"),_,index);
write_byte(index);
write_string(Buffer);
message_end();
return 1;
}
center(index,const message[])
{
if(!is_user_connected(index)) return 0;
client_print(index,print_center,"%s",message);
return 1;
}