/*================================================================================
[NST Wpn] Extra Item: Knife
Tac gia: NST
Team: Humans
Cong dung: Mot vu khi moi cho Human
Cvars:
- nst_cv47_dmg <3> - Uy luc cua sung
- nst_cv47_uclip <1|0> - Bang dan vo han ?
- nst_cv47_speed <1> - Toc do ban cua sung (cang nho thi cang ban nhanh)
- nst_cv47_zoom <1|0> - Zoom sung ?
- nst_cv47_clip <50> - So dan trong 1 bang
- nst_cv47_ammo <200> - Tong so dan cua sung
- nst_cv47_recoil <0> - Do giat cua sung
- nst_cv47_cost <4000> - Gia cua sung
================================================================================*/
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <fun>
#include <hamsandwich>
#include <cstrike>
#include <engine>
// Info Plugin
#define VERSION "1.0"
#define AUTHOR "NST"
// Info Weapon
#define CURENT_WEAPON CSW_KNIFE
new models_weapon[64] = "sword"
new name_weapon[64] = "Kiem san nguoi"
new plugin_name[64] = "NST Wpn %s"
new cmd_buy[64] = "nst_%s"
new name_class_weapon[64] = "nst_%s"
new V_MODEL[64] = "models/nst_wpn/v_%s.mdl"
new P_MODEL[64] = "models/nst_wpn/p_%s.mdl"
new cvar_dmg_name[64] = "nst_%s_dmg"
new cvar_uclip_name[64] = "nst_%s_uclip"
new cvar_speed_name[64] = "nst_%s_speed"
new cvar_zoom_name[64] = "nst_%s_zoom"
new cvar_clip_name[64] = "nst_%s_clip"
new cvar_ammo_name[64] = "nst_%s_ammo"
new cvar_recoil_name[64] = "nst_%s_recoil"
new cvar_cost_name[64] = "nst_%s_cost"
#define is_valid_player(%1) (1 <= %1 <= 32)
new user_clip[33], user_ammo[33]
new cost_by_ammo = 60
new cvar_dmgmultiplier, cvar_uclip, cvar_speed, cvar_zoom, cvar_clip, cvar_ammo, cvar_recoil, cvar_cost
new bool:G_HasWp[33]
new g_hasZoom[ 33 ]
const Wep_drop = ((1<<CURENT_WEAPON))
new szWeapon[17]
new Float:cl_pushangle[33][3]
////////////////////////////////// Ammo //////////////////////////////////
const SILENT_BS = ((1<<CSW_USP)|(1<<CURENT_WEAPON))
// weapons offsets
const m_pPlayer = 41
const m_iId = 43
const m_fKnown = 44
const m_flNextPrimaryAttack = 46
const m_flNextSecondaryAttack = 47
const m_flTimeWeaponIdle = 48
const m_iPrimaryAmmoType = 49
const m_iClip = 51
const m_fInReload = 54
const m_fInSpecialReload = 55
const m_fSilent = 74
const m_flNextAttack = 83
const m_rgAmmo_player_Slot0 = 376
stock const g_iDftMaxClip[CSW_P90+1] = {
-1, 13, -1, 10, 1, 7, 1, 30, 30, 1, 30,
20, 25, 30, 35, 25, 12, 20, 10, 30, 100,
8 , 30, 30, 20, 2, 7, 30, 30, -1, 50}
stock const g_iReloadAnims[CSW_P90+1] = {
-1, 5, -1, 3, -1, 6, -1, 1, 1, -1, 14,
4, 2, 3, 1, 1, 13, 7, 4, 1, 3,
6, 11, 1, 3, -1, 4, 1, 1, -1, 1}
stock const Float:g_fDelay[CSW_P90+1] = {
0.00, 2.70, 0.00, 2.00, 0.00, 0.55, 0.00, 3.15, 3.30, 0.00, 4.50,
2.70, 3.50, 3.35, 2.45, 3.30, 2.70, 2.20, 2.50, 2.63, 4.70,
0.55, 3.05, 2.12, 3.50, 0.00, 2.20, 3.00, 2.45, 0.00, 3.40
}
new const AMMOID[] = { -1, 9, -1, 2, 12, 5, 14, 6, 4, 13, 10, 7, 6, 4, 4, 4, 6, 10,
1, 10, 3, 5, 4, 10, 2, 11, 8, 4, 2, -1, 7 }
public plugin_init()
{
// Create value
format(V_MODEL, 63, V_MODEL, models_weapon)
format(P_MODEL, 63, P_MODEL, models_weapon)
format(cvar_dmg_name, 63, cvar_dmg_name, models_weapon)
format(cvar_uclip_name, 63, cvar_uclip_name, models_weapon)
format(cvar_speed_name, 63, cvar_speed_name, models_weapon)
format(cvar_zoom_name, 63, cvar_zoom_name, models_weapon)
format(cvar_clip_name, 63, cvar_clip_name, models_weapon)
format(cvar_ammo_name, 63, cvar_ammo_name, models_weapon)
format(cvar_recoil_name, 63, cvar_recoil_name, models_weapon)
format(cvar_cost_name, 63, cvar_cost_name, models_weapon)
format(plugin_name, 63, plugin_name, name_weapon)
format(cmd_buy, 63, cmd_buy, models_weapon)
format(name_class_weapon, 63, name_class_weapon, models_weapon)
register_plugin(plugin_name, VERSION, AUTHOR)
// Reg Cvar
cvar_dmgmultiplier = register_cvar(cvar_dmg_name, "2")
cvar_uclip = register_cvar(cvar_uclip_name, "0")
cvar_speed = register_cvar(cvar_speed_name,"1")
cvar_zoom = register_cvar(cvar_zoom_name,"0")
cvar_clip = register_cvar(cvar_clip_name,"1")
cvar_ammo = register_cvar(cvar_ammo_name,"1")
cvar_recoil = register_cvar(cvar_recoil_name,"0.4")
cvar_cost = register_cvar(cvar_cost_name,"1000")
//register_event("WeapPickup","checkModel","b","1=19")
register_event("CurWeapon","checkWeapon","be","1=1")
register_event("DeathMsg", "Death", "a")
register_event("HLTV", "event_start_freezetime", "a", "1=0", "2=0")
// Ham
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
get_weaponname(CURENT_WEAPON, szWeapon, charsmax(szWeapon))
RegisterHam(Ham_Item_PostFrame, szWeapon, "Item_PostFrame")
register_forward( FM_CmdStart, "fw_CmdStart" )
// Recoil
RegisterHam(Ham_Weapon_PrimaryAttack, szWeapon, "fw_primary_attack")
RegisterHam(Ham_Weapon_PrimaryAttack, szWeapon, "fw_primary_attack_post",1)
// Command
register_clcmd(cmd_buy,"buy_weapon")
register_clcmd("drop","cmd_drop", 0)
register_clcmd("buyammo1","buy_ammo", 0)
register_clcmd("primammo","buy_ammo", 0)
}
// Other Public
public plugin_precache()
{
format(V_MODEL, 63, V_MODEL, models_weapon)
format(P_MODEL, 63, P_MODEL, models_weapon)
precache_model(V_MODEL)
precache_model(P_MODEL)
}
public client_connect(id)
{
G_HasWp[id] = false
}
public client_disconnect(id)
{
G_HasWp[id] = false
}
public Death()
{
new id = read_data(2)
if(G_HasWp[id])
{
create_w_class(id, user_clip[id], user_ammo[id], 0)
G_HasWp[id] = false
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public event_start_freezetime()
{
remove_class_wpn()
}
// End Other Public
// Buy Weapon
public buy_weapon(id)
{
new plrClip, plrAmmo
get_user_weapon(id, plrClip , plrAmmo)
new user_money = cs_get_user_money(id);
new wp_cost = get_pcvar_num(cvar_cost);
new clip_max = get_pcvar_num(cvar_clip)
new ammo_max = get_pcvar_num(cvar_ammo)
if(!is_user_alive(id))
{
client_print(id, print_chat, "[NST Wpn] You can only buy %s when alive", name_weapon);
}
else if(user_money < wp_cost)
{
client_print(id, print_chat, "[NST Wpn] You can't afford that!");
}
else if(G_HasWp[id])
{
if (plrAmmo != ammo_max && user_money >= cost_by_ammo) buy_ammo(id)
else client_print(id, print_chat, "[NST Wpn] You already have a %s", name_weapon)
}
else
{
drop_prim(id)
show_hud_ammo(id, ammo_max)
give_weapon(id, clip_max, ammo_max)
cs_set_user_money(id, user_money-wp_cost)
client_print(id, print_chat, "[NST Wpn] You bought %s", name_weapon)
}
}
// End Buy Weapon
// Buy Ammo
public buy_ammo(id)
{
new plrClip, plrAmmo, plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
new clip_max = get_pcvar_num(cvar_clip)
new ammo_max = get_pcvar_num(cvar_ammo)
new ammo_show = (ammo_max-plrAmmo) + (clip_max-plrClip)
new user_money = cs_get_user_money(id)
if(plrWeapId == CURENT_WEAPON && G_HasWp[id] && user_money >= cost_by_ammo && plrAmmo != ammo_max)
{
show_hud_ammo(id, ammo_show)
cs_set_user_money(id, user_money-cost_by_ammo)
give_weapon(id, clip_max, ammo_max)
}
}
// End Buy Ammo
// Show Hud Ammo
public show_hud_ammo(id,ammo)
{
new clip_max = get_pcvar_num(cvar_clip)
if (ammo<=clip_max) fun_show_ammo(id, ammo)
else
{
new ammo_a = ammo % clip_max
new num_for = (ammo-ammo_a)/clip_max
for (new i = 1; i <= num_for; i++)
{
fun_show_ammo(id, clip_max)
}
if (ammo_a>0) fun_show_ammo(id, ammo_a)
}
}
fun_show_ammo(id, ammo)
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("AmmoPickup"), _, id)
write_byte(AMMOID[CURENT_WEAPON]) // ammo id
write_byte(ammo) // ammo amount
message_end()
}
// End Show Hud Ammo
// Check Weapon
public checkModel(id)
{
new szWeapID = read_data(2)
if ( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
{
set_pev(id, pev_viewmodel2, V_MODEL)
set_pev(id, pev_weaponmodel2, P_MODEL)
}
return PLUGIN_HANDLED
}
public checkWeapon(id)
{
new plrClip, plrAmmo, plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
if (plrWeapId == CURENT_WEAPON && G_HasWp[id])
{
checkModel(id)
// Speed
new Ent = get_weapon_ent(id,plrWeapId)
new Float:N_Speed
if(Ent)
{
N_Speed = get_pcvar_float(cvar_speed)
new Float:Delay = get_pdata_float( Ent, 46, 4) * N_Speed
if (Delay > 0.0) {
set_pdata_float( Ent, 46, Delay, 4)
}
}
}
return PLUGIN_HANDLED
}
// End Check Weapon
// Control Damage
public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CURENT_WEAPON && G_HasWp[attacker] )
{
SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
}
}
// End Control Damage
// Zoom Wepaon
public fw_CmdStart( id, uc_handle, seed )
{
if( !is_user_alive( id ) )
return PLUGIN_HANDLED
new szClip, szAmmo
new szWeapID = get_user_weapon( id, szClip, szAmmo )
if( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
{
// Zoom Weapon
if (get_pcvar_num(cvar_zoom))
{
if( ( get_uc( uc_handle, UC_Buttons ) & IN_ATTACK2 ) && !( pev( id, pev_oldbuttons ) & IN_ATTACK2 ) )
{
if(!g_hasZoom[id] == true)
{
g_hasZoom[id] = true
cs_set_user_zoom( id, CS_SET_AUGSG552_ZOOM, 0 )
client_cmd(id,"spk weapons/zoom")
}
else if (g_hasZoom[id])
{
g_hasZoom[ id ] = false
cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
}
}
}
// UClip
if (get_pcvar_num(cvar_uclip))
{
new ent = get_weapon_ent(id,CURENT_WEAPON)
cs_set_weapon_ammo(ent, get_pcvar_num(cvar_clip))
}
user_clip[id] = szClip
user_ammo[id] = szAmmo
}
if ( (g_hasZoom[ id ] && (pev(id, pev_button) & IN_RELOAD)) || (g_hasZoom[id] && szWeapID != CURENT_WEAPON) )
{
g_hasZoom[id] = false
cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
}
return PLUGIN_HANDLED
}
// End Zoom Wepaon
// Recoil of Weapon
public fw_primary_attack(ent)
{
new id = pev(ent,pev_owner)
pev(id,pev_punchangle,cl_pushangle[id])
return HAM_IGNORED
}
public fw_primary_attack_post(ent)
{
new id = pev(ent,pev_owner)
new szClip, szAmmo
new szWeapID = get_user_weapon( id, szClip, szAmmo )
if( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
{
new Float:push[3]
pev(id,pev_punchangle,push)
xs_vec_sub(push,cl_pushangle[id],push)
xs_vec_mul_scalar(push,get_pcvar_float(cvar_recoil),push)
xs_vec_add(push,cl_pushangle[id],push)
set_pev(id,pev_punchangle,push)
}
return HAM_IGNORED
}
// End Recoil of Weapon
// Drop Weapon
public cmd_drop(id)
{
new plrClip, plrAmmo
new plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
if(plrWeapId == CURENT_WEAPON && G_HasWp[id] && is_user_alive(id)) {
create_w_class(id, plrClip, plrAmmo, 1)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public create_w_class(id, clip, ammo, type)
{
new Float:Aim[3],Float:origin[3]
VelocityByAim(id, 64, Aim)
entity_get_vector(id,EV_VEC_origin,origin)
if (type == 1) {
origin[0] += 2*Aim[0]
origin[1] += 2*Aim[1]
}
new nst_cre_class = create_entity("info_target")
entity_set_string(nst_cre_class,EV_SZ_classname,name_class_weapon)
entity_set_size(nst_cre_class,Float:{-2.0,-2.0,-2.0},Float:{5.0,5.0,5.0})
entity_set_int(nst_cre_class,EV_INT_solid,1)
entity_set_int(nst_cre_class,EV_INT_movetype,6)
entity_set_int(nst_cre_class, EV_INT_iuser1, clip)
entity_set_int(nst_cre_class, EV_INT_iuser2, ammo)
entity_set_vector(nst_cre_class,EV_VEC_origin,origin)
G_HasWp[id] = false
remowegun(id)
}
// End Drop Weapon
// Remove Class Wepaons in new round
public remove_class_wpn()
{
new nextitem = find_ent_by_class(-1,name_class_weapon)
while(nextitem) {
remove_entity(nextitem)
nextitem = find_ent_by_class(-1,name_class_weapon)
}
return PLUGIN_CONTINUE
}
// End Remove Class Wepaons in new round
// Weapon Pickup
public pfn_touch(ptr, ptd) {
if(is_valid_ent(ptr)) {
new classname[32]
entity_get_string(ptr,EV_SZ_classname,classname,31)
if(equal(classname, name_class_weapon)) {
if(is_valid_ent(ptd)) {
new id = ptd
if(id > 0 && id < 34) {
if(!check_has_wpn(id) && !G_HasWp[id] && is_user_alive(id)) {
give_weapon(id,entity_get_int(ptr, EV_INT_iuser1), entity_get_int(ptr, EV_INT_iuser2))
remove_entity(ptr)
}
}
}
}
}
}
check_has_wpn(id)
{
new weapons[32], num, has_wpn = 0
get_user_weapons(id, weapons, num)
new type_wpn_cr = check_type_wpn(CURENT_WEAPON)
for (new i = 0; i < num; i++)
{
new type_wpn = check_type_wpn(weapons[i])
if (type_wpn == type_wpn_cr) has_wpn = 1
}
return has_wpn
}
// End Weapon Pickup
// Remove gun and save all guns
public remowegun(id) {
new wpnList[32]
new number
get_user_weapons(id,wpnList,number)
for (new i = 0;i < number ;i++) {
if (wpnList[i] == CURENT_WEAPON) {
fm_strip_user_gun(id, wpnList[i])
}
}
}
//Give wpn
public give_weapon(id, clip, ammo){
G_HasWp[id] = true
give_item(id,szWeapon)
cs_set_user_bpammo(id, CURENT_WEAPON, ammo)
new ent = get_weapon_ent(id,CURENT_WEAPON)
cs_set_weapon_ammo(ent, clip)
}
// Give Ammo Clip
public Item_PostFrame(iEnt)
{
static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)
new plrClip, plrAmmo, plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
if (plrWeapId == CURENT_WEAPON && G_HasWp[id])
{
static iId ; iId = get_pdata_int(iEnt, m_iId, 4)
static iMaxClip ; iMaxClip = get_pcvar_num(cvar_clip)
static fInReload ; fInReload = get_pdata_int(iEnt, m_fInReload, 4)
static Float:flNextAttack ; flNextAttack = get_pdata_float(id, m_flNextAttack, 5)
static iAmmoType ; iAmmoType = m_rgAmmo_player_Slot0 + get_pdata_int(iEnt, m_iPrimaryAmmoType, 4)
static iBpAmmo ; iBpAmmo = get_pdata_int(id, iAmmoType, 5)
static iClip ; iClip = get_pdata_int(iEnt, m_iClip, 4)
if( fInReload && flNextAttack <= 0.0 )
{
new j = min(iMaxClip - iClip, iBpAmmo)
set_pdata_int(iEnt, m_iClip, iClip + j, 4)
set_pdata_int(id, iAmmoType, iBpAmmo-j, 5)
set_pdata_int(iEnt, m_fInReload, 0, 4)
fInReload = 0
}
static iButton ; iButton = pev(id, pev_button)
if( (iButton & IN_ATTACK2 && get_pdata_float(iEnt, m_flNextSecondaryAttack, 4) <= 0.0)
|| (iButton & IN_ATTACK && get_pdata_float(iEnt, m_flNextPrimaryAttack, 4) <= 0.0) )
{
return
}
if( iButton & IN_RELOAD && !fInReload )
{
if( iClip >= iMaxClip )
{
set_pev(id, pev_button, iButton & ~IN_RELOAD)
if( SILENT_BS & (1<<iId) && !get_pdata_int(iEnt, m_fSilent, 4) )
{
SendWeaponAnim( id, iId == CSW_USP ? 8 : 7 )
}
else
{
SendWeaponAnim(id, 0)
}
}
else if( iClip == g_iDftMaxClip[iId] )
{
if( iBpAmmo )
{
set_pdata_float(id, m_flNextAttack, g_fDelay[iId], 5)
if( SILENT_BS & (1<<iId) && get_pdata_int(iEnt, m_fSilent, 4) )
{
SendWeaponAnim( id, iId == CSW_USP ? 5 : 4 )
}
else
{
SendWeaponAnim(id, g_iReloadAnims[iId])
}
set_pdata_int(iEnt, m_fInReload, 1, 4)
set_pdata_float(iEnt, m_flTimeWeaponIdle, g_fDelay[iId] + 0.5, 4)
}
}
}
}
}
SendWeaponAnim(id, iAnim)
{
set_pev(id, pev_weaponanim, iAnim)
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, id)
write_byte(iAnim)
write_byte(pev(id,pev_body))
message_end()
}
// End Give Ammo Clip
// Stock
stock drop_prim(id)
{
new weapons[32], num
get_user_weapons(id, weapons, num)
for (new i = 0; i < num; i++)
{
new type_wpn = check_type_wpn(weapons[i])
new type_wpn_cr = check_type_wpn(CURENT_WEAPON)
if (type_wpn == type_wpn_cr)
{
static wname[32]
get_weaponname(weapons[i], wname, sizeof wname - 1)
engclient_cmd(id, "drop", wname)
G_HasWp[id] = false
}
}
}
//get weapon id
stock get_weapon_ent(id,wpnid=0,wpnName[]="")
{
// who knows what wpnName will be
static newName[24];
// need to find the name
if(wpnid) get_weaponname(wpnid,newName,23);
// go with what we were told
else formatex(newName,23,"%s",wpnName);
// prefix it if we need to
if(!equal(newName,"weapon_",7))
format(newName,23,"weapon_%s",newName);
return fm_find_ent_by_owner(get_maxplayers(),newName,id);
}
check_type_wpn(id_wpn)
{
new type_wpn = 0
if (id_wpn == CSW_SCOUT || id_wpn == CSW_XM1014 || id_wpn == CSW_MAC10 || id_wpn == CSW_AUG || id_wpn == CSW_UMP45 || id_wpn == CSW_SG550 || id_wpn == CSW_GALIL || id_wpn == CSW_FAMAS || id_wpn == CSW_AWP || id_wpn == CSW_MP5NAVY || id_wpn == CSW_M249 || id_wpn == CSW_M3 || id_wpn == CSW_M4A1 || id_wpn == CSW_TMP || id_wpn == CSW_G3SG1 || id_wpn == CSW_SG552 || id_wpn == CSW_AK47 || id_wpn == CSW_P90)
{
type_wpn = 1
}
else if (id_wpn == CSW_P228 || id_wpn == CSW_ELITE || id_wpn == CSW_FIVESEVEN || id_wpn == CSW_USP || id_wpn == CSW_GLOCK18 || id_wpn == CSW_DEAGLE)
{
type_wpn = 2
}
return type_wpn
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1034\\ f0\\ fs16 \n\\ par }