so i did it that way but it still give the knife on respawn for all CT and it give them also after switch team to CT again not for the one who buy it only ( sorry if i type wrong )
PHP Code:
#include <amxmodx>
#include <fun>
#include <fakemeta>
#include <hamsandwich>
#include <gunxpmod>
#include <cstrike>
#define PLUGIN "Unlock Candy Knife"
#define VERSION "0.2"
#define AUTHOR "yas17sin"
#define ADMIN_ACCESS ADMIN_LEVEL_H
#define MAX_PLAYERS 32
enum Teams
{
Team_T = 1,
Team_CT
}
new g_iCurTeam[ MAX_PLAYERS + 1 ] = { 'U' , ... };
new KNIFE_V_MODEL[] = "models/v_Candy-knife.mdl"
new bool:g_KNIFE[33]
new bool:g_hasSpeed[33]
new cvar_knife_gore
new cvar_jump, cvar_dmgmult, cvar_knife_spd, cvar_knock
new const g_sound_knife[] = { "items/gunpickup2.wav" }
new const d_sounds[][] =
{
"Candy-Knife/knife_deploy1.wav",
"Candy-Knife/knife_hit1.wav",
"Candy-Knife/knife_hit2.wav",
"Candy-Knife/knife_hitwall.wav",
"Candy-Knife/knife_slash1.wav",
"Candy-Knife/knife_stab.wav"
}
new const oldknife_sounds[][] =
{
"weapons/knife_deploy1.wav",
"weapons/knife_hit1.wav",
"weapons/knife_hit2.wav",
"weapons/knife_hitwall1.wav",
"weapons/knife_slash1.wav",
"weapons/knife_stab.wav"
}
public plugin_init()
{
register_plugin(PLUGIN , VERSION , AUTHOR);
register_gxm_item("\wCandy Knife\r[ADMIN ACCESS]", " +speed +power +Knockback (Knife)", 250)
register_event( "TeamInfo" , "TeamInfo" , "a" );
register_event("CurWeapon","checkWeapon","be","1=1");
register_forward(FM_EmitSound, "fw_EmitSound");
register_forward(FM_PlayerPreThink, "fw_PlayerPreThink");
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage");
register_message(get_user_msgid("DeathMsg"), "message_DeathMsg");
cvar_knife_gore = register_cvar("knife_effect" , "1");
cvar_jump = register_cvar("knife_jump" , "380.0");
cvar_dmgmult = register_cvar("knife_dmg" , "5");
cvar_knife_spd = register_cvar("knife_spd" , "350.0");
cvar_knock = register_cvar("knife_power" , "17");
}
public gxm_item_enabled(id)
{
g_KNIFE[id] = true
g_hasSpeed[id] = true
}
public client_connect(id)
{
g_KNIFE[id] = false
g_hasSpeed[id] = false
}
public client_disconnect(id)
{
g_KNIFE[id] = false
g_hasSpeed[id] = false
}
public TeamInfo()
{
new id , szTeam[ 2 ];
id = read_data( 1 );
read_data( 2 , szTeam , charsmax( szTeam ) );
if ( g_iCurTeam[ id ] != szTeam[ 0 ] )
{
g_iCurTeam[ id ] = szTeam[ 0 ];
switch( szTeam[ 0 ] )
{
case 'T':
{
g_KNIFE[id] = false
g_hasSpeed[id] = false
}
case 'C':
{
g_KNIFE[id] = true
g_hasSpeed[id] = true
}
}
}
}
public plugin_precache()
{
precache_model(KNIFE_V_MODEL)
precache_sound(g_sound_knife)
for(new i = 0; i < sizeof d_sounds; i++)
precache_sound(d_sounds[i])
}
/*public buy_knife(id)
{
new flags = get_user_flags(id);
if( flags & ADMIN_ACCESS)
{
g_KNIFE[id] = true
g_hasSpeed[id] = true
engfunc(EngFunc_EmitSound, id, CHAN_BODY, g_sound_knife, 1.0, ATTN_NORM, 0, PITCH_NORM)
}
}*/
public checkWeapon(id)
{
new plrWeapId
plrWeapId = get_user_weapon(id)
if (plrWeapId == CSW_KNIFE && (g_KNIFE[id]))
{
checkModel(id)
}
}
public checkModel(id)
{
if (g_KNIFE[id])
{
set_pev(id, pev_viewmodel2, KNIFE_V_MODEL)
}
return PLUGIN_HANDLED
}
public fw_EmitSound(id, channel, const sound[])
{
if(!is_user_alive(id))
return FMRES_IGNORED
for(new i = 0; i < sizeof d_sounds; i++)
{
if(equal(sound, oldknife_sounds[i]))
{
if (g_KNIFE[id])
{
emit_sound(id, channel, d_sounds[i], 1.0, ATTN_NORM, 0, PITCH_NORM)
return FMRES_SUPERCEDE
}
if (!g_KNIFE[id])
{
emit_sound(id, channel, oldknife_sounds[i], 1.0, ATTN_NORM, 0, PITCH_NORM)
return FMRES_SUPERCEDE
}
}
}
return FMRES_IGNORED
}
public fw_PlayerPreThink(id)
{
if(!is_user_alive(id))
return FMRES_IGNORED
new temp[2], weapon = get_user_weapon(id, temp[0], temp[1])
if (weapon == CSW_KNIFE && g_KNIFE[id])
{
g_hasSpeed[id] = true
set_user_maxspeed(id, get_pcvar_float(cvar_knife_spd))
if ((pev(id, pev_button) & IN_JUMP) && !(pev(id, pev_oldbuttons) & IN_JUMP))
{
new flags = pev(id, pev_flags)
new waterlvl = pev(id, pev_waterlevel)
if (!(flags & FL_ONGROUND))
return FMRES_IGNORED
if (flags & FL_WATERJUMP)
return FMRES_IGNORED
if (waterlvl > 1)
return FMRES_IGNORED
new Float:fVelocity[3]
pev(id, pev_velocity, fVelocity)
fVelocity[2] += get_pcvar_num(cvar_jump)
set_pev(id, pev_velocity, fVelocity)
set_pev(id, pev_gaitsequence, 6)
}
}
return FMRES_IGNORED
}
public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
{
if(!is_user_connected(attacker))
return HAM_IGNORED
new weapon = get_user_weapon(attacker)
if (weapon == CSW_KNIFE && g_KNIFE[attacker])
{
SetHamParamFloat(4, damage * get_pcvar_float(cvar_dmgmult))
new Float:vec[3];
new Float:oldvelo[3];
pev(victim, pev_velocity, oldvelo);
create_velocity_vector(victim , attacker , vec);
vec[0] += oldvelo[0];
vec[1] += oldvelo[1];
set_pev(victim, pev_velocity, vec);
}
if(get_pcvar_num(cvar_knife_gore))
more_blood(victim)
return HAM_IGNORED
}
public message_DeathMsg(msg_id, msg_dest, id)
{
static szTruncatedWeapon[33], iattacker, ivictim
get_msg_arg_string(4, szTruncatedWeapon, charsmax(szTruncatedWeapon))
iattacker = get_msg_arg_int(1)
ivictim = get_msg_arg_int(2)
if(!is_user_connected(iattacker) || iattacker == ivictim)
return PLUGIN_CONTINUE
if(equal(szTruncatedWeapon, "knife") && get_user_weapon(iattacker) == CSW_KNIFE)
{
if(g_KNIFE[iattacker])
set_msg_arg_string(4, "Candy Knife")
}
if(equal(szTruncatedWeapon, "knife") && get_user_weapon(iattacker) == CSW_KNIFE)
{
if(!g_KNIFE[iattacker])
set_msg_arg_string(4, "knife")
}
return PLUGIN_CONTINUE
}
stock create_velocity_vector(victim,attacker,Float:velocity[3])
{
if(!is_user_alive(attacker))
return 0;
new Float:vicorigin[3];
new Float:attorigin[3];
pev(victim, pev_origin , vicorigin);
pev(attacker, pev_origin , attorigin);
new Float:origin2[3]
origin2[0] = vicorigin[0] - attorigin[0];
origin2[1] = vicorigin[1] - attorigin[1];
new Float:largestnum = 0.0;
if(floatabs(origin2[0])>largestnum) largestnum = floatabs(origin2[0]);
if(floatabs(origin2[1])>largestnum) largestnum = floatabs(origin2[1]);
origin2[0] /= largestnum;
origin2[1] /= largestnum;
if (g_KNIFE[attacker])
{
velocity[0] = ( origin2[0] * (get_pcvar_float(cvar_knock) * 3000) ) / floatround(get_distance_f(vicorigin, attorigin));
velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_knock) * 3000) ) / floatround(get_distance_f(vicorigin, attorigin));
}
if(velocity[0] <= 20.0 || velocity[1] <= 20.0)
velocity[2] = random_float(200.0 , 275.0);
return 1;
}
stock fm_set_user_maxspeed(index, Float:speed = -1.0)
{
engfunc(EngFunc_SetClientMaxspeed, index, speed);
set_pev(index, pev_maxspeed, speed);
return 1;
}
more_blood(id)
{
static iOrigin[3]
get_user_origin(id, iOrigin)
// Blood spray
message_begin(MSG_PVS, SVC_TEMPENTITY, iOrigin)
write_byte(TE_BLOODSTREAM)
write_coord(iOrigin[0])
write_coord(iOrigin[1])
write_coord(iOrigin[2]+10)
write_coord(random_num(-360, 360)) // x
write_coord(random_num(-360, 360)) // y
write_coord(-10) // z
write_byte(70) // color
write_byte(random_num(50, 100)) // speed
message_end()
for (new j = 0; j < 4; j++)
{
message_begin(MSG_PVS, SVC_TEMPENTITY, iOrigin)
write_byte(TE_WORLDDECAL)
write_coord(iOrigin[0]+random_num(-100, 100))
write_coord(iOrigin[1]+random_num(-100, 100))
write_coord(iOrigin[2]-36)
write_byte(random_num(190, 197)) // index
message_end()
}
}