/* Updated Throwing Knives by -]ToC[-Bludy
*
*
* COMMANDS: throw_knife - This is the command for everyone to throw knives
* say /knifehelp - Brings up knifehelp menu to help players bind keys
* say /throwingknives - Same as /knifehelp
*
* CVARS: amx_throwknives (default 0) Toggles Throwing Knives on and off ( 1 or 0 )
* amx_knifeammo (default 5) The amount of ammo to be given at roundstart ( 1 or higher )
* amx_knifetossforce (default 1200) Force at which knives are thrown ( 200 or higher )
* amx_maxknifeammo (default 10) Maximum amount of knives allowed at once ( 1 or higher )
* amx_knifedmg (default 25) Damage dealt on a knife hit ( 1 or higher )
* amx_dropknives (default 1) Toggles knife dropping on death on and off ( 1 or 0 )
*
* DROPPED FEATURES:
*
* - You must bind a key to throw_knife, USE + ATTACK was removed due to excess lag that likely does more harm than good
* - You can no longer drop your knives on command, only when you die
* - Team Attack system dropped, I am leaving your server admins in charge of punishment
*
* NEW FEATURES:
*
* - New knife model, more effecient, smaller file size, easier to download
* - New contact system, knife will stick to whatever they hit
* - New code which is less CPU intensive, less bugs, server crashing seems to be eliminated.
*
* DESCRIPTION:
*
* It was brought to my attention a few days ago that with the update to the AMX forums the file attached to the bottom
* of the forum topic had only an .amx file and no custom model. This gave me the motivation to create a new model that
* was smaller and faster to download, and a brand new knife system to make the knives more realistic. It took a few
* server crashes to get the code right, but it payed off in the end. A few of my clan members and I played throwing
* knife darts on one of the players sprays to celebrate.
*
* The knives work a lot better than before, and they are a lot of fun to play with. So get your knives out
* and go Have Fun
*
*/
#include <amxmod>
#include <fun>
#include <vexd_utilities>
new bool: knifeout[33]
new bool: g_delay[33]
new knifeammo[33]
new holdammo[33]
public plugin_init()
{
register_plugin("Throwing Knives","0.9.6","-]ToC[-Bludy")
register_event("ResetHUD","new_round","b")
register_event("CurWeapon","check_knife","b","1=1")
register_event("DeathMsg", "player_death", "a")
register_clcmd("throw_knife","command_knife",0,"- Throws a knife")
register_clcmd("say /knifehelp","knife_help")
register_clcmd("say /throwingknives","knife_help")
register_cvar("amx_throwknives","0")
register_cvar("amx_knifeammo","5")
register_cvar("amx_knifetossforce","1200")
register_cvar("amx_maxknifeammo","10")
register_cvar("amx_knifedmg","25")
register_cvar("amx_dropknives","1")
}
public player_death()
{
new id = read_data(2)
knife_drop(id)
return PLUGIN_HANDLED
}
public knife_drop(id)
{
if(get_cvar_num("amx_dropknives") == 0 || knifeammo[id] <= 0) return PLUGIN_HANDLED
new Float: Origin[3], Float: Velocity[3]
Entvars_Get_Vector(id, EV_VEC_origin, Origin)
new knifedrop = CreateEntity("info_target")
if(knifedrop == 0) {
return PLUGIN_HANDLED_MAIN
}
Entvars_Set_String(knifedrop, EV_SZ_classname, "knife_pickup")
ENT_SetModel(knifedrop, "models/w_knifepack.mdl")
new Float:MinBox[3] = {-1.0, -1.0, -1.0}
new Float:MaxBox[3] = {1.0, 1.0, 1.0}
Entvars_Set_Vector(knifedrop, EV_VEC_mins, MinBox)
Entvars_Set_Vector(knifedrop, EV_VEC_maxs, MaxBox)
ENT_SetOrigin(knifedrop, Origin)
Entvars_Set_Int(knifedrop, EV_INT_effects, 32)
Entvars_Set_Int(knifedrop, EV_INT_solid, 1)
Entvars_Set_Int(knifedrop, EV_INT_movetype, 6)
Entvars_Set_Edict(knifedrop, EV_ENT_owner, id)
VelocityByAim(id, 400 , Velocity)
Entvars_Set_Vector(knifedrop, EV_VEC_velocity ,Velocity)
holdammo[id] = knifeammo[id]
knifeammo[id] = 0
return PLUGIN_HANDLED
}
public knife_help(id)
{
new buffer[1024]
new len = copy( buffer , 1023 , "To use your knives have to bind a key to:^n^n\
throw_knife^n^n\
In order to bind a key you must open your console and use the bind command: ^n^n\
bind ^"key^" ^"command^" ^n^n" )
len += copy( buffer[len] , 1023-len , "In this case the command is ^"throw_knife^". Here are some examples:^n^n\
bind f throw_knife bind MOUSE3 throw_knife^n^n\
- If a knife is thrown, you may pick it up when it stops moving ^n\
- Knives are FF sensitive, you can hurt your teammates if FF is on^n\
- Your knife ammo will show in the center of your screen when you equip your knife^n" )
copy( buffer[len] , 1023-len ,"unless you have no knives^n- You will get credit for knife kills^n^n\
^nStart your knifing, Have fun!!" )
show_motd(id,buffer ,"Throwing Knife Help:")
return PLUGIN_HANDLED
}
public check_knife(id)
{
if(get_cvar_num("amx_throwknives") == 0) return PLUGIN_HANDLED
new weapon = read_data(2)
if(weapon == CSW_KNIFE)
{
knifeout[id] = true
if(knifeammo[id] >= 1) client_print(id, print_center,"You have %d knives",knifeammo[id])
}
else knifeout[id] = false
return PLUGIN_HANDLED
}
stock kill_all_entity(classname[]) {
new iEnt = FindEntity(-1, classname)
new tEnt
while(iEnt > 0)
{
tEnt = iEnt
iEnt = FindEntity(iEnt, classname)
RemoveEntity(tEnt)
}
}
public new_round(id)
{
if(knifeammo[id] < get_cvar_num("amx_knifeammo")) knifeammo[id] = get_cvar_num("amx_knifeammo")
g_delay[id] = false
kill_all_entity("throwing_knife")
kill_all_entity("knife_pickup")
}
public plugin_precache()
{
precache_sound("weapons/knife_hitwall1.wav")
precache_sound("weapons/knife_hit4.wav")
precache_sound("weapons/knife_deploy1.wav")
precache_model("models/w_knifepack.mdl")
precache_model("models/w_throwingknife.mdl")
}
public entity_touch(entity1, entity2)
{
if(entity1 > 0 && is_entity(entity1) && entity2 > 0 && is_entity(entity2)) {
new pToucher = entity1
new pTouched = entity2
new Classname[32]
Entvars_Get_String(pToucher, EV_SZ_classname, Classname, 31)
new owner = Entvars_Get_Edict(pToucher, EV_ENT_owner)
new Float: kOrigin[3]
Entvars_Get_Vector(pToucher, EV_VEC_origin, kOrigin)
if(equal(Classname,"knife_pickup"))
{
new Class2[32]
Entvars_Get_String(pTouched, EV_SZ_classname, Class2, 31)
if(!equal(Class2,"player") || knifeammo[pTouched] >= get_cvar_num("amx_maxknifeammo")) return PLUGIN_HANDLED
if((knifeammo[pTouched] + holdammo[owner]) > get_cvar_num("amx_maxknifeammo"))
{
knifeammo[pTouched] += get_cvar_num("amx_maxknifeammo") - knifeammo[pTouched]
holdammo[owner] -= get_cvar_num("amx_maxknifeammo") - knifeammo[pTouched]
emit_sound(pToucher, CHAN_ITEM, "weapons/knife_deploy1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}
else
{
knifeammo[pTouched] += holdammo[owner]
emit_sound(pToucher, CHAN_ITEM, "weapons/knife_deploy1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
RemoveEntity(pToucher)
}
client_print(pTouched, print_center,"You have %i knives",knifeammo[pTouched])
}
if(equal(Classname,"throwing_knife"))
{
if(get_user_health(pTouched))
{
new movetype = Entvars_Get_Int(pToucher, EV_INT_movetype)
if(movetype == 0 && knifeammo[pTouched] < get_cvar_num("amx_maxknifeammo"))
{
if(knifeammo[pTouched] < get_cvar_num("amx_maxknifeammo")) knifeammo[pTouched] += 1
client_print(pTouched,print_center,"You have %i knives",knifeammo[pTouched])
emit_sound(pToucher, CHAN_ITEM, "weapons/knife_deploy1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
RemoveEntity(pToucher)
}
else
{
if(owner == pTouched) return PLUGIN_HANDLED
Entvars_Set_Float(pTouched, EV_FL_dmg_take, get_cvar_num("amx_knifedmg") * 1.0)
if((get_user_health(pTouched) - get_cvar_num("amx_knifedmg")) <= 0)
{
MessageBlock(get_user_msgid("DeathMsg"),1)
user_kill(pTouched)
}
else set_user_health(pTouched, get_user_health(pTouched) - get_cvar_num("amx_knifedmg"))
if(get_user_team(pTouched) == get_user_team(owner))
{
new name[33]
get_user_name(owner,name,32)
client_print(0,print_chat,"%s attacked a teammate",name)
}
emit_sound(pTouched, CHAN_ITEM, "weapons/knife_hit4.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
if(!is_user_alive(pTouched))
{
if(get_user_team(pTouched) == get_user_team(owner)) set_user_frags(owner, get_user_frags(owner) - 2)
else set_user_frags(owner, get_user_frags(owner) + 1)
new gmsgScoreInfo = get_user_msgid("ScoreInfo")
new gmsgDeathMsg = get_user_msgid("DeathMsg")
set_user_frags(pTouched, get_user_frags(pTouched) + 1)
message_begin(MSG_ALL,gmsgScoreInfo)
write_byte(owner)
write_short(get_user_frags(owner) + 1)
write_short(get_user_deaths(owner))
write_short(0)
write_short(get_user_team(owner))
message_end()
message_begin(MSG_ALL,gmsgScoreInfo)
write_byte(pTouched)
write_short(get_user_frags(pTouched) + 1)
write_short(get_user_deaths(pTouched))
write_short(0)
write_short(get_user_team(pTouched))
message_end()
message_begin(MSG_ALL,gmsgDeathMsg,{0,0,0},0)
write_byte(owner)
write_byte(pTouched)
write_byte(0)
write_string("knife")
message_end()
}
RemoveEntity(pToucher)
return PLUGIN_HANDLED
}
}
Entvars_Set_Int(pToucher, EV_INT_movetype, 0)
emit_sound(pToucher, CHAN_ITEM, "weapons/knife_hitwall1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}
}
return PLUGIN_CONTINUE
}
public make_delay(pass[]) g_delay[pass[0]] = false
public command_knife(id)
{
if(!knifeout[id] || !is_user_alive(id) || g_delay[id] || knifeammo[id] == 0 || get_cvar_num("amx_throwknives") == 0) return PLUGIN_HANDLED
new pass[1]
pass[0] = id
set_task(0.5,"make_delay",987+id,pass,1)
g_delay[id] = true
knifeammo[id] -= 1
client_print(id,print_center,"You have %i knives",knifeammo[id])
new Float: Origin[3], Float: Velocity[3], Float: vAngle[3], Ent
Entvars_Get_Vector(id, EV_VEC_origin , Origin)
Entvars_Get_Vector(id, EV_VEC_v_angle, vAngle)
Ent = CreateEntity("info_target")
if(Ent == 0) {
return PLUGIN_HANDLED_MAIN
}
Entvars_Set_String(Ent, EV_SZ_classname, "throwing_knife")
ENT_SetModel(Ent, "models/w_throwingknife.mdl")
new Float:MinBox[3] = {-1.0, -7.0, -1.0}
new Float:MaxBox[3] = {1.0, 7.0, 1.0}
Entvars_Set_Vector(Ent, EV_VEC_mins, MinBox)
Entvars_Set_Vector(Ent, EV_VEC_maxs, MaxBox)
vAngle[0] -= 90
ENT_SetOrigin(Ent, Origin)
Entvars_Set_Vector(Ent, EV_VEC_angles, vAngle)
Entvars_Set_Int(Ent, EV_INT_effects, 2)
Entvars_Set_Int(Ent, EV_INT_solid, 1)
Entvars_Set_Int(Ent, EV_INT_movetype, 6)
Entvars_Set_Edict(Ent, EV_ENT_owner, id)
VelocityByAim(id, get_cvar_num("amx_knifetossforce") , Velocity)
Entvars_Set_Vector(Ent, EV_VEC_velocity ,Velocity)
return PLUGIN_HANDLED
}