Well currently , you have probably know CSO-NST right ? I have his source code from beta 2. But the problem is the melee wpn that i add in can't stab correctly(delay). I mean the animation is't finished yet but the player has taken damage. I have the plugin here but i still don't figure out what it's used for
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>
#include <xs>
#include <engine>
#include <nst_zombie>
#include <nst_wpn>
// Var main
const TYPE_WPN = NST_WPN_KNIFE
const MAX_WPN = 32
const MAX_MYWPN = 6
new COUNT_WPN
new c_name[MAX_WPN][64]
new c_model[MAX_WPN][32]
new c_wpnchange[MAX_WPN]
new c_gravity[MAX_WPN]
new c_team[MAX_WPN]
new c_buy[MAX_WPN]
new c_knockback[MAX_WPN]
new Float:c_deploy[MAX_WPN]
new Float:c_damage[MAX_WPN]
new Float:c_time_attack[MAX_WPN]
new c_cost[MAX_WPN]
new c_model_p[MAX_WPN][64]
new c_model_v[MAX_WPN][64]
new c_model_v_bl[MAX_WPN][64]
new c_model_v_gr[MAX_WPN][64]
new c_sound_miss[MAX_WPN][64]
new c_sound_hitwall[MAX_WPN][64]
new c_sound_hit1[MAX_WPN][64]
new c_sound_hit2[MAX_WPN][64]
new c_sound_stab[MAX_WPN][64]
//for delay knife damage
const Float:def_first_attack = 0.5
const Float:def_second_attack = 1.2
const Float:def_range = 70.0
const Float:def_first_dmg_delay = 0.25
const Float:def_second_dmg_delay = 0.5
const Float:def_second_dmg = 100.0
new Float:g_fDelay[33]
enum
{
ANIM_IDLE,
ANIM_SLASH1,
ANIM_SLASH2,
ANIM_DRAW,
ANIM_STAB,
ANIM_STAB_MISS,
ANIM_MIDSLASH1,
ANIM_MIDSLASH2
}
// main value
new g_weapon[33], g_lastbuy[33], g_canbuy[33]
////for show weapon pickup///////////
new pre_weapon[64] = "0";
////////////////////////////
// my weapons
new g_mywpn[MAX_MYWPN], g_mywpn_cache[MAX_MYWPN][32], total_mywpn_cache
// section config
enum
{
SECTION_TYPE = 0,
SECTION_NAME,
SECTION_MODEL,
SECTION_WPNCHANGE,
SECTION_DAMAGE,
SECTION_GRAVITY,
SECTION_KNOCKBACK,
SECTION_DEPLOY,
SECTION_COST,
SECTION_TEAM,
SECTION_BUY,
SECTION_TIME_ATTACK
}
// Task offsets
enum (+= 100)
{
TASK_GIVEWPN = 2000,
TASK_GIVEWPNBOT
}
#define ID_GIVEWPN (taskid - TASK_GIVEWPN)
#define ID_GIVEWPNBOT (taskid - TASK_GIVEWPNBOT)
//for delay damage
#define task_execute_my_damage 25251325
new g_msgTextMsg
new g_hamczbots, cvar_botquota
// cs offsets value
const m_pPlayer = 41
const m_flNextPrimaryAttack = 46
const m_flNextSecondaryAttack = 47
const m_flTimeWeaponIdle = 48
const m_flNextAttack = 83
//##############################################################
// REGISTER PLUGIN
//##############################################################
public plugin_natives()
{
register_native("nst_wpn_give_weapon3", "natives_give_weapon", 1)
register_native("nst_wpn_get_int3", "natives_get_int", 1)
register_native("nst_wpn_get_float3", "natives_get_float", 1)
}
public plugin_precache()
{
// get list weapon cache
mywpn_create_ini(NST_WPN_INI_READ)
// load config
load_config_from_files()
// create mywpn
mywpn_create_mywpn()
}
public plugin_init()
{
register_plugin(NST_WPN_NAME_KNIFE, NST_WPN_VERSION, NST_WPN_AUTHOR)
// Language files
register_dictionary(NST_WPN_LANG_FILE)
// idmsg
g_msgTextMsg = get_user_msgid("TextMsg")
// Reg Public
register_event("CurWeapon","event_CurWeapon","be","1=1")
register_event("HLTV", "event_start_freezetime", "a", "1=0", "2=0")
register_forward(FM_EmitSound,"fw_emitsound")
RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
register_message(get_user_msgid("DeathMsg"), "message_DeathMsg")
// Reg Cmd
register_clcmd("nst_menu_wpn3", "cmd_menu_wpn")
register_clcmd("nst_rebuy_wpn3", "cmd_rebuy_wpn")
register_clcmd("nst_buy_wpn", "cmd_buy_wpn")
register_clcmd("nst_buy_mywpn", "cmd_buy_mywpn")
cvar_botquota = get_cvar_pointer("bot_quota")
//delay damage for knife
register_forward(FM_CmdStart, "fw_cmdstart")
register_forward(FM_UpdateClientData, "fm_update_data", 1)
}
public execute_my_damage(taskid)
{
new id = taskid - task_execute_my_damage
if (!is_user_alive(id))
return
if (get_user_weapon(id) != CSW_KNIFE)
return
// Find target
new Float:ftorigin[3]
new Float:faimOrigin[3], RetVec[3], Float:fRetVec[3]
new aimOrigin[3], target, body
get_user_origin(id, aimOrigin, 0)
get_user_aiming(id, target, body)
get_user_origin(id, RetVec, 4)
pev(target, pev_origin, ftorigin)
IVecFVec(aimOrigin, faimOrigin)
IVecFVec(RetVec, fRetVec)
new hitplace
new ent = find_ent_by_owner(-1, "weapon_knife", id)
if(target > 0 && target <= get_maxplayers())
{
new Float:range = vector_distance(faimOrigin, ftorigin)
if (range <= def_range)
{
if (body != 8)
{
if (!get_cvar_num("mp_friendlyfire"))
if (get_user_team(id) == get_user_team(target))
return
ExecuteHamB(Ham_TakeDamage, target, ent, id, def_second_dmg, DMG_SLASH)
ExecuteHamB(Ham_TraceAttack, target, id, def_second_dmg, fRetVec, body, DMG_SLASH)
//fakedamage(target, "", damage , DMG_BULLET)
if (body == HIT_HEAD)
hitplace = 1
if (body != HIT_HEAD)
hitplace = 0
new random_sound = random_num(1, 4)
new random_file[256]
format(random_file, 255, "weapons/knife_hit%d.wav", random_sound)
emit_sound(target, CHAN_AUTO, random_file, 1.0, ATTN_NORM, 0, PITCH_NORM)
//if (!is_user_alive(target))
// g4u_set_knife_kill(id, hitplace)
}
else
{
new random_sound = random_num(1, 2)
new random_file[256]
format(random_file, 255, "weapons/ric_metal-%d.wav", random_sound)
emit_sound(target, CHAN_AUTO, random_file, 1.0, ATTN_NORM, 0, PITCH_NORM)
}
}
}
else
{
if(target)
{
new torigin[3]
get_user_origin(id, torigin, 3)
IVecFVec(torigin, ftorigin)
new Float:range = vector_distance(faimOrigin, ftorigin)
if (range <= def_range)
{
new classname[32]
pev(target, pev_classname, classname, 31)
if (equal(classname, "hostage_entity", 14) || equal(classname, "monster_scientist", 17))
{
new Float:hdamage = random_float(80.0, 100.0)
fakedamage(target, "knife", hdamage , DMG_SLASH)
new health = pev(target, pev_health)
if (pev(target, pev_iuser1) < 1)
{
if (float(health) - hdamage > 0.0 )
{
client_print(id, print_center, "#Injured_Hostage")
cs_set_user_money(id, cs_get_user_money(id) - 300, 1)
}
else
{
client_print(id, print_center, "#Killed_Hostage")
cs_set_user_money(id, cs_get_user_money(id) - 3300, 1)
cs_set_user_hostagekills(id, cs_get_user_hostagekills(id) + 1)
set_pev(target, pev_iuser1, 1)
}
}
//ExecuteHamB(Ham_TakeDamage, target, ent, id, random_float(damage, damage * 1.5), DMG_SLASH)
}
if (equal(classname, "func_breakable", 14 ) || equal(classname, "func_pushable", 13))
{
new flags = pev(target, pev_spawnflags)
if (flags != SF_BREAK_TRIGGER_ONLY)
ExecuteHamB(Ham_TakeDamage, target, ent, id, random_float(80.0, 100.0), DMG_SLASH)
//fakedamage(target, hud, random_float(damage, damage * 1.7) , DMG_SLASH)
emit_sound(id, CHAN_AUTO, "weapons/knife_hitwall1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}
}
}
else
{
new torigin[3]
get_user_origin(id, torigin, 3)
IVecFVec(torigin, ftorigin)
new Float:range = vector_distance(faimOrigin, ftorigin)
if (range <= def_range)
emit_sound(id, CHAN_AUTO, "weapons/knife_hitwall1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}
}
}
public fm_update_data(id, sendweapon, cd_handle)
{
if (!is_user_alive(id))
return FMRES_IGNORED
if (get_user_weapon(id) != CSW_KNIFE)
return FMRES_IGNORED
set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.00001)
return FMRES_HANDLED
}
public fw_cmdstart(id, uchandle, seed)
{
if (!is_user_alive(id))
return FMRES_IGNORED
if (get_user_weapon(id) == CSW_KNIFE)
{
new button = get_uc(uchandle, UC_Buttons)
if (button & IN_ATTACK)
{
set_uc(uchandle, UC_Buttons, button &~IN_ATTACK)
if (get_gametime() - g_fDelay[id] >= def_first_attack)
{
new ent = find_ent_by_owner(-1, "weapon_knife", id)
ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
g_fDelay[id] = get_gametime()
set_pdata_float(ent, 46, def_first_attack, 4)
}
}
else if (button & IN_ATTACK2)
{
set_uc(uchandle, UC_Buttons, button &~IN_ATTACK2)
if (get_gametime() - g_fDelay[id] >= def_second_attack)
{
//if (task_exists(id + task_execute_my_damage))
//remove_task(id + task_execute_my_damage)
new ent = find_ent_by_owner(-1, "weapon_knife", id)
set_task(def_second_dmg_delay, "execute_my_damage", id + task_execute_my_damage)
SendWeaponAnim(id, ANIM_STAB)
g_fDelay[id] = get_gametime()
set_pdata_float(ent, 46, def_second_attack, 4)
}
}
}
return FMRES_IGNORED
}
//##############################################################
// LOAD CONFIG
//##############################################################
new data_name[64], data_model[32], data_wpnchange, Float:data_damage, data_gravity, data_cost, data_team, data_buy, data_knockback, Float:data_deploy, Float:data_time_attack
load_config_from_files()
{
// Build customization file path
new path[64]
get_configsdir(path, charsmax(path))
format(path, charsmax(path), "%s/%s", path, NST_WPN_SETTING_FILE)
// File not present
if (!file_exists(path))
{
new error[100]
formatex(error, charsmax(error), "Cannot load customization file %s!", path)
set_fail_state(error)
return;
}
// Set up some vars to hold parsing info
new linedata[1024], key[64], value[960]
// Open customization file for reading
new file = fopen(path, "rt")
new idwpn = 1
while (file && !feof(file))
{
// Read one line at a time
fgets(file, linedata, charsmax(linedata))
// Replace newlines with a null character to prevent headaches
replace(linedata, charsmax(linedata), "^n", "")
// Blank line or comment
if (!linedata[0] || linedata[0] == ';') continue;
// Replace
replace_all(linedata, charsmax(linedata), ",", "")
replace_all(linedata, charsmax(linedata), "[type]", ",")
replace_all(linedata, charsmax(linedata), "[name]", ",")
replace_all(linedata, charsmax(linedata), "[model]", ",")
replace_all(linedata, charsmax(linedata), "[wchange]", ",")
replace_all(linedata, charsmax(linedata), "[damage]", ",")
replace_all(linedata, charsmax(linedata), "[gravity]", ",")
replace_all(linedata, charsmax(linedata), "[knockback]", ",")
replace_all(linedata, charsmax(linedata), "[deploy]", ",")
replace_all(linedata, charsmax(linedata), "[cost]", ",")
replace_all(linedata, charsmax(linedata), "[team]", ",")
replace_all(linedata, charsmax(linedata), "[buy]", ",")
replace_all(linedata, charsmax(linedata), "[time_attack]", ",")
// Get value
strtok(linedata, key, charsmax(key), value, charsmax(value), ',')
new i
while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
{
switch (i)
{
case SECTION_NAME: format(data_name, charsmax(data_name), "%s", key)
case SECTION_MODEL: format(data_model, charsmax(data_model), "%s", key)
case SECTION_WPNCHANGE: data_wpnchange = str_to_num(key)
case SECTION_DAMAGE: data_damage = str_to_float(key)
case SECTION_GRAVITY: data_gravity = str_to_num(key)
case SECTION_KNOCKBACK: data_knockback = str_to_num(key)
case SECTION_DEPLOY: data_deploy = str_to_float(key)
case SECTION_COST: data_cost = str_to_num(key)
case SECTION_TEAM: data_team = str_to_num(key)
case SECTION_BUY: data_buy = str_to_num(key)
case SECTION_TIME_ATTACK: data_time_attack = str_to_num(key)
}
//client_print(0, print_chat, "STT[%i] VL[%s]", i, key)
i++
}
// no cache weapon can't buy
if (!data_buy && !nst_wpn_get_mod_has_supplybox()) continue;
// Set Value
if (nst_get_weapon_type(data_wpnchange) == TYPE_WPN)
{
// Set Value
format(c_name[idwpn], 63, "%s", data_name)
format(c_model[idwpn], 31, "%s", data_model)
c_wpnchange[idwpn] = data_wpnchange
c_gravity[idwpn] = data_gravity
c_team[idwpn] = data_team
c_buy[idwpn] = data_buy
c_knockback[idwpn] = data_knockback
c_deploy[idwpn] = data_deploy
c_damage[idwpn] = data_damage
c_cost[idwpn] = data_cost
c_time_attack[idwpn]= data_time_attack
// Precache
if ( !nst_wpn_mywpn() || (nst_wpn_mywpn() && mywpn_check_cached(data_model)) || (!data_buy && nst_wpn_get_mod_has_supplybox()) )
{
format(c_model_p[idwpn], 63, "models/nst_wpn/p_%s.mdl", data_model)
format(c_model_v[idwpn], 63, "models/nst_wpn/v_%s.mdl", data_model)
precache_model(c_model_p[idwpn])
//precache_model(c_model_v[idwpn])
//testing for bl&gr file v
format(c_model_v_bl[idwpn], 63, "models/nst_wpn/v_%s_BL.mdl", data_model)
format(c_model_v_gr[idwpn], 63, "models/nst_wpn/v_%s_GR.mdl", data_model)
if(file_exists(c_model_v_bl[idwpn]))
precache_model(c_model_v_bl[idwpn])
else
precache_model(c_model_v[idwpn])
if(file_exists(c_model_v_gr[idwpn]))
precache_model(c_model_v_gr[idwpn])
format(c_sound_miss[idwpn], 63, "weapons/%s_miss.wav", data_model)
format(c_sound_hitwall[idwpn], 63, "weapons/%s_hitwall.wav", data_model)
format(c_sound_hit1[idwpn], 63, "weapons/%s_hit1.wav", data_model)
format(c_sound_hit2[idwpn], 63, "weapons/%s_hit2.wav", data_model)
format(c_sound_stab[idwpn], 63, "weapons/%s_stab.wav", data_model)
precache_sound(c_sound_miss[idwpn])
precache_sound(c_sound_hitwall[idwpn])
precache_sound(c_sound_hit1[idwpn])
precache_sound(c_sound_hit2[idwpn])
precache_sound(c_sound_stab[idwpn])
}
COUNT_WPN = idwpn
idwpn++
}
// check max wpn
if (idwpn == MAX_WPN) return;
//client_print(0, print_chat, "==[%i][%s]", idwpn, linedata)
}
}
//##############################################################
// MAIN PUBLIC
//##############################################################
public nst_zb_user_infected(id, infector)
{
if (nst_zb_get_user_zombie(id))
{
g_weapon[id] = 0
}
}
public client_disconnect(id)
{
g_weapon[id] = 0
}
public client_putinserver(id)
{
g_weapon[id] = 0
if (is_user_bot(id) && !g_hamczbots && cvar_botquota)
{
set_task(0.1, "register_ham_czbots", id)
}
}
public register_ham_czbots(id)
{
// Make sure it's a CZ bot and it's still connected
if (g_hamczbots || !is_user_connected(id) || !get_pcvar_num(cvar_botquota))
return;
RegisterHamFromEntity(Ham_Spawn, id, "fw_PlayerSpawn_Post", 1)
// Ham forwards for CZ bots succesfully registered
g_hamczbots = true
// If the bot has already spawned, call the forward manually for him
if (is_user_alive(id)) fw_PlayerSpawn_Post(id)
}
public event_start_freezetime()
{
new reset[33]
g_canbuy = reset
if (nst_zb_remove_weapons_newround()) g_weapon = reset
}
public message_DeathMsg()
{
// get value data
static killer, weapon[32], weaponid, victim//, headshot
killer = get_msg_arg_int(1)
victim = get_msg_arg_int(2)
//headshot = get_msg_arg_int(3)
get_msg_arg_string(4, weapon, charsmax(weapon))
if (equali(weapon, "grenade")) format(weapon, charsmax(weapon), "hegrenade")
format(weapon, charsmax(weapon), "weapon_%s", weapon)
weaponid = get_weaponid(weapon)
// get wpn sprites name
new attacker_wpn = g_weapon[killer]
if (attacker_wpn && weaponid==c_wpnchange[attacker_wpn])
{
// get sprites weapon
new sprites_wpn[32]
format(sprites_wpn, charsmax(sprites_wpn), "%s", c_model[attacker_wpn])
// send deathmsg
set_msg_arg_string(4, sprites_wpn)
}
// remove wpn of victim
g_weapon[victim] = 0
}
// Change Sound
public fw_emitsound(entity,channel,sample[],Float:volume,Float:attenuation,fFlags,pitch)
{
new id = entity
if (!is_user_connected(id))
return FMRES_IGNORED;
new CURENT_WEAPON = g_weapon[id]
new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
new plrClip, plrAmmo, plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
if (plrWeapId == CHANGE_WEAPON && g_weapon[id])
{
new sound_new[64]
if( (equal(sample,"weapons/knife_slash1.wav")) || (equal(sample,"weapons/knife_slash2.wav")) ) copy(sound_new, 63, c_sound_miss[CURENT_WEAPON])
else if(equal(sample,"weapons/knife_hitwall1.wav")) copy(sound_new, 63, c_sound_hitwall[CURENT_WEAPON])
else if( (equal(sample,"weapons/knife_hit1.wav")) || (equal(sample,"weapons/knife_hit3.wav"))) copy(sound_new, 63, c_sound_hit1[CURENT_WEAPON])
else if( (equal(sample,"weapons/knife_hit2.wav")) || (equal(sample,"weapons/knife_hit4.wav"))) copy(sound_new, 63, c_sound_hit2[CURENT_WEAPON])
else if(equal(sample,"weapons/knife_stab.wav")) copy(sound_new, 63, c_sound_stab[CURENT_WEAPON])
if (strlen(sound_new)) emit_sound(entity,channel,sound_new,volume,attenuation,fFlags,pitch)
return FMRES_SUPERCEDE
}
return FMRES_IGNORED;
}
// Ham Player Spawn Post Forward
public fw_PlayerSpawn_Post(id)
{
// Not alive or didn't join a team yet
if (!is_user_alive(id))
return;
new mod_runing = nst_get_mod_runing()
// set can buy in zb3
if (mod_runing == NST_MOD_ZB3)
{
g_canbuy[id] = 0
}
// give weapon in new round for scenario mod
else if (mod_runing == NST_MOD_HMS)
{
if (g_weapon[id])
{
static params[1]
params[0] = g_weapon[id]
if (task_exists(id+TASK_GIVEWPN)) remove_task(id+TASK_GIVEWPN)
set_task(0.1, "task_give_wpn", id+TASK_GIVEWPN, params, sizeof params)
}
}
// give random weapons for bot
if (is_user_bot(id))
{
new Float: time_give = random_float(2.0, 4.0)
if (task_exists(id+TASK_GIVEWPNBOT)) remove_task(id+TASK_GIVEWPNBOT)
set_task(time_give, "task_give_wpn_bot", id+TASK_GIVEWPNBOT)
}
}
public task_give_wpn(params[1], taskid)
{
new id = ID_GIVEWPN
give_weapon_mod(id, params[0])
}
public task_give_wpn_bot(taskid)
{
new id = ID_GIVEWPNBOT
new bot_use_wpn = random_num(0, nst_bot_use_weapons())
if (bot_use_wpn)
{
if (!g_weapon[id]) buy_weapon(id, get_random_weapon())
}
}
get_random_weapon()
{
// check total weapon can buy
new total_canbuy = get_total_weapon_buy(1)
if (!total_canbuy) return 0;
// random weapon
new idwpn
// when use myweapons
if (nst_wpn_mywpn())
{
if (!total_mywpn_cache) return 0;
new i = random(total_mywpn_cache)
idwpn = get_idwpn_from_model(g_mywpn_cache[i])
return idwpn;
}
// when not use my weapons
else
{
for (new i=0; i<MAX_WPN; i++)
{
idwpn = random_num(1, COUNT_WPN)
if (c_buy[idwpn]) return idwpn;
}
}
return 0;
}
get_total_weapon_buy(buy)
{
new total
for (new i=1; i<=COUNT_WPN; i++)
{
if (c_buy[i]==buy) total++
}
return total;
}
// Give Weapon
public give_weapon(id)
{
if (!is_user_alive(id)) return;
new CURENT_WEAPON = g_weapon[id]
new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
// check wpn
if (!CHANGE_WEAPON) return;
// give wpn
new weaponname[32]
get_weaponname(CHANGE_WEAPON, weaponname, charsmax(weaponname))
fm_give_item(id, weaponname)
return;
}
// Check Weapon
public checkModel(id)
{
if (nst_zb_get_user_zombie(id)) return PLUGIN_HANDLED
new CURENT_WEAPON = g_weapon[id]
new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
new plrClip, plrAmmo, plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
if ( plrWeapId == CHANGE_WEAPON && g_weapon[id])
{
if(get_user_team(id)==1)
if (file_exists(c_model_v_bl[CURENT_WEAPON]))
set_pev(id, pev_viewmodel2,c_model_v_bl[CURENT_WEAPON])
else
set_pev(id, pev_viewmodel2, c_model_v[CURENT_WEAPON])
else
if (file_exists(c_model_v_gr[CURENT_WEAPON]))
set_pev(id, pev_viewmodel2,c_model_v_gr[CURENT_WEAPON])
else
set_pev(id, pev_viewmodel2,c_model_v[CURENT_WEAPON])
set_pev(id, pev_weaponmodel2, c_model_p[CURENT_WEAPON])
if(!is_user_bot(id))
{
/////////////////////write weapon name to file////////////////
new file_name[256]
format(file_name, 255, "/addons/amxmodx/configs/current_wpn_name.cfg")
write_file(file_name,c_model[g_weapon[id]], 0)
//////////////////////////////////////////////////////////////////
}
}
return PLUGIN_HANDLED
}
public fw_CmdStart(id, uc_handle, seed)
{
new CURENT_WEAPON = g_weapon[id]
static buttons
buttons = get_uc(uc_handle, UC_Buttons)
new Float:time_attack = c_time_attack[CURENT_WEAPON]
if ((buttons & IN_ATTACK2))
{
set_player_nextattack(id, time_attack)
}
}
public event_CurWeapon(id)
{
if (nst_zb_get_user_zombie(id)) return;
new CURENT_WEAPON = g_weapon[id]
new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
new plrClip, plrAmmo, plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
if (CURENT_WEAPON && plrWeapId==CHANGE_WEAPON)
{
checkModel(id)
}
if(CURENT_WEAPON==0 && !is_user_bot(id))
{
new WeaponNum = read_data(2) // read and store the weaponID
if(WeaponNum ==29)
{
/////////////////////write weapon name to file////////////////
new file_name[256],temp_normal[64]
format(file_name, 255, "/addons/amxmodx/configs/current_wpn_name.cfg")
format(temp_normal,63,"%d",WeaponNum)
write_file(file_name,temp_normal, 0)
//////////////////////////////////////////////////////////////////
//checkModel_Normal(id,WeaponNum)
}
}
new current_wpn_sprite[256],text[64],trash
format(current_wpn_sprite, 255, "/addons/amxmodx/configs/current_wpn_name.cfg")
read_file(current_wpn_sprite, 0, text, 63, trash)
if(strcmp(pre_weapon,text))
{
Show_WeaponPickup(id)
pre_weapon=text
}
}
//##############################################################
// BUY WEAPON
//##############################################################
public cmd_buy_wpn(id)
{
new models[64]
read_argv(1, models, 63)
new idwpn = get_idwpn_from_model(models)
if (nst_wpn_mywpn()) mywpn_add(id, idwpn)
else buy_weapon(id, idwpn)
}
public cmd_buy_mywpn(id)
{
new models[64]
read_argv(1, models, 63)
new idwpn = get_idwpn_from_model(models)
buy_weapon(id, idwpn)
}
public buy_weapon(id, idwpn)
{
// Check can buy weapon
if (!is_user_alive(id) || !c_wpnchange[idwpn] || !c_buy[idwpn]) return;
if (!nst_wpn_get_canbuy_team_mod() && c_team[idwpn] && get_user_team(id)!=c_team[idwpn]) return;
// get value
new message[128], buyzone, mod_runing, free_wpn
buyzone = nst_get_user_buyzone(id)
mod_runing = nst_get_mod_runing()
free_wpn = nst_wpn_free()
// zombie mod3 can buy weapon
if (mod_runing == NST_MOD_ZB3 && g_canbuy[id])
{
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_BUY_CANNOT")
nst_color_saytext(id, message)
return;
}
// check buyzone
if (!buyzone)
{
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_NOT_BUYZONE")
nst_color_saytext(id, message)
return;
}
// check money
new money = cs_get_user_money(id)
if (!free_wpn) money -= c_cost[idwpn]
if (money<0)
{
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_ENOUGH_MONEY")
nst_color_saytext(id, message)
return;
}
// buy ammmo if has weapon
if (g_weapon[id] == idwpn)
{
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_BOUGHT", c_name[idwpn])
nst_color_saytext(id, message)
return;
}
// not in mywpn
if (nst_wpn_mywpn() && !mywpn_check_cached(c_model[idwpn]) && c_buy[idwpn])
{
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_NOT_IN_MYWPN", c_name[idwpn])
nst_color_saytext(id, message)
return;
}
// Give weapon
give_weapon_mod(id, idwpn)
nst_set_user_money(id, money)
// set can buy zombie mod3
if (mod_runing == NST_MOD_ZB3) g_canbuy[id] = 1
}
give_weapon_mod(id, idwpn)
{
if (!c_wpnchange[idwpn]) return;
new message[128]
if (!is_user_alive(id))
{
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_BUY_WHEN_ALIVE", c_name[idwpn])
nst_color_saytext(id, message)
return;
}
else if (nst_zb_get_user_zombie(id))
{
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_ZOMBIE_NOT_BUY")
nst_color_saytext(id, message)
return;
}
if (c_buy[idwpn]) g_lastbuy[id] = idwpn
g_weapon[id] = idwpn
Show_WeaponPickup(id)
give_weapon(id)
checkModel(id)
if (get_user_weapon(id) == c_wpnchange[g_weapon[id]]) nst_wpn_send_weapon_anim(id, 3)
//format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_BUY_COMPLETE", c_name[idwpn])
//nst_color_saytext(id, message)
}
get_idwpn_from_model(models[])
{
for(new i=1; i<MAX_WPN; i++)
{
if (equali(c_model[i], models)) return i;
}
return 0;
}
Show_WeaponPickup(id)
{
nst_wpn_show_weaponpickup(id, c_model[g_weapon[id]])
}
//##############################################################
// MENU WEAPON
//##############################################################
public cmd_menu_wpn(id)
{
if (!is_user_alive(id)) return PLUGIN_HANDLED
new type, type_str[32], mywpn_enable
read_argv(1, type_str, charsmax(type_str))
type = str_to_num(type_str)
mywpn_enable = nst_wpn_mywpn()
// member only use main menu wpn if use mywpn
if (mywpn_enable && !nst_is_user_admin(id) && type!=NST_MENUWPN_MAIN) return PLUGIN_HANDLED
// show menu wpn
if (mywpn_enable)
{
if (type==NST_MENUWPN_SHOP) menu_wpn(id)
else menu_mywpn(id, type)
}
else menu_wpn(id)
return PLUGIN_HANDLED
}
menu_wpn(id)
{
new menuwpn_title[64]
format(menuwpn_title, 63, "[%L] %L:", LANG_PLAYER, "MENU_TITLE_SHOP", LANG_PLAYER, "MENU_TITLE_KNIFE")
new mHandleID = menu_create(menuwpn_title, "menu_wpn_handler")
menu_additem(mHandleID, "Default Knife", "0", 0)
new i = 1, check_value = 1
while(check_value && i<MAX_WPN)
{
if ( (!nst_wpn_mywpn() && !nst_wpn_get_canbuy_team_mod() && c_team[i] && get_user_team(id)!=c_team[i]) || !c_buy[i])
{
i++
continue;
}
if (c_wpnchange[i] <= 0) check_value = 0
if (check_value)
{
new wpn_cost = c_cost[i]
new item_name[150], idwpn[32]
format(item_name, 149, "%s: %i$", c_name[i], wpn_cost)
format(idwpn, 31, "%i", i)
new free_wpn, check_money, user_money
free_wpn = nst_wpn_free()
user_money = cs_get_user_money(id)
if (!free_wpn && user_money<wpn_cost && !nst_wpn_mywpn()) check_money = 1
menu_additem(mHandleID, item_name, idwpn, check_money)
}
i++
}
menu_display(id, mHandleID, 0)
return PLUGIN_HANDLED
}
public menu_wpn_handler(id, menu, item)
{
if (item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new idwpn[32], name[32], access
menu_item_getinfo(menu, item, access, idwpn, 31, name, 31, access)
new idweapon = str_to_num(idwpn)
if (nst_wpn_mywpn()) mywpn_add(id, idweapon)
else buy_weapon(id, idweapon)
menu_destroy(menu)
return PLUGIN_HANDLED
}
public cmd_rebuy_wpn(id)
{
new idwpn = g_lastbuy[id]
if (idwpn>0) buy_weapon(id, idwpn)
return PLUGIN_HANDLED
}
//##############################################################
// MY WEAPONS
//##############################################################
// ADD WEAPON INTO MYWEAPONS
mywpn_add(id, idwpn)
{
// check value
if (!idwpn || !c_wpnchange[idwpn] || !c_buy[idwpn] || g_mywpn[0]==idwpn) return;
// admin only
if (!nst_is_user_admin(id))
{
new message[128]
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_ONLY_FOR_ADMIN")
nst_color_saytext(id, message)
return;
}
// add new weapon in to my weapons
new mywpn_set[MAX_MYWPN], check_has, check_origin
check_has = mywpn_check_has(idwpn)
new origin_last = MAX_MYWPN-1
mywpn_set[0] = idwpn
for (new i=1; i<MAX_MYWPN; i++)
{
if (!check_has || g_mywpn[origin_last]==idwpn)
{
mywpn_set[i] = g_mywpn[i-1]
}
else
{
if (g_mywpn[i-1]==idwpn) check_origin = 1
if (check_origin) mywpn_set[i] = g_mywpn[i]
else mywpn_set[i] = g_mywpn[i-1]
}
}
g_mywpn = mywpn_set
// update file res & ini
mywpn_create_res()
mywpn_create_ini(NST_WPN_INI_SAVE)
new message[128]
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_ADD_MYWPN", c_name[idwpn])
nst_color_saytext(0, message)
format(message, charsmax(message), "%L", LANG_PLAYER, "NOTICE_HELP_MYWPN")
SendCenterText(0, message)
// show mywpn
menu_mywpn(id, NST_MENUWPN_MYWPN)
}
mywpn_check_has(idwpn)
{
for (new i=0; i<MAX_MYWPN; i++)
{
if (g_mywpn[i]==idwpn) return 1;
}
return 0;
}
mywpn_check_cached(model[])
{
for (new i=0; i<MAX_MYWPN; i++)
{
if (equali(g_mywpn_cache[i], model)) return 1;
}
return 0;
}
// CREATE INI FILE
mywpn_create_ini(run)
{
// Build customization file file_url
new file_url[64]
get_configsdir(file_url, charsmax(file_url))
format(file_url, charsmax(file_url), "%s/%s", file_url, NST_MYWPN_SETTING_FILE)
// File not present
if (!file_exists(file_url))
{
write_file(file_url, "", -1)
return;
}
// Set up some vars to hold parsing info
new linedata[1024], key[64], value[960], i, lineset[1024]
// Open customization file for reading
new file = fopen(file_url, "rt")
while (file && !feof(file))
{
// Read one line at a time
fgets(file, linedata, charsmax(linedata))
// Replace newlines with a null character to prevent headaches
replace(linedata, charsmax(linedata), "^n", "")
// Blank line or comment
if (!linedata[0] || linedata[0] == ';')
{
i++
continue;
}
// Get key and value(s)
strtok(linedata, key, charsmax(key), value, charsmax(value), '=')
// Trim spaces
trim(key)
trim(value)
// update weapon
if (equali(key, "KNIFE"))
{
// update list weapons
if (run==NST_WPN_INI_SAVE)
{
// get list weapon
new valueset[512]
for (new e=0; e<MAX_MYWPN; e++)
{
if (!g_mywpn[e]) continue;
format(valueset, charsmax(valueset), "%s, %s", valueset, c_model[g_mywpn[e]])
}
// save list weapon
format(lineset, charsmax(lineset), "%s = %s", key, valueset[2])
write_file(file_url, lineset, i)
//client_print(0, print_chat, "da cap nhat xong")
}
// set value for g_mywpn in new round
else if (run==NST_WPN_INI_READ)
{
strtolower(value)
new e
while (e<MAX_MYWPN && value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), ','))
{
trim(key)
trim(value)
format(g_mywpn_cache[e], 31, "%s", key)
e++
}
}
}
i++
}
}
mywpn_create_mywpn()
{
new idwpn
// create g_mywpn
for (new i=0; i<MAX_MYWPN; i++)
{
idwpn = get_idwpn_from_model(g_mywpn_cache[i])
if (c_wpnchange[idwpn])
{
g_mywpn[total_mywpn_cache] = idwpn
total_mywpn_cache++
}
}
// update g_mywpn_cache
for (new i=0; i<MAX_MYWPN; i++)
{
idwpn = g_mywpn[i]
if (c_wpnchange[idwpn]) format(g_mywpn_cache[i], 31, "%s", c_model[idwpn])
else format(g_mywpn_cache[i], 31, "")
}
}
// CREATE RES FILE
mywpn_create_res()
{
// File not present
if (!file_exists(nst_mywpn_res_url))
{
return;
}
// Set up some vars to hold parsing info
new linedata[1024], type_wpn_str[32]
num_to_str(TYPE_WPN, type_wpn_str, charsmax(type_wpn_str))
// Open customization file for reading
new file = fopen(nst_mywpn_res_url, "rt")
new i
while (file && !feof(file))
{
// Read one line at a time
fgets(file, linedata, charsmax(linedata))
// Replace newlines with a null character to prevent headaches
replace(linedata, charsmax(linedata), "^n", "")
replace(linedata, charsmax(linedata), " ", "")
if (linedata[0]=='/' && linedata[1]=='/' && linedata[2]==type_wpn_str[0])
{
mywpn_set_row_value(i, linedata)
}
i++
}
if (file) fclose(file)
}
mywpn_set_row_value(i, linedata[])
{
//client_print(0, print_chat, "[%s]", linedata)
new res_row_search[64], res_row_set[64]
new idwpn, wpnchange
for (new e=0; e<MAX_MYWPN; e++)
{
idwpn = g_mywpn[e]
wpnchange = c_wpnchange[idwpn]
// img
format(res_row_search, charsmax(res_row_search), nst_mywpn_res_img_search, TYPE_WPN, e+1)
if (wpnchange) format(res_row_set, charsmax(res_row_set), nst_mywpn_res_img_set, c_model[idwpn])
else res_row_set = nst_mywpn_res_img_none
if (equali(linedata, res_row_search))
{
write_file(nst_mywpn_res_url_ct, res_row_set, i+1)
write_file(nst_mywpn_res_url_ter, res_row_set, i+1)
return;
}
// team
format(res_row_search, charsmax(res_row_search), nst_mywpn_res_team_search, TYPE_WPN, e+1)
if (wpnchange) format(res_row_set, charsmax(res_row_set), nst_mywpn_res_team_set, c_team[idwpn])
else res_row_set = nst_mywpn_res_team_none
if (equali(linedata, res_row_search))
{
write_file(nst_mywpn_res_url_ct, res_row_set, i+1)
write_file(nst_mywpn_res_url_ter, res_row_set, i+1)
return;
}
// name
format(res_row_search, charsmax(res_row_search), nst_mywpn_res_name_search, TYPE_WPN, e+1)
if (wpnchange) format(res_row_set, charsmax(res_row_set), nst_mywpn_res_name_set, c_name[idwpn], c_cost[idwpn])
else res_row_set = nst_mywpn_res_name_none
if (equali(linedata, res_row_search))
{
write_file(nst_mywpn_res_url_ct, res_row_set, i+1)
write_file(nst_mywpn_res_url_ter, res_row_set, i+1)
return;
}
// command
format(res_row_search, charsmax(res_row_search), nst_mywpn_res_bottom_search, TYPE_WPN, e+1)
if (wpnchange) format(res_row_set, charsmax(res_row_set), nst_mywpn_res_bottom_set, c_model[idwpn])
else res_row_set = nst_mywpn_res_bottom_none
if (equali(linedata, res_row_search))
{
write_file(nst_mywpn_res_url_ct, res_row_set, i+1)
write_file(nst_mywpn_res_url_ter, res_row_set, i+1)
return;
}
}
}
// MENU MYWPN
public menu_mywpn(id, type)
{
new title[64], fun_name[32]
format(title, charsmax(title), "[%L] %L:", LANG_PLAYER, "MENU_TITLE_MYWPN", LANG_PLAYER, "MENU_TITLE_KNIFE")
if (type==NST_MENUWPN_MYWPN) format(fun_name, charsmax(fun_name), "menu_editmywpn_handler")
else format(fun_name, charsmax(fun_name), "menu_mywpn_handler")
new mHandleID = menu_create(title, fun_name)
for (new i=0; i<MAX_MYWPN; i++)
{
new idwpn
if (type==NST_MENUWPN_MYWPN) idwpn = g_mywpn[i]
else idwpn = get_idwpn_from_model(g_mywpn_cache[i])
if (!idwpn || !c_wpnchange[idwpn] || !c_buy[idwpn]) continue;
if (type!=NST_MENUWPN_MYWPN && !nst_wpn_get_canbuy_team_mod() && c_team[idwpn] && get_user_team(id)!=c_team[idwpn])
continue;
new wpn_cost = c_cost[idwpn]
new item_name[128], idweapon[32]
format(item_name, charsmax(item_name), "%s: %i$", c_name[idwpn], wpn_cost)
format(idweapon, charsmax(idweapon), "%i", idwpn)
new free_wpn, check_money, user_money
free_wpn = nst_wpn_free()
user_money = cs_get_user_money(id)
if (!free_wpn && user_money<wpn_cost) check_money = 1
menu_additem(mHandleID, item_name, idweapon, check_money)
}
menu_display(id, mHandleID, 0)
}
public menu_mywpn_handler(id, menu, item)
{
if (item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new idwpn[32], name[32], access
menu_item_getinfo(menu, item, access, idwpn, 31, name, 31, access)
new idweapon = str_to_num(idwpn)
buy_weapon(id, idweapon)
menu_destroy(menu)
return PLUGIN_HANDLED
}
public menu_editmywpn_handler(id, menu, item)
{
if (item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new idwpn[32], name[32], access
menu_item_getinfo(menu, item, access, idwpn, 31, name, 31, access)
new idweapon = str_to_num(idwpn)
mywpn_remove(id, idweapon)
menu_destroy(menu)
return PLUGIN_HANDLED
}
mywpn_remove(id, idwpn)
{
if (!idwpn || !c_wpnchange[idwpn]) return;
if (!nst_is_user_admin(id))
{
new message[128]
format(message, charsmax(message), "^x04[NST Wpn]^x01 %L", LANG_PLAYER, "NOTICE_ONLY_FOR_ADMIN")
nst_color_saytext(id, message)
return;
}
new mywpn_set[MAX_MYWPN], check_origin
for (new i=0; i<MAX_MYWPN; i++)
{
if (g_mywpn[i]==idwpn)
{
check_origin = i
g_mywpn[i] = 0
}
}
for (new i=0; i<MAX_MYWPN; i++)
{
if (!check_origin)
{
if (i==MAX_MYWPN-1) mywpn_set[i] = 0
else mywpn_set[i] = g_mywpn[i+1]
}
else
{
if (i==MAX_MYWPN-1) mywpn_set[i] = 0
else if (i>=check_origin && i<MAX_MYWPN-1) mywpn_set[i] = g_mywpn[i+1]
else mywpn_set[i] = g_mywpn[i]
}
}
g_mywpn = mywpn_set
// show menu mywpn
menu_mywpn(id, NST_MENUWPN_MYWPN)
// update file res & ini
mywpn_create_res()
mywpn_create_ini(NST_WPN_INI_SAVE)
}
SendCenterText(id, message[])
{
new dest
if (id) dest = MSG_ONE
else dest = MSG_ALL
message_begin(dest, g_msgTextMsg, {0,0,0}, id)
write_byte(4)
write_string(message)
message_end()
}
//##############################################################
// STOCK
//##############################################################
stock 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()
}
// Give an item to a player (from fakemeta_util)
stock fm_give_item(id, const item[])
{
static ent
ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item))
if (!pev_valid(ent)) return;
static Float:originF[3]
pev(id, pev_origin, originF)
set_pev(ent, pev_origin, originF)
set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN)
dllfunc(DLLFunc_Spawn, ent)
static save
save = pev(ent, pev_solid)
dllfunc(DLLFunc_Touch, ent, id)
if (pev(ent, pev_solid) != save)
return;
engfunc(EngFunc_RemoveEntity, ent)
}
stock set_player_nextattack(id, Float:nexttime)
{
set_pdata_float(id, m_flNextAttack, nexttime, 4)
}
//##############################################################
// NATIVE
//##############################################################
public natives_give_weapon(id, const weapon[])
{
param_convert(2)
new namewpn[64]
format(namewpn, charsmax(namewpn), "%s", weapon)
new idwpn = get_idwpn_from_model(namewpn)
give_weapon_mod(id, idwpn)
}
public natives_get_int(id, data)
{
new CURENT_WEAPON = g_weapon[id]
new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
if (!CURENT_WEAPON || get_user_weapon(id)!=CHANGE_WEAPON) return 0;
new result
switch (data)
{
case NST_WPN_DATA_HASWEAPON: result = CURENT_WEAPON
case NST_WPN_DATA_KNOCKBACK: result = c_knockback[CURENT_WEAPON]
case NST_WPN_DATA_GRAVITY: result = c_gravity[CURENT_WEAPON]
}
return result;
}
public Float:natives_get_float(id, data)
{
new CURENT_WEAPON = g_weapon[id]
new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
if (!CURENT_WEAPON || get_user_weapon(id)!=CHANGE_WEAPON) return 0.0;
new Float:result
switch (data)
{
case NST_WPN_DATA_DEPLOY: result = c_deploy[CURENT_WEAPON]
case NST_WPN_DATA_DAMAGE: result = c_damage[CURENT_WEAPON]
}
return result;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1034\\ f0\\ fs16 \n\\ par }
*/