AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Unknow Command (https://forums.alliedmods.net/showthread.php?t=222331)

cosmin200 08-01-2013 10:15

Unknow Command
 
So i was edited nst wpn to make custom weapons hud but i have a problem i dont know the weapon id so i can't select weapon from slot 1(primary weapon) , 2(secondary weapon) ...

PHP Code:

L 08/01/2013 16:58:09Invalid weapon id 0
L 08
/01/2013 16:58:09: [AMXXDisplaying debug trace (plugin "cso_wpn_rifles.amxx")
L 08/01/2013 16:58:09: [AMXXRun time error 10native error (native "get_weaponname")
L 08/01/2013 16:58:09: [AMXX]    [0cso_wpn_rifles.sma::ClientCommand_SelectGun (line 1053

Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#include <cstrike>
#include <engine>

#include <nst_zombie>
#include <nst_scenario>
#include <nst_wpn>


// Setting
const TYPE_WPN = NST_WPN_RIFLES
const MAX_WPN = 128
const MAX_MYWPN = 8
new COUNT_WPN
new const CLASS_NAME_LIGHT[] = "nst_light_%i"
new const CLASS_NAME_NADE[] = "nst_nade_%i"

// main value
new g_weapon[33], g_lastbuy[33], g_canbuy[33], Float:g_sight_begin[33], g_user_clip[33], g_user_ammo[33], g_user_nade[33], g_user_light[33],
g_zoom[33], g_can_zoom[33], g_changing[33], g_double[33], g_current_cswpn[33], g_clip[33], g_silen[33][CSW_P90+1],
g_attack[33], g_notpickup[33], g_l_reloading[33], g_m_ready[33], g_m_shoot[33], g_m_canclick[33],
Float:g_idle[33], g_k_deploy[33], g_s_reloading[33], g_s_sreloading[33], g_lg_deploy[33]

// my weapons
new g_mywpn[MAX_MYWPN], g_mywpn_cache[MAX_MYWPN][32], total_mywpn_cache

// config value
new c_type[MAX_WPN]
new c_name[MAX_WPN][64]
new c_model[MAX_WPN][32]
new c_wpnchange[MAX_WPN]
new c_wpn_hud[MAX_WPN][64]
new c_gravity[MAX_WPN]
new c_sound[MAX_WPN]
new c_team[MAX_WPN]
new c_buy[MAX_WPN]
new c_knockback[MAX_WPN]
new Float:c_reload[MAX_WPN]
new Float:c_deploy[MAX_WPN]
new c_fastrun[MAX_WPN]
new Float:c_sight_time[MAX_WPN]
new c_sight_model[MAX_WPN][32]
new Float:c_damage[MAX_WPN]
new Float:c_speed[MAX_WPN]
new c_zoom[MAX_WPN]
new c_clip[MAX_WPN]
new c_ammo[MAX_WPN]
new Float:c_recoil[MAX_WPN]
new c_cost[MAX_WPN]

new c_model_p[MAX_WPN][64]
new c_model_v[MAX_WPN][64]
new c_model_v2[MAX_WPN][64]
new c_model_w[MAX_WPN][64]
new c_model_s[MAX_WPN][64]
new c_sound1[MAX_WPN][64]
new c_sound2[MAX_WPN][64]
new c_sound1_silen[MAX_WPN][64]
new c_sound2_silen[MAX_WPN][64]
new c_sound_hitmiss[MAX_WPN][64]
new c_sound_hitwall[MAX_WPN][64]
new c_sound_hitplayer[MAX_WPN][64]
new c_sound_nadeexp[MAX_WPN][64]
new c_cache_nadeexp[MAX_WPN]
new c_sound_light_fire[MAX_WPN][64]
new c_sound_light_exp[MAX_WPN][64]
new c_cache_light_exp[MAX_WPN]

// Double Weapons
new Float:c_d_timechange1[MAX_WPN]
new Float:c_d_timechange2[MAX_WPN]
new Float:c_d_damage[MAX_WPN]
new Float:c_d_speed[MAX_WPN]
new c_d_zoom[MAX_WPN]
new Float:c_d_recoil[MAX_WPN]
new c_d_clip[MAX_WPN]
new Float:c_d_reload[MAX_WPN]
new Float:c_d_deploy[MAX_WPN]
new c_d_sight_model[MAX_WPN][32]

//Weapons Knife
new Float:c_k_time[MAX_WPN]
new Float:c_k_radius[MAX_WPN]
new Float:c_k_damage[MAX_WPN]
new Float:c_k_deploy[MAX_WPN]
new Float:c_k_knockback[MAX_WPN]

// weapons launcher
new c_l_nade[MAX_WPN]
new c_l_costammo[MAX_WPN]
new Float:c_l_timechange1[MAX_WPN]
new Float:c_l_timechange2[MAX_WPN]
new Float:c_l_timereload[MAX_WPN]
new Float:c_l_knockback[MAX_WPN]
new Float:c_l_radius[MAX_WPN]
new Float:c_l_damage[MAX_WPN]
new c_l_type[MAX_WPN]

// weapons shotguns
new Float:c_s_timereload[MAX_WPN]

// Cvar weapons light
new c_lg_ammo[MAX_WPN]
new c_lg_costammo[MAX_WPN]
new Float:c_lg_damage[MAX_WPN]
new Float:c_lg_radius[MAX_WPN]
new Float:c_lg_knockback[MAX_WPN]
new Float:c_lg_deploy[MAX_WPN]
new Float:c_lg_timeattack[MAX_WPN]
new c_lg_colortrail[MAX_WPN][32]

// Cvar weapons m134
new Float:c_m_timeready[MAX_WPN]

// enum weapon type
enum
{
        WEAPONS_NORMAL = 1,
        WEAPONS_DOUBLE,
        WEAPONS_KNIFE,
        WEAPONS_LAUNCHER,
        WEAPONS_SHOTGUN,
        WEAPONS_LIGHT,
        WEAPONS_M134
}
// enum section weapon
enum
{
        SECTION_TYPE = 0,
        SECTION_NAME,
        SECTION_MODEL,
        SECTION_WPNCHANGE,
        SECTION_DAMAGE,
        SECTION_SPEED,
        SECTION_ZOOM,
        SECTION_CLIP,
        SECTION_AMMO,
        SECTION_RECOIL,
        SECTION_GRAVITY,
        SECTION_KNOCKBACK,
        SECTION_RELOAD,
        SECTION_DEPLOY,
        SECTION_FASTRUN,
        SECTION_SIGHT_TIME,
        SECTION_SIGHT_MODEL,
        SECTION_COST,
        SECTION_SOUND,
        SECTION_TEAM,
        SECTION_BUY,
        SECTION_STARTNUM
}
enum
{
        SECTION_D_TIMECHANGE1 = SECTION_STARTNUM,
        SECTION_D_TIMECHANGE2,
        SECTION_D_DAMAGE,
        SECTION_D_SPEED,
        SECTION_D_ZOOM,
        SECTION_D_RECOIL,
        SECTION_D_CLIP,
        SECTION_D_RELOAD,
        SECTION_D_DEPLOY,
        SECTION_D_SIGHTMODEL
       
}
enum
{
        SECTION_K_TIME = SECTION_STARTNUM,
        SECTION_K_RADIUS,
        SECTION_K_DAMAGE,
        SECTION_K_DEPLOY,
        SECTION_K_KNOCKBACK
}
enum
{
        SECTION_L_NADE = SECTION_STARTNUM,
        SECTION_L_COSTAMMO,
        SECTION_L_TIMECHANGE1,
        SECTION_L_TIMECHANGE2,
        SECTION_L_TIMERELOAD,
        SECTION_L_KNOCKBACK,
        SECTION_L_RADIUS,
        SECTION_L_DAMAGE,
        SECTION_L_TYPE
}
enum
{
        SECTION_S_TIMERELOAD = SECTION_STARTNUM
}
enum
{
        SECTION_LG_AMMO = SECTION_STARTNUM,
        SECTION_LG_COSTAMMO,
        SECTION_LG_DAMAGE,
        SECTION_LG_RADIUS,
        SECTION_LG_KNOCKBACK,
        SECTION_LG_DEPLOY,
        SECTION_LG_TIMEATTACK,
        SECTION_LG_COLORTRAIL
}
enum
{
        SECTION_M134_TIMEREADY = SECTION_STARTNUM
}

// zoom type
enum
{
        ZOOMTYPE_NONE = 0,
        ZOOMTYPE_AUG,
        ZOOMTYPE_SNIPER,
        ZOOMTYPE_SIGHT
}
// Task
enum (+= 100)
{
        TASK_BUYAMMO = 2000,
        TASK_GIVEWPN,
        TASK_GIVEWPNBOT,
        TASK_REMOVECLASSWPM,
        TASK_CHANGEWPN,
        TASK_PICKUPWPN,
        TASK_KNIFE_ATTACK,
        TASK_KNIFE_DEPLOY,
        TASK_SHOTGUN_RELOAD,
        TASK_SHOTGUN_SRELOAD,
        TASK_LAUNCHER_RELOAD,
        TASK_LIGHT_DEPLOY,
        TASK_LIGHT_ATTACK,
        TASK_M134_READY,
        TASK_M134_FIRE_CHANGE,
        TASK_M134_CANCLICK,
        TASK_SIGHT_BEGIN
       
}
#define ID_BUYAMMO (taskid - TASK_BUYAMMO)
#define ID_GIVEWPN (taskid - TASK_GIVEWPN)
#define ID_GIVEWPNBOT (taskid - TASK_GIVEWPNBOT)
#define ID_REMOVECLASSWPM (taskid - TASK_REMOVECLASSWPM)
#define ID_CHANGEWPN (taskid - TASK_CHANGEWPN)
#define ID_PICKUPWPN (taskid - TASK_PICKUPWPN)
#define ID_KNIFE_ATTACK (taskid - TASK_KNIFE_ATTACK)
#define ID_KNIFE_DEPLOY (taskid - TASK_KNIFE_DEPLOY)
#define ID_SHOTGUN_RELOAD (taskid - TASK_SHOTGUN_RELOAD)
#define ID_SHOTGUN_SRELOAD (taskid - TASK_SHOTGUN_SRELOAD)
#define ID_LAUNCHER_RELOAD (taskid - TASK_LAUNCHER_RELOAD)
#define ID_LIGHT_DEPLOY (taskid - TASK_LIGHT_DEPLOY)
#define ID_LIGHT_ATTACK (taskid - TASK_LIGHT_ATTACK)
#define ID_M134_READY (taskid - TASK_M134_READY)
#define ID_M134_FIRE_CHANGE (taskid - TASK_M134_FIRE_CHANGE)
#define ID_M134_CANCLICK (taskid - TASK_M134_CANCLICK)
#define ID_SIGHT_BEGIN (taskid - TASK_SIGHT_BEGIN)

// cs wepaon type
const CSWPN_NOCLIP        = ((1<<2)|(1<<CSW_HEGRENADE)|(1<<CSW_SMOKEGRENADE)|(1<<CSW_FLASHBANG)|(1<<CSW_KNIFE)|(1<<CSW_C4))
const CSWPN_SHOTGUNS        = ((1<<CSW_M3)|(1<<CSW_XM1014))
const CSWPN_SILENT        = ((1<<CSW_USP)|(1<<CSW_M4A1))
const CSWPN_SNIPER        = ((1<<CSW_SCOUT)|(1<<CSW_SG550)|(1<<CSW_AWP)|(1<<CSW_G3SG1))
const CSWPN_FIRSTZOOM        = ((1<<CSW_AUG)|(1<<CSW_SG552))
const CSWPN_BURST        = ((1<<CSW_FAMAS)|(1<<CSW_GLOCK18))

// offset
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

const XO_CBASEPLAYERWEAPON = 4

// cs weapon default value
new const WEAPON_CLIP[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
}
new const RELOAD_ANIM[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
}
new const Float:WEAPON_DELAY[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 WEAPON_NAME[][] = { "", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10",
                        "weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550",
                        "weapon_galil", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249",
                        "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552",
                        "weapon_ak47", "weapon_knife", "weapon_p90"
}
new const WEAPON_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
}
new const WEAPON_AMMOTYPE[][] = { "", "357sig", "", "762nato", "", "buckshot", "", "45acp", "556nato", "", "9mm", "57mm", "45acp",
                        "556nato", "556nato", "556nato", "45acp", "9mm", "338magnum", "9mm", "556natobox", "buckshot",
                        "556nato", "9mm", "762nato", "", "50ae", "556nato", "762nato", "", "57mm"
}

// other vlaue
new g_msgStatusIcon, g_msgTextMsg
new g_hamczbots, cvar_botquota, cvar_friendlyfire
new cache_blood, cache_bloodspray, cache_trail, cache_smoke, cache_explo

// CS sounds
new const sound_buyammo[] = "items/9mmclip1.wav"
new Float:g_wait_act = 0.4

// shotgun anim
enum {
        idle,
        shoot1,
        shoot2,
        insert,
        after_reload,
        start_reload,
        draw
}

enum {
        m3,
        xm1014
}

new const CSWeaponList[][] =
{
                                { -1, -1, -1, -1, -1 },
          /*CSW_P228*/                { 9, 52, 1, 3, 0 },
                                { -1, -1, -1, -1, -1 },
        /*CSW_SCOUT*/                { 2, 90, 0, 9, 0 },
        /*CSW_HEGRENADE*/        { 12, 1, 3, 1, 24 },
        /*CSW_XM1014*/                { 5, 32, 0, 12, 0 },
        /*CSW_C4*/                { 14, 1, 4, 3, 24 },
        /*CSW_MAC10*/                { 6, 100, 0, 13, 0 },
        /*CSW_AUG*/                { 4, 90, 0, 14, 0 },
        /*CSW_SMOKEGRENADE*/        { 13, 1, 3, 3, 24 },
        /*CSW_ELITE*/                { 10, 120, 1, 5, 0 },
        /*CSW_FIVESEVEN*/        { 7, 100, 1, 6, 0 },
        /*CSW_UMP45*/                { 6, 100, 0, 15, 0 },
        /*CSW_SG550*/                { 4, 90, 0, 16, 0 },
        /*CSW_GALIL*/                { 4, 90, 0, 17, 0 },
        /*CSW_FAMAS*/                { 4, 90, 0, 18, 0 },
        /*CSW_USP*/                { 6, 100, 1, 4, 0 },
        /*CSW_GLOCK18*/                { 10, 120, 1, 2, 0 },
        /*CSW_AWP*/                { 1, 30, 0, 2, 0 },
        /*CSW_MP5NAVY*/                { 10, 120, 0, 7, 0 },
        /*CSW_M249*/                { 3, 200, 0, 4, 0 },
        /*CSW_M3*/                { 5, 32, 0, 5, 0 },
        /*CSW_M4A1*/                { 4, 90, 0, 6, 0 },       
        /*CSW_TMP*/                { 10, 120, 0, 11, 0 },
        /*CSW_G3SG1*/                { 2, 90, 0, 3, 0 },
        /*CSW_FLASHBANG*/        { 11, 2, 3, 2, 24 },
        /*CSW_DEAGLE*/                { 8, 35, 1, 1, 0 },
        /*CSW_SG552*/                { 4, 90, 0, 10, 0 },
        /*CSW_AK47*/                { 2, 90, 0, 1, 0 },
          /*CSW_KNIFE*/                { -1, -1, 2, 1, 0},
          /*CSW_P90*/                { 7, 100, 0, 8, 0 }
}

//##############################################################
// REGISTER PLUGIN
//##############################################################
public plugin_natives()
{
        register_native("nst_wpn_give_weapon1", "natives_give_weapon", 1)
        register_native("nst_wpn_set_fullammo1", "natives_set_fullammo", 1)       
        register_native("nst_wpn_get_fastrunanim_weapon1", "natives_get_fastrunanim_weapon", 1)
        register_native("nst_wpn_get_user_sight1", "natives_get_user_sight", 1)
        register_native("nst_wpn_get_int1", "natives_get_int", 1)
        register_native("nst_wpn_get_float1", "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()
       
        // sprites
        cache_trail = precache_model("sprites/smoke.spr")
        cache_blood = precache_model("sprites/blood.spr")
        cache_bloodspray = precache_model("sprites/bloodspray.spr")
        cache_smoke  = precache_model("sprites/steam1.spr")
        cache_explo = precache_model("sprites/fexplo.spr")
       
        // CS sounds (just in case)
        engfunc(EngFunc_PrecacheSound, sound_buyammo)
}
public plugin_init()
{
        register_plugin(NST_WPN_NAME_RIFLES, NST_WPN_VERSION, NST_WPN_AUTHOR)
       
        // Language files
        register_dictionary(NST_WPN_LANG_FILE)
       
        // Msgid
        g_msgStatusIcon = get_user_msgid("StatusIcon")
        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_CmdStart, "fw_CmdStart" )
        register_forward(FM_SetModel, "fw_SetModel")
        register_forward(FM_Touch, "fw_Touch")
        RegisterHam(Ham_Touch, "weaponbox", "fw_TouchWeapon")
        RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
        register_message(get_user_msgid("DeathMsg"), "message_DeathMsg")
       
        // Reg Cmd
        register_clcmd("buyammo1","cmd_buyammo")
        register_clcmd("primammo","cmd_buyfullammo")
        register_clcmd("nst_menu_wpn1", "cmd_menu_wpn")
        register_clcmd("nst_rebuy_wpn1", "cmd_rebuy_wpn")
        register_clcmd("nst_buy_wpn", "cmd_buy_wpn")
        register_clcmd("nst_buy_mywpn", "cmd_buy_mywpn")
        register_clcmd("nst_change_wpn","cmd_change_wpn")
       
        // Cvar
        cvar_botquota = get_cvar_pointer("bot_quota")
        cvar_friendlyfire = get_cvar_pointer("mp_friendlyfire")
       
        // HAM Forwards
        new szWeapon[17]
        for(new i=1; i<=CSW_P90; i++)
        {
                if (!(CSWPN_NOCLIP & (1<<i)) && get_weaponname(i, szWeapon, charsmax(szWeapon)))
                {
                        RegisterHam(Ham_Weapon_PrimaryAttack, szWeapon, "fw_Weapon_PrimaryAttack_Post", 1)
                        RegisterHam(Ham_Weapon_WeaponIdle, szWeapon, "fw_Weapon_WeaponIdle")
                        RegisterHam(Ham_Weapon_Reload, szWeapon, "fw_Weapon_Reload")
                        RegisterHam(Ham_Item_AddToPlayer, szWeapon, "ItemAddToPlayer", 1 );

                        if (CSWPN_SHOTGUNS & (1<<i)) RegisterHam(Ham_Item_PostFrame, szWeapon, "fw_Shotgun_PostFrame")
                        else RegisterHam(Ham_Item_PostFrame, szWeapon, "fw_Item_PostFrame")
                }
        }
       
        //register_concmd("qq", "qq")
}
public qq(id)
{
        client_print(id, print_chat, "[%i] [%i]", COUNT_WPN, get_random_weapon())
}



//##############################################################
// LOAD CONFIG
//##############################################################
new data_type, data_name[64], data_model[32], data_wpnchange, Float:data_damage, Float:data_speed, data_zoom, data_clip, data_ammo, Float:data_recoil, data_gravity, data_knockback, Float:data_reload, Float:data_deploy, data_fastrun, Float:data_sight_time, data_sight_model[32], data_cost, data_sound_type, data_team, data_buy,
        Float:data_d_timechange_1, Float:data_d_timechange_2, Float:data_d_damage, Float:data_d_speed, data_d_zoom, Float:data_d_recoil, data_d_clip, Float:data_d_reload, Float:data_d_deploy, data_d_sight_model[32],
        Float:data_k_time, Float:data_k_radius, Float:data_k_damage, Float:data_k_deploy, Float:data_k_knockback,
        data_l_nade, data_l_costammo, Float:data_l_timechange_1, Float:data_l_timechange_2, Float:data_l_timereload, Float:data_l_knockback, Float:data_l_radius, Float:data_l_damage, data_l_type,
        Float:data_s_timereload,
        data_lg_ammo, data_lg_costammo, Float:data_lg_damage, Float:data_lg_radius, Float:data_lg_knockback, Float:data_lg_deploy, Float:data_lg_timeattack, data_lg_colortrail[32],
        Float:data_m_timeready

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), "[speed]", ",")
                replace_all(linedata, charsmax(linedata), "[zoom]", ",")
                replace_all(linedata, charsmax(linedata), "[clip]", ",")
                replace_all(linedata, charsmax(linedata), "[ammo]", ",")
                replace_all(linedata, charsmax(linedata), "[recoil]", ",")
                replace_all(linedata, charsmax(linedata), "[gravity]", ",")
                replace_all(linedata, charsmax(linedata), "[knockback]", ",")
                replace_all(linedata, charsmax(linedata), "[reload]", ",")
                replace_all(linedata, charsmax(linedata), "[deploy]", ",")
                replace_all(linedata, charsmax(linedata), "[fastrun]", ",")
                replace_all(linedata, charsmax(linedata), "[sight_time]", ",")
                replace_all(linedata, charsmax(linedata), "[sight_model]", ",")
                replace_all(linedata, charsmax(linedata), "[cost]", ",")
                replace_all(linedata, charsmax(linedata), "[sound]", ",")
                replace_all(linedata, charsmax(linedata), "[team]", ",")
                replace_all(linedata, charsmax(linedata), "[buy]", ",")

                replace_all(linedata, charsmax(linedata), "[d_tchange1]", ",")
                replace_all(linedata, charsmax(linedata), "[d_tchange2]", ",")
                replace_all(linedata, charsmax(linedata), "[d_damage]", ",")
                replace_all(linedata, charsmax(linedata), "[d_speed]", ",")
                replace_all(linedata, charsmax(linedata), "[d_zoom]", ",")
                replace_all(linedata, charsmax(linedata), "[d_recoil]", ",")
                replace_all(linedata, charsmax(linedata), "[d_clip]", ",")
                replace_all(linedata, charsmax(linedata), "[d_reload]", ",")
                replace_all(linedata, charsmax(linedata), "[d_deploy]", ",")
                replace_all(linedata, charsmax(linedata), "[d_sight_model]", ",")

                replace_all(linedata, charsmax(linedata), "[k_time]", ",")
                replace_all(linedata, charsmax(linedata), "[k_radius]", ",")
                replace_all(linedata, charsmax(linedata), "[k_damage]", ",")
                replace_all(linedata, charsmax(linedata), "[k_deploy]", ",")
                replace_all(linedata, charsmax(linedata), "[k_knockback]", ",")
               
                replace_all(linedata, charsmax(linedata), "[l_nade]", ",")
                replace_all(linedata, charsmax(linedata), "[l_costammo]", ",")
                replace_all(linedata, charsmax(linedata), "[l_tchange1]", ",")
                replace_all(linedata, charsmax(linedata), "[l_tchange2]", ",")
                replace_all(linedata, charsmax(linedata), "[l_reload]", ",")
                replace_all(linedata, charsmax(linedata), "[l_knockback]", ",")
                replace_all(linedata, charsmax(linedata), "[l_radius]", ",")
                replace_all(linedata, charsmax(linedata), "[l_damage]", ",")
                replace_all(linedata, charsmax(linedata), "[l_type]", ",")

                replace_all(linedata, charsmax(linedata), "[s_reload]", ",")
               
                replace_all(linedata, charsmax(linedata), "[lg_ammo]", ",")
                replace_all(linedata, charsmax(linedata), "[lg_costammo]", ",")
                replace_all(linedata, charsmax(linedata), "[lg_damage]", ",")
                replace_all(linedata, charsmax(linedata), "[lg_radius]", ",")
                replace_all(linedata, charsmax(linedata), "[lg_knockback]", ",")
                replace_all(linedata, charsmax(linedata), "[lg_deploy]", ",")
                replace_all(linedata, charsmax(linedata), "[lg_timeattack]", ",")
                replace_all(linedata, charsmax(linedata), "[lg_color]", ",")
               
                replace_all(linedata, charsmax(linedata), "[m_timeready]", ",")

                // 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_TYPE: data_type = str_to_num(key)
                                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_SPEED: data_speed = str_to_float(key)
                                case SECTION_ZOOM: data_zoom = str_to_num(key)
                                case SECTION_CLIP: data_clip = str_to_num(key)
                                case SECTION_AMMO: data_ammo = str_to_num(key)
                                case SECTION_RECOIL: data_recoil = str_to_float(key)
                                case SECTION_GRAVITY: data_gravity = str_to_num(key)
                                case SECTION_KNOCKBACK: data_knockback = str_to_num(key)
                                case SECTION_RELOAD: data_reload = str_to_float(key)
                                case SECTION_DEPLOY: data_deploy = str_to_float(key)
                                case SECTION_FASTRUN: data_fastrun = str_to_num(key)
                                case SECTION_SIGHT_TIME: data_sight_time = str_to_float(key)
                                case SECTION_SIGHT_MODEL: format(data_sight_model, charsmax(data_sight_model), "%s", key)
                                case SECTION_COST: data_cost = str_to_num(key)
                                case SECTION_SOUND: data_sound_type = str_to_num(key)
                                case SECTION_TEAM: data_team = str_to_num(key)
                                case SECTION_BUY: data_buy = str_to_num(key)
                        }
                       
                        if (data_type == WEAPONS_DOUBLE)
                        {
                                switch (i)
                                {
                                        case SECTION_D_TIMECHANGE1: data_d_timechange_1 = str_to_float(key)
                                        case SECTION_D_TIMECHANGE2: data_d_timechange_2 = str_to_float(key)
                                        case SECTION_D_DAMAGE: data_d_damage = str_to_float(key)
                                        case SECTION_D_SPEED: data_d_speed = str_to_float(key)
                                        case SECTION_D_ZOOM: data_d_zoom = str_to_num(key)
                                        case SECTION_D_RECOIL: data_d_recoil = str_to_float(key)
                                        case SECTION_D_CLIP: data_d_clip = str_to_num(key)
                                        case SECTION_D_RELOAD: data_d_reload = str_to_float(key)
                                        case SECTION_D_DEPLOY: data_d_deploy = str_to_float(key)
                                        case SECTION_D_SIGHTMODEL: format(data_d_sight_model, charsmax(data_d_sight_model), "%s", key)
                                }
                        }
                        else if (data_type == WEAPONS_KNIFE)
                        {
                                switch (i)
                                {
                                        case SECTION_K_TIME: data_k_time = str_to_float(key)
                                        case SECTION_K_RADIUS: data_k_radius = str_to_float(key)
                                        case SECTION_K_DAMAGE: data_k_damage = str_to_float(key)
                                        case SECTION_K_DEPLOY: data_k_deploy = str_to_float(key)
                                        case SECTION_K_KNOCKBACK: data_k_knockback = str_to_float(key)
                                }
                        }
                        else if (data_type == WEAPONS_LAUNCHER)
                        {
                                switch (i)
                                {
                                        case SECTION_L_NADE: data_l_nade = str_to_num(key)
                                        case SECTION_L_COSTAMMO: data_l_costammo = str_to_num(key)
                                        case SECTION_L_TIMECHANGE1: data_l_timechange_1 = str_to_float(key)
                                        case SECTION_L_TIMECHANGE2: data_l_timechange_2 = str_to_float(key)
                                        case SECTION_L_TIMERELOAD: data_l_timereload = str_to_float(key)
                                        case SECTION_L_KNOCKBACK: data_l_knockback = str_to_float(key)
                                        case SECTION_L_RADIUS: data_l_radius = str_to_float(key)
                                        case SECTION_L_DAMAGE: data_l_damage = str_to_float(key)
                                        case SECTION_L_TYPE: data_l_type = str_to_num(key)
                                }
                        }
                        else if (data_type == WEAPONS_SHOTGUN && (CSWPN_SHOTGUNS & (1<<data_wpnchange)))
                        {
                                switch (i)
                                {
                                        case SECTION_S_TIMERELOAD: data_s_timereload = str_to_float(key)
                                }
                        }
                        else if (data_type == WEAPONS_LIGHT)
                        {
                                switch (i)
                                {
                                        case SECTION_LG_AMMO: data_lg_ammo = str_to_num(key)
                                        case SECTION_LG_COSTAMMO: data_lg_costammo = str_to_num(key)
                                        case SECTION_LG_DAMAGE: data_lg_damage = str_to_float(key)
                                        case SECTION_LG_RADIUS: data_lg_radius = str_to_float(key)
                                        case SECTION_LG_KNOCKBACK: data_lg_knockback = str_to_float(key)
                                        case SECTION_LG_DEPLOY: data_lg_deploy = str_to_float(key)
                                        case SECTION_LG_TIMEATTACK: data_lg_timeattack = str_to_float(key)
                                        case SECTION_LG_COLORTRAIL: format(data_lg_colortrail, charsmax(data_lg_colortrail), "%s", key)
                                }
                        }
                        else if (data_type == WEAPONS_M134)
                        {
                                switch (i)
                                {
                                        case SECTION_M134_TIMEREADY: data_m_timeready = str_to_float(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 Main
                        c_type[idwpn] = data_type
                        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_sound[idwpn] = data_sound_type
                        c_team[idwpn] = data_team
                        c_buy[idwpn] = data_buy
                        c_knockback[idwpn] = data_knockback
                        c_reload[idwpn] = data_reload
                        c_deploy[idwpn] = data_deploy
                        c_fastrun[idwpn] = data_fastrun

                        data_ammo = max(data_ammo, nst_zb_get_weapons_ammo(data_wpnchange))
                        data_ammo = max(data_ammo, nst_scn_get_weapons_ammo(data_wpnchange))
                       
                        // Create Cvar                               
                        c_damage[idwpn] = data_damage
                        c_speed[idwpn] = data_speed
                        c_zoom[idwpn] = data_zoom
                        c_clip[idwpn] = data_clip
                        c_ammo[idwpn] = data_ammo
                        c_recoil[idwpn] = data_recoil
                        c_cost[idwpn] = data_cost
                       
                        if (data_type==WEAPONS_DOUBLE)
                        {                               
                                c_d_timechange1[idwpn] = data_d_timechange_1
                                c_d_timechange2[idwpn] = data_d_timechange_2
                                c_d_damage[idwpn] = data_d_damage
                                c_d_speed[idwpn] = data_d_speed
                                c_d_zoom[idwpn] = data_d_zoom
                                c_d_recoil[idwpn] = data_d_recoil
                                c_d_clip[idwpn] = data_d_clip
                                c_d_reload[idwpn] = data_d_reload
                                c_d_deploy[idwpn] = data_d_deploy
                        }
                        else if (data_type==WEAPONS_KNIFE)
                        {
                                c_k_time[idwpn] = data_k_time
                                c_k_radius[idwpn] = data_k_radius
                                c_k_damage[idwpn] = data_k_damage
                                c_k_deploy[idwpn] = data_k_deploy
                                c_k_knockback[idwpn] = data_k_knockback
                        }
                        else if (data_type==WEAPONS_LAUNCHER)
                        {
                                c_l_nade[idwpn] = data_l_nade
                                c_l_costammo[idwpn] = data_l_costammo
                                c_l_timechange1[idwpn] = data_l_timechange_1
                                c_l_timechange2[idwpn] = data_l_timechange_2
                                c_l_timereload[idwpn] = data_l_timereload
                                c_l_knockback[idwpn] = data_l_knockback
                                c_l_radius[idwpn] = data_l_radius
                                c_l_damage[idwpn] = data_l_damage
                                c_l_type[idwpn] = data_l_type
                        }       
                        else if (data_type == WEAPONS_SHOTGUN && (CSWPN_SHOTGUNS & (1<<data_wpnchange)))
                        {
                                c_s_timereload[idwpn] = data_s_timereload
                        }
                        else if (data_type==WEAPONS_LIGHT)
                        {
                                c_lg_ammo[idwpn] = data_lg_ammo
                                c_lg_costammo[idwpn] = data_lg_costammo
                                c_lg_damage[idwpn] = data_lg_damage
                                c_lg_radius[idwpn] = data_lg_radius
                                c_lg_knockback[idwpn] = data_lg_knockback
                                c_lg_deploy[idwpn] = data_lg_deploy
                                c_lg_timeattack[idwpn] = data_lg_timeattack
                                format(c_lg_colortrail[idwpn], 31, "%s", data_lg_colortrail)
                        }
                        else if (data_type == WEAPONS_M134)
                        {
                                c_m_timeready[idwpn] = data_m_timeready
                        }
                       
                        // Cache File
                        if ( !nst_wpn_mywpn() || (nst_wpn_mywpn() && mywpn_check_cached(data_model)) || (!data_buy && nst_wpn_get_mod_has_supplybox()) )
                        {
                                // Create Models and Sound
                                format(c_model_p[idwpn], 63, "models/zombi/p_%s.mdl", data_model)
                                format(c_model_v[idwpn], 63, "models/zombi/v_%s.mdl", data_model)
                                format(c_model_w[idwpn], 63, "models/zombi/w_%s.mdl", data_model)
                                format(c_sound1[idwpn], 63, "weapons/%s_shoot1.wav", data_model)
                                format(c_sound1_silen[idwpn], 63, "weapons/%s_shoot1_silen.wav", data_model)
                                format(c_sound2[idwpn], 63, "weapons/%s_shoot2.wav", data_model)
                                format(c_sound2_silen[idwpn], 63, "weapons/%s_shoot2_silen.wav", data_model)
       
                                precache_model(c_model_p[idwpn])
                                precache_model(c_model_v[idwpn])
                                precache_model(c_model_w[idwpn])
                                if (data_sound_type) precache_sound(c_sound1[idwpn])

                                precacheList( retrieveEventSounds( c_model_v[idwpn] ) );

                                format(c_wpn_hud[idwpn], 63, "sprites/s_%s.spr", data_model)
                                precache_generic(c_wpn_hud[idwpn])
                                format(c_wpn_hud[idwpn], 63, "sprites/t_%s.txt", data_model)
                                precache_generic(c_wpn_hud[idwpn])
                                format(c_wpn_hud[idwpn], 63, "t_%s", data_model)

                                register_clcmd(c_wpn_hud[idwpn], "ClientCommand_SelectGun" )
                               
                                // sight
                                if (c_zoom[idwpn]==ZOOMTYPE_SIGHT)
                                {
                                        c_sight_time[idwpn] = data_sight_time
                                        format(c_sight_model[idwpn], 31, "models/zombi/v_%s.mdl", data_sight_model)
                                        precache_model(c_sight_model[idwpn])
                                }

                                // type wpn
                                if (data_type==WEAPONS_DOUBLE)
                                {
                                        format(c_model_v2[idwpn], 63, "models/zombi/v_%s_2.mdl", data_model)
                                        precache_model(c_model_v2[idwpn])
                                       
                                        if (c_d_zoom[idwpn]==ZOOMTYPE_SIGHT)
                                        {
                                                format(c_d_sight_model[idwpn], 31, "models/zombi/v_%s.mdl", data_d_sight_model)
                                                precache_model(c_d_sight_model[idwpn])
                                        }
                                       
                                        if (data_sound_type==2) precache_sound(c_sound2[idwpn])
                                       
                                }
                                else if (data_type==WEAPONS_KNIFE)
                                {
                                        format(c_sound_hitmiss[idwpn], 63, "weapons/%s_hitmiss.wav", data_model)
                                        format(c_sound_hitwall[idwpn], 63, "weapons/%s_hitwall.wav", data_model)
                                        format(c_sound_hitplayer[idwpn], 63, "weapons/%s_hitplayer.wav", data_model)
       
                                        precache_sound(c_sound_hitmiss[idwpn])
                                        precache_sound(c_sound_hitwall[idwpn])
                                        precache_sound(c_sound_hitplayer[idwpn])
                                }
                                else if (data_type==WEAPONS_LAUNCHER)
                                {
                                        format(c_model_v2[idwpn], 63, "models/zombi/v_%s_2.mdl", data_model)
                                        format(c_sound_nadeexp[idwpn], 63, "weapons/%s_exp.wav", data_model)
                                        format(c_model_s[idwpn], 63, "models/zombi/s_grenade.mdl")
                                        //format(c_model_s[idwpn], 63, "models/zombi/s_%s.mdl", data_model)
       
                                        precache_model(c_model_s[idwpn])
                                        precache_sound(c_sound_nadeexp[idwpn])
                                        if (data_l_type)
                                        {
                                                c_model_v2[idwpn] = c_model_v[idwpn]
                                                c_sound2[idwpn] = c_sound1[idwpn]
                                                c_sound1_silen[idwpn] = c_sound1[idwpn]
                                                c_sound2_silen[idwpn] = c_sound1[idwpn]
                                        }
                                        else
                                        {
                                                precache_model(c_model_v2[idwpn])
                                                precache_sound(c_sound2[idwpn])
                                                if (data_sound_type==2)
                                                {
                                                        precache_sound(c_sound2[idwpn])
                                                        precache_sound(c_sound2_silen[idwpn])
                                                }
                                        }
                                       
                                        // spr exp
                                        new g_spr_exp[64]
                                        format(g_spr_exp, 63, "sprites/zombi/%s_exp.spr", data_model)
                                        c_cache_nadeexp[idwpn] = precache_model(g_spr_exp)
                                }
                                else if (data_type==WEAPONS_LIGHT)
                                {
                                        format(c_sound_light_fire[idwpn], 63, "weapons/%s_lg_fire.wav", data_model)
                                        format(c_sound_light_exp[idwpn], 63, "weapons/%s_lg_exp.wav", data_model)
                                        precache_sound(c_sound_light_fire[idwpn])
                                        precache_sound(c_sound_light_exp[idwpn])
                                       
                                        new lg_exp[64]
                                        format(lg_exp, charsmax(lg_exp), "sprites/zombi/%s_lg_exp.spr", data_model)
                                        c_cache_light_exp[idwpn] = precache_model(lg_exp)
                                }
                               
                               
                                if (CSWPN_SILENT & (1<<data_wpnchange))
                                {
                                        if (data_type==WEAPONS_DOUBLE)
                                        {
                                                if (data_sound_type==2) precache_sound(c_sound2_silen[idwpn])
                                        }
                                        else precache_sound(c_sound1_silen[idwpn])
                                }
                        }
                       
                        COUNT_WPN = idwpn
                        idwpn++
                }
               
                // check max wpn
                if (idwpn == MAX_WPN) return;
        }
}

precacheList( Array:list )
{
    if( list != Invalid_Array )
    {
        new count = ArraySize( list );

        if( count )
        {
            const maxSoundLength = 64;

            new const soundDir[] = "sound/";
            new sound[ maxSoundLength + sizeof soundDir ];

            for( new i = 0; i < count; i++ )
            {
                formatex( sound, charsmax( sound ), "%s%a", soundDir, ArrayGetStringHandle( list, i ) );

                if( file_exists( sound ) )
                {
                    //log_amx( "Found = %s", sound[ charsmax( soundDir ) ] );
                    precache_sound( sound[ charsmax( soundDir ) ] );
                }
            }
        }

        ArrayDestroy( list );
    }
}

Array:retrieveEventSounds( const model[] )
{
    new Array:arrayEventsSounds = Invalid_Array;
    new Trie:trieEventsSounds = Invalid_Trie;
   
    new f = fopen( model, "rb" );

    if( f )
    {
        const studioHeaderNumSeq = 164;
        const mstudioseqdescSize = 176;

        new sequenceIndex;
        new sequenceCount;

        const studioSeqHeaderNumEvents = 48;
        const mstudioeventSize        = 76;
        const studioEventOptionIndex  = 12;

        new eventIndex;
        new eventCount;
        new eventOption[64];

        fseek( f, studioHeaderNumSeq, SEEK_SET );
        {
            fread( f, sequenceCount, BLOCK_INT );
            fread( f, sequenceIndex, BLOCK_INT );
        }
        fseek( f, sequenceIndex, SEEK_SET );

        arrayEventsSounds = ArrayCreate( sizeof eventOption );
        trieEventsSounds = TrieCreate();

        new last = sequenceIndex;

        for( new i = 0; i < sequenceCount; i++ )
        {
            fseek( f, studioSeqHeaderNumEvents, SEEK_CUR );
            fread( f, eventCount, BLOCK_INT );

            if( eventCount )
            {
                fread( f, eventIndex, BLOCK_INT );
                fseek( f, eventIndex, SEEK_SET );

                for( new j = 0; j < eventCount; j++ )
                {
                    fseek( f, studioEventOptionIndex, SEEK_CUR );
                    fread_blocks( f, eventOption, sizeof eventOption, BLOCK_CHAR );

                    if( containi( eventOption, ".wav" ) > 0 && !TrieKeyExists( trieEventsSounds, eventOption ) )
                    {
                        log_amx( "%s", eventOption );
                        ArrayPushString( arrayEventsSounds, eventOption );
                        TrieSetCell( trieEventsSounds, eventOption, true );
                    }

                    fseek( f, mstudioeventSize - ( sizeof eventOption + studioEventOptionIndex ), SEEK_CUR );
                }
            }

            fseek( f, last += mstudioseqdescSize, SEEK_SET );
        }
       
        TrieDestroy( trieEventsSounds );

        fclose( f );
    }

    return arrayEventsSounds;
}

public fw_TouchWeapon(ent, id)
{
        // Not a player
        if (!is_user_alive(id) || !pev_valid(ent))
                return HAM_IGNORED;
       
        // Zombie not pickup
        if (nst_zb_get_user_zombie(id)) return HAM_SUPERCEDE;
       
        // Not can pickup wpn
        if (g_notpickup[id]) return HAM_SUPERCEDE;
       
       
        // PickUp Wpn
        static Float:velocity[3]
        pev(ent, pev_velocity, velocity)       
        new CURENT_WEAPON = get_idweapon_from_ent(ent)
        if ( !check_has_wpn(id) && !g_weapon[id] && CURENT_WEAPON && (!velocity[0] &&!velocity[0] &&!velocity[0]) )
        {
                // give wpn
                g_weapon[id] = CURENT_WEAPON
                g_user_clip[id] = pev(ent, pev_iuser1)
                g_user_ammo[id] = pev(ent, pev_iuser2)
                g_double[id] = pev(ent, pev_iuser3)
                g_user_nade[id] = pev(ent, pev_iuser4)
                g_user_light[id] = pev(ent, pev_euser1)

                if (c_type[CURENT_WEAPON]==WEAPONS_LIGHT) ShowStatusIcon(id, g_user_light[id], 1)
       
                give_weapon(id, g_user_clip[id], g_user_ammo[id])
                engfunc(EngFunc_RemoveEntity, ent)
               
                // set time pickup
                g_notpickup[id] = 1
                if (task_exists(id+TASK_PICKUPWPN)) remove_task(id+TASK_PICKUPWPN)
                set_task(0.2, "task_remove_notpickup", id+TASK_PICKUPWPN)

                return HAM_IGNORED;
        }

        return HAM_IGNORED;
}

public ClientCommand_SelectGun()
{
}

//##############################################################
// EVENT - FORWARD - MESSAGE
//##############################################################
public event_start_freezetime()
{
        new reset[33]
        g_canbuy = reset
        g_notpickup = reset
        g_m_canclick = reset
        if (nst_zb_remove_weapons_newround()) g_weapon = reset
}
public client_disconnect(id)
{
        g_weapon[id] = 0
}
public client_putinserver(id)
{
        if (is_user_bot(id) && !g_hamczbots && cvar_botquota)
        {
                set_task(0.1, "register_ham_czbots", id)
        }
       
        g_weapon[id] = 0
}
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)
}
// NST Wpn Draw Forwards
public nst_wpn_weapon_draw(id)
{
        checkModel(id)
}
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]
                if (c_type[attacker_wpn]==WEAPONS_DOUBLE && g_double[killer]) format(sprites_wpn, charsmax(sprites_wpn), "%s_2", c_model[attacker_wpn])
                else format(sprites_wpn, charsmax(sprites_wpn), "%s", c_model[attacker_wpn])
               
                // send deathmsg
                set_msg_arg_string(4, sprites_wpn)
               
                return PLUGIN_CONTINUE
        }
               
        return PLUGIN_CONTINUE
}
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)
                }
        }
       
        // remove zoom
        reset_zoom(id)
       
        // 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 fw_SetModel(entity, const model[])
{
        // We don't care
        if (strlen(model) < 8)
                return FMRES_IGNORED;

        // Get id
        new id, wmodel[64]
        id = pev(entity, pev_owner)
        format(wmodel, charsmax(wmodel), "%s", model[9])

        // check haswpn
        if (g_weapon[id])
        {
                new CURENT_WEAPON = g_weapon[id]
                new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
                new idwpn = get_idwpn_from_wmodel(wmodel)
               
                if (CHANGE_WEAPON == idwpn)
                {
                        create_info_wmodel(entity, CURENT_WEAPON, id)
                        if (c_type[CURENT_WEAPON]==WEAPONS_LIGHT) HideStatusIcon(id)
                        g_weapon[id] = 0
                       
                        return FMRES_SUPERCEDE
                }
        }
       
        return FMRES_IGNORED
}
public event_CurWeapon(id)
{
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
       
        new plrClip, plrAmmo, plrWeapId
        plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
       
        // Update current weapons
        if (g_current_cswpn[id] != plrWeapId)
        {
                g_can_zoom[id] = 0
                g_attack[id] = 0
                g_idle[id] = 0.0
                g_m_ready[id] = 0
                g_m_shoot[id] = 0
                remove_task_running(id)
                HideStatusIcon(id)
               
                if (CURENT_WEAPON && plrWeapId == CHANGE_WEAPON)
                {
                        // fix auto shoot for m134
                        if (c_type[CURENT_WEAPON]==WEAPONS_M134) set_player_nexprimaryattack(id, 2.0)
                }
        }
        g_current_cswpn[id] = plrWeapId
       
        // check weapons
        if (plrWeapId == CHANGE_WEAPON && CURENT_WEAPON)
        {
                checkModel(id)

                // change sound attack
                if (nst_wpn_get_sound_attack()==1 && g_attack[id])
                {
                        change_sound_attack(id)
                        g_attack[id] = 0
                }
               
                // Update Clip Ammo
                if (!(c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER && g_double[id]))
                {
                        g_user_clip[id] = plrClip
                        g_user_ammo[id] = plrAmmo
                }
               
                // show & hide user light
                if (c_type[CURENT_WEAPON]==WEAPONS_LIGHT)
                {
                        static flash
                        flash = (g_lg_deploy[id]) ? 2 : 1
                        ShowStatusIcon(id, g_user_light[id], flash)
                }
        }

        // Check HasWpn
        check_has_current_wpn(id)
       
        //client_print(id, print_chat, "[%i]", g_weapon[id])
}
checkModel(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 (plrWeapId == CHANGE_WEAPON && g_weapon[id])
        {
                // set v_sight when sight
                if (natives_get_user_sight(id) && (get_gametime()-g_sight_begin[id]>=c_sight_time[CURENT_WEAPON]))
                {
                        if (g_double[id]) set_pev(id, pev_viewmodel2, c_d_sight_model[CURENT_WEAPON])
                        else set_pev(id, pev_viewmodel2, c_sight_model[CURENT_WEAPON])
                }
                // set v_model_2 when double weapon
                else if (g_double[id]) set_pev(id, pev_viewmodel2, c_model_v2[CURENT_WEAPON])
               
                // set v_model
                else set_pev(id, pev_viewmodel2,c_model_v[CURENT_WEAPON])
               
                // set p_model
                set_pev(id, pev_weaponmodel2, c_model_p[CURENT_WEAPON])
        }
}
public fw_CmdStart(id, uc_handle, seed)
{
        if(!is_user_alive(id))
        {
                reset_zoom(id)
                return;
        }

        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new szClip, szAmmo
        new szWeapID = get_user_weapon( id, szClip, szAmmo )
        static buttons
        buttons = get_uc(uc_handle, UC_Buttons)       

        if(szWeapID == CHANGE_WEAPON && CURENT_WEAPON)
        {
                // create zoom
                new zoom = c_zoom[CURENT_WEAPON]
                if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE)
                {
                        new d_zoom = c_d_zoom[CURENT_WEAPON]
                        if (!g_double[id])
                        {
                                if (!zoom) remove_zoom(id, uc_handle)
                                else create_zoom(id, uc_handle, zoom)
                        }
                        else
                        {
                                if (!d_zoom) remove_zoom(id, uc_handle)
                                else create_zoom(id, uc_handle, d_zoom)
                        }
                }
                else if (c_type[CURENT_WEAPON]==WEAPONS_KNIFE ||
                        c_type[CURENT_WEAPON]==WEAPONS_LIGHT ||
                        c_type[CURENT_WEAPON]==WEAPONS_M134 ||
                        (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER && g_double[id]))
                {
                        remove_zoom(id, uc_handle)
                }
                else
                {
                        if (!zoom) remove_zoom(id, uc_handle)
                        else create_zoom(id, uc_handle, zoom)
                }
       
                // Check Zoom
                if ( (g_zoom[id] && (pev(id, pev_button) & IN_RELOAD)) || g_changing[id] || !g_can_zoom[id] || nst_wpn_get_user_fastrun(id))
                {
                        reset_zoom(id)
                }
               
                // Update Ammo
                if( !(CSWPN_SHOTGUNS & (1<<CHANGE_WEAPON)) ) cs_set_user_bpammo(id, CHANGE_WEAPON, g_user_ammo[id])

                // change sound attack
                if (nst_wpn_get_sound_attack()==2 && g_clip[id] != szClip && (buttons & IN_ATTACK))
                {
                        g_clip[id] = szClip
                        change_sound_attack(id)
                }
               
                // ################## Other Attack ##################
                // knife attack
                if ( (c_type[CURENT_WEAPON]==WEAPONS_KNIFE))
                {
                        if (buttons & IN_ATTACK2)
                        {
                                buttons &= ~IN_ATTACK2
                                set_uc(uc_handle, UC_Buttons, buttons)
                                use_knife_attack(id)
                        }
                }
                // launcher m203
                else if (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER)
                {
                        if (g_double[id])
                        {
                                // M203 attack
                                if (buttons & IN_ATTACK)
                                {
                                        buttons &= ~IN_ATTACK
                                        set_uc(uc_handle, UC_Buttons, buttons)
                                        use_m203_attack(id)
                                }
                                // remove reload
                                else if (buttons & IN_RELOAD)
                                {
                                        buttons &= ~IN_RELOAD
                                        set_uc(uc_handle, UC_Buttons, buttons)
                                        nst_wpn_send_weapon_anim(id, 0)
                                        set_weapons_timeidle(id, 0.5)
                                        set_player_nextattack(id, 0.5)
                                }
                               
                                // Remove Anmo Clip and Set Nade
                                new ent = get_weapon_ent(id,CHANGE_WEAPON)
                                if (ent) cs_set_weapon_ammo(ent, -1)
                                cs_set_user_bpammo(id, CHANGE_WEAPON, g_user_nade[id])
                        }       
                }
                // shotgun reload
                else if (c_type[CURENT_WEAPON]==WEAPONS_SHOTGUN)
                {
                        // reload
                        if (buttons & IN_RELOAD)
                        {
                                buttons &= ~IN_RELOAD
                                set_uc(uc_handle, UC_Buttons, buttons)
                                use_shotgun_sreload(id)
                        }
                        if (szAmmo && !szClip) use_shotgun_sreload(id)
                }
                // fire light
                else if (c_type[CURENT_WEAPON]==WEAPONS_LIGHT)
                {
                        if (buttons & IN_ATTACK2)
                        {
                                buttons &= ~IN_ATTACK2
                                set_uc(uc_handle, UC_Buttons, buttons)
                                use_light_attack(id)
                        }
                }
                // m134
                else if (c_type[CURENT_WEAPON]==WEAPONS_M134)
                {
                        use_m134_attack(id, szClip, uc_handle)
                }               
        }
       
        if (g_zoom[id] && szWeapID != CHANGE_WEAPON)
        {
                reset_zoom(id)
        }
}
public fw_Touch(ent, id)
{
        if (!pev_valid(ent)) return FMRES_IGNORED
       
        new EntClassName[32], class_light[64], class_nade[64]
        format(class_nade, charsmax(class_nade), CLASS_NAME_NADE, TYPE_WPN)
        format(class_light, charsmax(class_light), CLASS_NAME_LIGHT, TYPE_WPN)
        entity_get_string(ent, EV_SZ_classname, EntClassName, charsmax(EntClassName))

        if (equal(EntClassName, class_nade))
        {
                grenade_explode(ent)
                remove_entity(ent)
                return FMRES_IGNORED
        }
        else if (equal(EntClassName, class_light))
        {
                light_explode(ent)
                remove_entity(ent)
                return FMRES_IGNORED
        }
       
        return FMRES_IGNORED
}
public fw_Weapon_WeaponIdle(iEnt)
{
        static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)
       
        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 && CURENT_WEAPON)
        {
                g_can_zoom[id] = 1
                if (!g_idle[id]) g_idle[id] = get_gametime()
               
                if (c_type[CURENT_WEAPON]==WEAPONS_M134)
                {
                        if (!g_m_shoot[id] && plrClip) set_player_nextattack(id, 1.0)
                        if ((pev(id, pev_button) & IN_RELOAD)) set_player_nextattack(id, 0.0)
                }
               
                if (CSWPN_SHOTGUNS & (1<<CHANGE_WEAPON)) fw_Shotgun_WeaponIdle(iEnt)
        }
}
public fw_Weapon_PrimaryAttack_Post(ent)
{
        new id = pev(ent,pev_owner)

        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new szClip, szAmmo
        new szWeapID = get_user_weapon( id, szClip, szAmmo )
       
        if( szWeapID == CHANGE_WEAPON && g_weapon[id])
        {
                // Double Wpn
                if (szClip) g_attack[id] = 1
                g_can_zoom[id] = 1
                g_idle[id] = 0.0
                remove_task_running(id)
                //client_print(id, print_chat, "[tan cong]")
        }
       
        return HAM_IGNORED
}
public fw_Weapon_Reload(ent)
{
        new id = pev(ent,pev_owner)
       
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new szClip, szAmmo
        new szWeapID = get_user_weapon( id, szClip, szAmmo )
       
        if( szWeapID == CHANGE_WEAPON && g_weapon[id])
        {
                if (szClip<get_clip_weapon(id) && szAmmo) g_can_zoom[id] = 0
                g_attack[id] = 0
                g_m_shoot[id] = 0
               
                // remove auto reload for shotgun
                if (c_type[CURENT_WEAPON]==WEAPONS_SHOTGUN)
                {
                        nst_wpn_send_weapon_anim(id, 0)
                        use_shotgun_sreload(id)
                        return HAM_IGNORED
                }
               
                // set value
                g_idle[id] = 0.0
                remove_task_running(id)

                //client_print(id, print_chat, "[thay dan]")
        }
       
        return HAM_IGNORED
}
public fw_Item_PostFrame(iEnt)
{
        static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)
        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])
        {

                static iId ; iId = get_pdata_int(iEnt, m_iId, 4)
                static iMaxClip ; iMaxClip = get_clip_weapon(id)
                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)
                        g_user_ammo[id] = iBpAmmo-j
                        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( CSWPN_SILENT & (1<<iId) && !get_pdata_int(iEnt, m_fSilent, 4) )
                                {
                                        nst_wpn_send_weapon_anim( id, iId == CSW_USP ? 8 : 7 )
                                }
                                else
                                {
                                        nst_wpn_send_weapon_anim(id, 0)
                                }
                                set_weapons_timeidle(id, 1.0)
                        }
                        else if( iClip == WEAPON_CLIP[iId] )
                        {
                                if( iBpAmmo )
                                {
                                        set_pdata_float(id, m_flNextAttack, WEAPON_DELAY[iId], 5)
       
                                        if( CSWPN_SILENT & (1<<iId) && get_pdata_int(iEnt, m_fSilent, 4) )
                                        {
                                                nst_wpn_send_weapon_anim( id, iId == CSW_USP ? 5 : 4 )
                                        }
                                        else
                                        {
                                                nst_wpn_send_weapon_anim(id, RELOAD_ANIM[iId])
                                        }
                                        set_pdata_int(iEnt, m_fInReload, 1, 4)
                                        set_pdata_float(iEnt, m_flTimeWeaponIdle, WEAPON_DELAY[iId] + 0.5, 4)
                                }
                        }
                }
               
                // check silent
                if ( CSWPN_SILENT & (1<<iId) && get_pdata_int(iEnt, m_fSilent, 4) ) g_silen[id][iId] = 1
                else g_silen[id][iId] = 0
        }
}
public fw_Shotgun_PostFrame(iEnt)
{
        static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)       
        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])
        {
               
        static iBpAmmo ; iBpAmmo = get_pdata_int(id, 381, 5)
        static iClip ; iClip = get_pdata_int(iEnt, m_iClip, 4)
        static iId ; iId = get_pdata_int(iEnt, m_iId, 4)
        static iMaxClip ; iMaxClip = get_clip_weapon(id)

        // Support for instant reload (used for example in my plugin "Reloaded Weapons On New Round")
        if( get_pdata_int(iEnt, m_fInReload, 4) && get_pdata_float(id, m_flNextAttack, 5) <= 0.0 )
        {
                new j = min(iMaxClip - iClip, iBpAmmo)
                set_pdata_int(iEnt, m_iClip, iClip + j, 4)
                set_pdata_int(id, 381, iBpAmmo-j, 5)
                set_pdata_int(iEnt, m_fInReload, 0, 4)
                g_user_ammo[id] = iBpAmmo-j
                return
        }

        static iButton ; iButton = pev(id, pev_button)
        if( iButton & IN_ATTACK && get_pdata_float(iEnt, m_flNextPrimaryAttack, 4) <= 0.0 )
        {
                return
        }

        if( iButton & IN_RELOAD  )
        {
                if( iClip >= iMaxClip )
                {
                        set_pev(id, pev_button, iButton & ~IN_RELOAD) // still this fucking animation
                        set_pdata_float(iEnt, m_flNextPrimaryAttack, 0.5, 4)  // Tip ?
                }

                else if( iClip == WEAPON_CLIP[iId] )
                {
                        if( iBpAmmo )
                        {
                                Shotgun_Reload(iEnt, iId, iMaxClip, iClip, iBpAmmo, id)
                        }
                }
        }
        }
}
Shotgun_Reload(iEnt, iId, iMaxClip, iClip, iBpAmmo, id)
{
        //static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)       
        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(iBpAmmo <= 0 || iClip == iMaxClip)
                        return
       
                if(get_pdata_int(iEnt, m_flNextPrimaryAttack, 4) > 0.0)
                        return
       
                switch( get_pdata_int(iEnt, m_fInSpecialReload, 4) )
                {
                        case 0:
                        {
                                nst_wpn_send_weapon_anim( id , start_reload)
                                set_pdata_int(iEnt, m_fInSpecialReload, 1, 4)
                                set_pdata_float(id, m_flNextAttack, 0.55, 4)
                                set_pdata_float(iEnt, m_flTimeWeaponIdle, 0.55, 4)
                                set_pdata_float(iEnt, m_flNextPrimaryAttack, 0.55, 4)
                                set_pdata_float(iEnt, m_flNextSecondaryAttack, 0.55, 4)
                                return
                        }
                        case 1:
                        {
                                if( get_pdata_float(iEnt, m_flTimeWeaponIdle, 4) > 0.0 )
                                {
                                        return
                                }
                                set_pdata_int(iEnt, m_fInSpecialReload, 2, 4)
                                emit_sound(id, CHAN_ITEM, random_num(0,1) ? "weapons/reload1.wav" : "weapons/reload3.wav", 1.0, ATTN_NORM, 0, 85 + random_num(0,0x1f))
                                nst_wpn_send_weapon_anim( id, insert )
       
                                set_pdata_float(iEnt, m_flTimeWeaponIdle, iId == CSW_XM1014 ? 0.30 : 0.45, 4)
                        }
                        default:
                        {
                                set_pdata_int(iEnt, m_iClip, iClip + 1, 4)
                                set_pdata_int(id, 381, iBpAmmo-1, 5)
                                set_pdata_int(iEnt, m_fInSpecialReload, 1, 4)
                                g_user_ammo[id] = iBpAmmo-1
                        }
                }
        }
}
public fw_Shotgun_WeaponIdle(iEnt)
{
        if (get_pdata_float(iEnt, m_flTimeWeaponIdle, 4) > 0.0) return;
       
        static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)

        static iId ; iId = get_pdata_int(iEnt, m_iId, 4)
        static iMaxClip ; iMaxClip = get_clip_weapon(id)

        static iClip ; iClip = get_pdata_int(iEnt, m_iClip, 4)
        static fInSpecialReload ; fInSpecialReload = get_pdata_int(iEnt, m_fInSpecialReload, 4)

        if( !iClip && !fInSpecialReload )
        {
                return
        }

        if( fInSpecialReload )
        {
                static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)
                static iBpAmmo ; iBpAmmo = get_pdata_int(id, 381, 5)
                static iDftMaxClip ; iDftMaxClip = WEAPON_CLIP[iId]

                if( iClip < iMaxClip && iClip == iDftMaxClip && iBpAmmo )
                {
                        Shotgun_Reload(iEnt, iId, iMaxClip, iClip, iBpAmmo, id)
                        return
                }
                else if( iClip == iMaxClip && iClip != iDftMaxClip )
                {
                        nst_wpn_send_weapon_anim( id, after_reload )

                        set_pdata_int(iEnt, m_fInSpecialReload, 0, 4)
                        set_pdata_float(iEnt, m_flTimeWeaponIdle, 1.5, 4)
                }
        }
}


//##############################################################
// MENU WEAPON
//##############################################################
public cmd_menu_wpn(id, level, cid)
{
        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 title[64], typewpn = TYPE_WPN
        if (typewpn == NST_WPN_RIFLES) format(title, charsmax(title), "[%L] %L:", LANG_PLAYER, "MENU_TITLE_SHOP", LANG_PLAYER, "MENU_TITLE_RIFLES")
        else if (typewpn == NST_WPN_PISTOLS) format(title, charsmax(title), "[%L] %L:", LANG_PLAYER, "MENU_TITLE_SHOP", LANG_PLAYER, "MENU_TITLE_PISTOLS")

        new mHandleID = menu_create(title, "menu_wpn_handler")
        new i, 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)
}
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)
       
        // add weapon into mywpn if is admin
        if (nst_wpn_mywpn()) mywpn_add(id, idweapon)
       
        // else buy weapon for player
        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 WEAPON
//##############################################################
// 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[CSO]^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[CSO]^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)
               
                new name_type[64], typewpn = TYPE_WPN
                if (typewpn == NST_WPN_RIFLES) name_type = "RIFLES"
                else if (typewpn == NST_WPN_PISTOLS) name_type = "PISTOLS"

                // update weapon
                if (equali(key, name_type))
                {
                        // 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], typewpn = TYPE_WPN
        if (typewpn == NST_WPN_RIFLES) format(title, charsmax(title), "[%L] %L:", LANG_PLAYER, "MENU_TITLE_MYWPN", LANG_PLAYER, "MENU_TITLE_RIFLES")
        else if (typewpn == NST_WPN_PISTOLS) format(title, charsmax(title), "[%L] %L:", LANG_PLAYER, "MENU_TITLE_MYWPN", LANG_PLAYER, "MENU_TITLE_PISTOLS")
               
        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[CSO]^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)
}


//##############################################################
// BUY WEAPON - AMMO
//##############################################################
// BUY WEAPONS
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;
       
        // 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 can't buy
        if (nst_zb_get_user_zombie(id))
        {
                format(message, charsmax(message), "^x04[CSO]^x01 %L", LANG_PLAYER, "NOTICE_ZOMBIE_NOT_BUY")
                nst_color_saytext(id, message)
                return;
        }

        // # team can't buy
        if (!nst_wpn_get_canbuy_team_mod() && c_team[idwpn] && get_user_team(id)!=c_team[idwpn])
        {
                new teamname[32]
                if (c_team[idwpn]==1) teamname = "TR"
                else if (c_team[idwpn]==2) teamname = "CT"
                format(message, charsmax(message), "^x04[CSO]^x01 %L", LANG_PLAYER, "NOTICE_NOT_TEAM_USE", teamname)
                nst_color_saytext(id, message)
                return;
        }
       
        // zombie mod3 can buy weapon
        if (mod_runing == NST_MOD_ZB3 && g_canbuy[id])
        {
                format(message, charsmax(message), "^x04[CSO]^x01 %L", LANG_PLAYER, "NOTICE_BUY_CANNOT")
                nst_color_saytext(id, message)
                return;
        }
       
        // check buyzone
        if (!buyzone)
        {
                format(message, charsmax(message), "^x04[CSO]^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[CSO]^x01 %L", LANG_PLAYER, "NOTICE_ENOUGH_MONEY")
                nst_color_saytext(id, message)
                return;
        }

        // buy ammmo if has weapon
        if (g_weapon[id] == idwpn)
        {
                cmd_buyfullammo(id)
                format(message, charsmax(message), "^x04[CSO]^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[CSO]^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
       
        return;
}
give_weapon_mod(id, idwpn)
{
        new message[128]
       
        if (!is_user_alive(id))
        {
                format(message, charsmax(message), "^x04[CSO]^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[CSO]^x01 %L", LANG_PLAYER, "NOTICE_ZOMBIE_NOT_BUY")
                nst_color_saytext(id, message)
                return;
        }

        new plrClip, plrAmmo
        get_user_weapon(id, plrClip , plrAmmo)
        new clip_max = c_clip[idwpn]
        new ammo_max = c_ammo[idwpn]
       
        // Drop all rifles wpn
        //if (is_user_bot(id)) remove_weapons(id)
        //else drop_weapons(id)
        drop_weapons(id)
       
        g_weapon[id] = idwpn
        g_user_clip[id] = clip_max
        g_user_ammo[id] = ammo_max
        if (c_buy[idwpn]) g_lastbuy[id] = idwpn
        g_double[id] = 0
       
        if (c_type[idwpn]==WEAPONS_LAUNCHER)
        {
                g_user_nade[id] = c_l_nade[idwpn]
                if (!c_l_type[idwpn]) g_double[id] = 0
                else g_double[id] = 1
        }
        else if (c_type[idwpn]==WEAPONS_LIGHT)
        {
                g_user_light[id] = c_lg_ammo[idwpn]
                ShowStatusIcon(id, g_user_light[id], 1)
        }

        show_hud_ammo(id, ammo_max)
        give_weapon(id, g_user_clip[id], g_user_ammo[id])

        format(message, charsmax(message), "^x04[CSO]^x01 %L", LANG_PLAYER, "NOTICE_BUY_COMPLETE", c_name[idwpn])
        nst_color_saytext(id, message)
        if (c_type[idwpn]==WEAPONS_DOUBLE)
        {
                format(message, charsmax(message), "^x04[CSO]^x01 %L", LANG_PLAYER, "NOTICE_HELP_CHANGE")
                nst_color_saytext(id, message)
        }
}
// BUY AMMO
public cmd_buyfullammo(id)
{
        // zombie can't buy ammo
        if (!is_user_alive(id) || nst_zb_get_user_zombie(id)) return PLUGIN_HANDLED

        // zombie mod3 can't buy ammo
        new mod_runing = nst_get_mod_runing()
        if (mod_runing == NST_MOD_ZB3) return PLUGIN_HANDLED
       
        new message[64]
        new buyzone = nst_get_user_buyzone(id)

        // buy zone
        if (!buyzone)
        {
                format(message, 63, "^x04[CSO]^x01 %L", LANG_PLAYER, "NOTICE_NOT_BUYZONE")
                nst_color_saytext(id, message)
                return PLUGIN_CONTINUE
        }
        else if (g_weapon[id])
        {
                // give full ammo
                buy_full_ammo(id)       
                return PLUGIN_HANDLED;
        }

        return PLUGIN_CONTINUE
}
public cmd_buyammo(id)
{
        // zombie can't buy ammo
        if (!is_user_alive(id) || nst_zb_get_user_zombie(id)) return PLUGIN_HANDLED
       
        // zombie mod3 can't buy ammo
        new mod_runing = nst_get_mod_runing()
        if (mod_runing == NST_MOD_ZB3) return PLUGIN_HANDLED
       
        new message[64]
        new buyzone = nst_get_user_buyzone(id)
       
        // buy zone
        if (!buyzone)
        {
                format(message, 63, "^x04[CSO]^x01 %L", LANG_PLAYER, "NOTICE_NOT_BUYZONE")
                nst_color_saytext(id, message)
        }
        else if (g_weapon[id])
        {
                // give ammo
                buy_ammo(id)
                return PLUGIN_HANDLED;
        }

        return PLUGIN_CONTINUE
}
buy_full_ammo(id)
{
        if (!g_weapon[id]) return;
       
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
       
        new numammo = c_ammo[CURENT_WEAPON] - cs_get_user_bpammo(id, CHANGE_WEAPON)
        new numclip = (numammo/get_clip_weapon(id))+1
       
        if (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER) numclip += c_l_nade[CURENT_WEAPON]
        else if (c_type[CURENT_WEAPON]==WEAPONS_LIGHT) numclip += c_lg_ammo[CURENT_WEAPON]
       
        for (new i = 1; i <= numclip; i++)
        {
                buy_ammo(id)
        }
}
buy_ammo(id)
{
        if (!g_weapon[id]) return;
       
        // get weapon id
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new user_money = cs_get_user_money(id)
        new light_max, nade_max
        if (c_type[CURENT_WEAPON]==WEAPONS_LIGHT) light_max = c_lg_ammo[CURENT_WEAPON]
        else if (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER) nade_max = c_l_nade[CURENT_WEAPON]
       
        // buy nade
        if (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER && g_user_nade[id] < nade_max)
        {
                new nade_num = min(1, nade_max-g_user_nade[id])
                new cost = nade_num*c_l_costammo[CURENT_WEAPON]
                if (user_money >= cost)
                {
                        g_user_nade[id] += nade_num
                        fun_show_nade(id, nade_num)
                        nst_set_user_money(id, user_money-cost)
                        PlayEmitSound(id, sound_buyammo, CHAN_ITEM)
                }
        }
        // buy light
        else if (c_type[CURENT_WEAPON]==WEAPONS_LIGHT && g_user_light[id] < light_max)
        {
                new light_num = min(1, light_max-g_user_light[id])
                new cost = light_num*c_lg_costammo[CURENT_WEAPON]
                if (user_money >= cost)
                {
                        g_user_light[id] += light_num
                        fun_show_nade(id, light_num)
                        nst_set_user_money(id, user_money-cost)
                        PlayEmitSound(id, sound_buyammo, CHAN_ITEM)
                       
                        static flash
                        flash = (g_lg_deploy[id]) ? 2 : 1
                        ShowStatusIcon(id, g_user_light[id], flash)
                }
        }
        // buy ammo
        else if (!(c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER && g_double[id]))
        {
                new ammo_max = c_ammo[CURENT_WEAPON]
                new clip_max = get_clip_weapon(id)
                new cost = min(ammo_max-g_user_ammo[id], clip_max)
                if (g_user_ammo[id]<ammo_max && user_money>=cost)
                {
                        ExecuteHamB(Ham_GiveAmmo, id, clip_max, WEAPON_AMMOTYPE[CHANGE_WEAPON], ammo_max)
                        give_weapon(id, g_user_clip[id], cs_get_user_bpammo(id, CHANGE_WEAPON))
                        PlayEmitSound(id, sound_buyammo, CHAN_ITEM)
                        nst_set_user_money(id, user_money-cost)
                }
        }
}
show_hud_ammo(id,ammo)
{
        new clip_max = get_clip_weapon(id)
       
        if (ammo<=clip_max) fun_show_ammo(id, ammo)
        else
        {
                new ammo_a = ammo % clip_max
                new num_for = (ammo-ammo_a)/clip_max
                if (num_for)
                {
                        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)
{
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
       
        message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("AmmoPickup"), _, id)
        write_byte(WEAPON_AMMOID[CHANGE_WEAPON]) // ammo id
        write_byte(ammo) // ammo amount
        message_end()
       
        PlayEmitSound(id, sound_buyammo, CHAN_ITEM)
}
fun_show_nade(id, num)
{
        new hudnade[32]
        format(hudnade, charsmax(hudnade), "nade_%s", c_model[g_weapon[id]])
       
        for (new i = 1; i <= num; i++)
        {
                message_begin(MSG_ONE, get_user_msgid("ItemPickup"), _, id)
                write_string(hudnade)
                message_end()
        }
}


//##############################################################
// KNIFE ATTACK
//##############################################################
public use_knife_attack(id)
{
        // Check can attack
        if (nst_wpn_get_freezetime() || g_k_deploy[id] || !g_idle[id]) return;
        if (g_idle[id] && (get_gametime()-g_idle[id]<=g_wait_act)) return;

        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new Float:time_deploy = c_k_deploy[CURENT_WEAPON]
       
        // play anim & sound
        nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_KNIFE_ATTACK))
        set_weapons_timeidle(id, time_deploy)
        set_player_nextattack(id, time_deploy)
        PlayEmitSound(id, c_sound_hitmiss[CURENT_WEAPON], CHAN_WEAPON)
       
        // attack
        if (task_exists(id+TASK_KNIFE_ATTACK)) remove_task(id+TASK_KNIFE_ATTACK)
        set_task(c_k_time[CURENT_WEAPON], "task_knife_attack", id+TASK_KNIFE_ATTACK)
       
        // set time wait
        g_k_deploy[id] = 1
        if (task_exists(id+TASK_KNIFE_DEPLOY)) remove_task(id+TASK_KNIFE_DEPLOY)
        set_task(time_deploy, "task_knife_deploy", id+TASK_KNIFE_DEPLOY)
}
public task_knife_deploy(taskid)
{
        new id = ID_KNIFE_DEPLOY
        g_k_deploy[id] = 0
        if (task_exists(taskid)) remove_task(taskid)
}
public task_knife_attack(taskid)
{
        new id = ID_KNIFE_ATTACK
        if (task_exists(taskid)) remove_task(taskid)
       
        if (!is_user_alive(id)) return;
        knife_search_victim(id)
}
knife_search_victim(id)
{
        new CURENT_WEAPON = g_weapon[id]

        new victim, body
       
        // Get victim1
        get_user_aiming(id, victim, body)
        if (is_user_alive(victim) && get_entity_distance(id, victim) <= floatround(c_k_radius[CURENT_WEAPON]))
        {
                knife_attack_victim(id, victim, body)
                return;
        }

        // Get victim2
        new Float:aOrigin[3]
        pev(id, pev_origin, aOrigin)

        victim = 0
        new victim2 = -1
        while ((victim2 = engfunc(EngFunc_FindEntityInSphere, victim2, aOrigin, c_k_radius[CURENT_WEAPON])) != 0)
        {
                if (id==victim2 || (!is_user_alive(victim2) && !nst_scn_is_bot(victim2))) continue;
               
                new Float:vOrigin[3]
                pev(victim2, pev_origin, vOrigin)
                if(!is_in_viewcone(id, vOrigin)) continue
               
                if ( !pev_valid(victim) || (pev_valid(victim) && get_entity_distance(id, victim2)<get_entity_distance(id, victim)) )
                        victim = victim2
        }
        if (pev_valid(victim))
        {
                knife_attack_victim(id, victim, 0)
                return;
        }
       
        // attack to wall
        new aimOrigin[3], Float:aimOriginF[3]
        get_user_origin(id, aimOrigin, 3)
        aimOriginF[0] = float(aimOrigin[0])
        aimOriginF[1] = float(aimOrigin[1])
        aimOriginF[2] = float(aimOrigin[2])
        new Float:DistanceToWall = vector_distance(aOrigin, aimOriginF)
        if (DistanceToWall<=c_k_radius[CURENT_WEAPON])
        {
                new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
                set_pev(ent, pev_origin, aimOriginF)
                PlayEmitSound(id, c_sound_hitwall[CURENT_WEAPON], CHAN_WEAPON)
                engfunc(EngFunc_RemoveEntity, ent)
                return;
        }
}
knife_attack_victim(id, victim, body)
{
        // check friend fire
        if (get_user_team(id)==get_user_team(victim) && !get_pcvar_num(cvar_friendlyfire)) return;
       
        // take dama victim
        new CURENT_WEAPON = g_weapon[id]
        new Float:damage = float(knife_get_damage_attack(body))*c_k_damage[CURENT_WEAPON]
        nst_wpn_take_damage(id, victim, damage, NST_WPN_TYPEDAMAGE_NONE)
        knife_create_block_sprites(id)
        knife_create_knockback(id, victim)
        PlayEmitSound(id, c_sound_hitplayer[CURENT_WEAPON], CHAN_WEAPON)
}
knife_get_damage_attack(body)
{
        new dmg
        switch (body)
        {
                case HIT_HEAD: dmg = 60
                case HIT_CHEST: dmg = 15
                case HIT_STOMACH: dmg = 18
                case HIT_LEFTARM: dmg = 15
                case HIT_RIGHTARM: dmg = 15
                case HIT_LEFTLEG: dmg = 11
                case HIT_RIGHTLEG: dmg = 11
                case HIT_GENERIC: dmg = 15
                default: dmg = 15
        }
        return dmg
}
knife_create_block_sprites(id)
{
        new vEnd[3]
        get_user_origin(id, vEnd, 3)
       
        // Show some blood :)
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_BLOODSPRITE)
        write_coord(vEnd[0])
        write_coord(vEnd[1])
        write_coord(vEnd[2])
        write_short(cache_bloodspray)
        write_short(cache_blood)
        write_byte(75)
        write_byte(5)
        message_end()
}
knife_create_knockback(attacker, victim)
{
        new CURENT_WEAPON = g_weapon[attacker]

        new Float:Velocity[3], Float:vOrigin[3], Float:aOrigin[3], Float:fDistance
        pev(victim, pev_velocity, Velocity)
        pev(victim, pev_origin, vOrigin)
        pev(attacker, pev_origin, aOrigin)
        fDistance = get_distance_f(aOrigin, vOrigin)

        new Float:fTime = floatdiv(fDistance, float(1000))
        new Float:fVelocity[3]
        fVelocity[0] = floatdiv((vOrigin[0] - aOrigin[0]), fTime)*c_k_knockback[CURENT_WEAPON]
        fVelocity[1] = floatdiv((vOrigin[1] - aOrigin[1]), fTime)*c_k_knockback[CURENT_WEAPON]
        fVelocity[2] = floatdiv((vOrigin[2] - aOrigin[2]), fTime)*c_k_knockback[CURENT_WEAPON]
        set_pev(victim, pev_velocity, fVelocity)
        return 1
}


//##############################################################
// M134 ATTACK
//##############################################################
use_m134_attack(id, szClip, uc_handle)
{
        if (nst_wpn_get_freezetime() || !g_idle[id]) return;
        if (g_idle[id] && (get_gametime()-g_idle[id]<=g_wait_act)) return;
               
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        static buttons
        buttons = get_uc(uc_handle, UC_Buttons)
       
        new Float:time_ready = c_m_timeready[CURENT_WEAPON]
        new Float:time_canclick = 1.0
        new Float:time_idle_change = 0.5

        if ((buttons & IN_ATTACK))
        {
                if (!g_m_canclick[id] && !g_m_ready[id] && !g_m_shoot[id] && szClip)
                {
                        buttons &= ~IN_ATTACK
                        set_uc(uc_handle, UC_Buttons, buttons)
                       
                        set_weapons_timeidle(id, time_ready)
                        nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_M134_FIRE_READY))

                        g_m_ready[id] = 1
                        set_player_nextattack(id, time_ready)
                        if (task_exists(id+TASK_M134_READY)) remove_task(id+TASK_M134_READY)
                        set_task(time_ready, "task_m134_create_shoot", id+TASK_M134_READY)
                       
                        // double click
                        g_m_canclick[id] = 1
                        if (task_exists(id+TASK_M134_CANCLICK)) remove_task(id+TASK_M134_CANCLICK)
                        set_task(time_canclick, "task_m134_remove_canclick", id+TASK_M134_CANCLICK)
                }
        }
        else if ((buttons & IN_ATTACK2))
        {
                if (!g_m_canclick[id] && !g_m_ready[id] && !g_m_shoot[id] && szClip)
                {
                        buttons &= ~IN_ATTACK2
                        set_uc(uc_handle, UC_Buttons, buttons)
                       
                        set_weapons_timeidle(id, time_idle_change)
                        nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_M134_IDLE_CHANGE))

                        // create can shoot
                        g_m_ready[id] = 1
                        set_player_nextattack(id, time_ready)
                        if (task_exists(id+TASK_M134_READY)) remove_task(id+TASK_M134_READY)
                        set_task(time_ready, "task_m134_create_shoot", id+TASK_M134_READY)
                       
                        // create anim fire change
                        if (task_exists(id+TASK_M134_FIRE_CHANGE)) remove_task(id+TASK_M134_FIRE_CHANGE)
                        set_task(time_idle_change, "task_m134_create_fire_change", id+TASK_M134_FIRE_CHANGE)
                       
                        // double click
                        g_m_canclick[id] = 1
                        if (task_exists(id+TASK_M134_CANCLICK)) remove_task(id+TASK_M134_CANCLICK)
                        set_task(time_canclick, "task_m134_remove_canclick", id+TASK_M134_CANCLICK)
                }
        }
        else if (szClip)
        {       
                if (g_m_ready[id] || g_m_shoot[id])
                {
                        g_m_ready[id] = 0
                        g_m_shoot[id] = 0

                        if (task_exists(id+TASK_M134_READY)) remove_task(id+TASK_M134_READY)
                        set_weapons_timeidle(id, time_ready)
                        nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_M134_FIRE_AFTER))
                }
               
                if ((buttons & IN_RELOAD)) set_player_nextattack(id, 0.0)
        }
       
        //client_print(id, print_chat, "Ready[%i] Shoot[%i]", g_m_ready[id], g_m_shoot[id])
}
public task_m134_create_shoot(taskid)
{
        if (task_exists(taskid)) remove_task(taskid)
        new id = ID_M134_READY
        g_m_ready[id] = 0
        g_m_shoot[id] = 1
        //set_player_nextattack(id, 0.0)
}
public task_m134_remove_canclick(taskid)
{
        remove_task(taskid)
        new id = ID_M134_CANCLICK
        g_m_canclick[id] = 0
}
public task_m134_create_fire_change(taskid)
{
        remove_task(taskid)
       
        new id = ID_M134_FIRE_CHANGE
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new szClip, szAmmo
        new szWeapID = get_user_weapon( id, szClip, szAmmo )
        new Float:time_fire_change = 0.2
       
        if (szWeapID==CHANGE_WEAPON && CURENT_WEAPON && c_type[CURENT_WEAPON]==WEAPONS_M134 && (pev(id, pev_button) & IN_ATTACK2))
        {
                if (!g_attack[id]) nst_wpn_send_weapon_anim(id, get_weapon_anim(get_user_weapon(id), NST_ANI_M134_FIRE_CHANGE))
                if (szClip) set_task(time_fire_change, "task_m134_create_fire_change", id+TASK_M134_FIRE_CHANGE)
        }
}


//##############################################################
// LIGHT ATTACK
//##############################################################
use_light_attack(id)
{
        if (nst_wpn_get_freezetime() || !g_user_light[id] || g_lg_deploy[id] || !g_idle[id]) return;
        if (g_idle[id] && (get_gametime()-g_idle[id]<=g_wait_act)) return;
               
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new Float:time_deploy = c_lg_deploy[CURENT_WEAPON]
        new Float:time_attack = c_lg_timeattack[CURENT_WEAPON]
       
        // fire light
        if (task_exists(id+TASK_LIGHT_ATTACK)) remove_task(id+TASK_LIGHT_ATTACK)
        set_task(time_attack, "task_light_attack", id+TASK_LIGHT_ATTACK)

        // play anim and sound
        nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_LIGHT_ATTACK))
        set_weapons_timeidle(id, time_deploy)
        set_player_nextattack(id, 1.0)
        PlayEmitSound(id, c_sound_light_fire[CURENT_WEAPON], CHAN_WEAPON)
       
        // set time reload
        g_lg_deploy[id] = 1
        if (task_exists(id+TASK_LIGHT_DEPLOY)) remove_task(id+TASK_LIGHT_DEPLOY)
        set_task(time_deploy, "task_light_deploy", id+TASK_LIGHT_DEPLOY)

        // update nade
        g_user_light[id] -= 1
        ShowStatusIcon(id, g_user_light[id], 2)
       
        //client_print(id, print_chat, "[%i]", g_user_light[id])
}
public task_light_deploy(taskid)
{
        new id = ID_LIGHT_DEPLOY
        g_lg_deploy[id] = 0
        if (task_exists(taskid)) remove_task(taskid)
        ShowStatusIcon(id, g_user_light[id], 1)
}
public task_light_attack(taskid)
{
        if (task_exists(taskid)) remove_task(taskid)
        new id = ID_LIGHT_ATTACK
        new CURENT_WEAPON = g_weapon[id]

        // get value
        new Float: fOrigin[3], Float:fAngle[3],Float: fVelocity[3]
        pev(id, pev_origin, fOrigin)
        pev(id, pev_view_ofs, fAngle)
        fOrigin[0] += fAngle[0]
        fOrigin[1] += fAngle[1]
        fOrigin[2] += fAngle[2]
        fm_velocity_by_aim(id, 2.0, fVelocity, fAngle)
        fAngle[0] *= -1.0
       
        // create ent light
        new class_light[32]
        format(class_light, charsmax(class_light), CLASS_NAME_LIGHT, TYPE_WPN)

        new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
        set_pev(ent, pev_classname, class_light)
        engfunc(EngFunc_SetModel, ent, "models/w_hegrenade.mdl")
        set_pev(ent, pev_mins, Float:{-1.0, -1.0, -1.0})
        set_pev(ent, pev_maxs, Float:{1.0, 1.0, 1.0})
        set_pev(ent, pev_origin, fOrigin)
        fOrigin[0] += fVelocity[0]
        fOrigin[1] += fVelocity[1]
        fOrigin[2] += fVelocity[2]
        set_pev(ent, pev_movetype, MOVETYPE_BOUNCE)
        set_pev(ent, pev_gravity, 0.01)
        fVelocity[0] *= 1000.0
        fVelocity[1] *= 1000.0
        fVelocity[2] *= 1000.0
        set_pev(ent, pev_velocity, fVelocity)
        set_pev(ent, pev_angles, fAngle)
        set_pev(ent, pev_solid, SOLID_BBOX)        //store the enitty id
        set_pev(ent, pev_owner, id)
        set_pev(ent, pev_iuser1, CURENT_WEAPON)
       
        // invisible ent
        fm_set_rendering(ent, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 0)
       
        // create trail
        new value[64], key[32], trail_i, trail[3]
        format(value, charsmax(value), "%s", c_lg_colortrail[CURENT_WEAPON])
        strtolower(value)
        while (value[0] != 0 && strtok(value, key, charsmax(key), value, charsmax(value), '-'))
        {
                if (trail_i<3) trail[trail_i] = str_to_num(key)
                trail_i ++
        }
        message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
        write_byte(TE_BEAMFOLLOW)
        write_short(ent)                //entity
        write_short(cache_trail)        //model
        write_byte(5)                        //10)//life
        write_byte(3)                        //5)//width
        write_byte(trail[0])                        //r
        write_byte(trail[1])                        //g
        write_byte(trail[2])                        //b
        write_byte(200)                        //brightness
        message_end()                       

        //client_print(0, print_chat, "phong [%i][%i][%i]", trail[0], trail[1], trail[2])
}
light_explode(ent)
{
        // check ent
        if (!pev_valid(ent)) return;
       
        // get attacker idweapons
        new attacker = pev(ent, pev_owner)
        new CURENT_WEAPON = entity_get_int(ent, EV_INT_iuser1)
       
        // search victim
        new Float:entOrigin[3], Float:fDistance, Float:fDamage, Float:nade_damage, Float:nade_radius, Float:vOrigin[3]
        nade_damage = c_lg_damage[CURENT_WEAPON]
        nade_radius = c_lg_radius[CURENT_WEAPON]
        pev(ent, pev_origin, entOrigin)
        entOrigin[2] += 1.0
       
        new victim = -1
        while ((victim = engfunc(EngFunc_FindEntityInSphere, victim, entOrigin, nade_radius)) != 0)
        {
                if (attacker==victim || !pev_valid(victim)) continue;
               
                // get damage
                pev(victim, pev_origin, vOrigin)
                fDistance = get_distance_f(vOrigin, entOrigin)
                fDamage = nade_damage - floatmul(nade_damage, floatdiv(fDistance, nade_radius)) //get the damage value
                fDamage *= estimate_take_hurt(entOrigin, victim, 0) //adjust
                light_take_damage(attacker, victim, fDamage, CURENT_WEAPON)
        }
       
        // create effect exp
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(TE_EXPLOSION); // TE_EXPLOSION
        write_coord(floatround(entOrigin[0])); // origin x
        write_coord(floatround(entOrigin[1])); // origin y
        write_coord(floatround(entOrigin[2])); // origin z
        write_short(c_cache_light_exp[CURENT_WEAPON]); // sprites
        write_byte(40); // scale in 0.1's
        write_byte(30); // framerate
        write_byte(14); // flags
        message_end(); // message end

        // play sound exp
        PlayEmitSound(ent, c_sound_light_exp[CURENT_WEAPON], CHAN_WEAPON)
}
light_take_damage(attacker, victim, Float:damage, idweapon)
{
        if (damage<0.0) return;
       
        // check friend fire
        if (get_user_team(attacker)==get_user_team(victim) && !get_pcvar_num(cvar_friendlyfire)) return;
       
        // take dama victim
        nst_wpn_take_damage(attacker, victim, damage, NST_WPN_TYPEDAMAGE_NADE)
        light_create_knockback(attacker, victim, damage, idweapon)
}
light_create_knockback(attacker, victim, Float:damage, idweapon)
{
        new Float:Velocity[3], Float:vOrigin[3], Float:aOrigin[3], Float:fDistance
        pev(victim, pev_velocity, Velocity)
        pev(victim, pev_origin, vOrigin)
        pev(attacker, pev_origin, aOrigin)
        fDistance = get_distance_f(aOrigin, vOrigin)

        new Float:knockback = c_lg_knockback[idweapon]
        new Float:fTime = floatdiv(fDistance, damage)
        new Float:fVelocity[3]
        fVelocity[0] = floatdiv((vOrigin[0] - aOrigin[0]), fTime)*knockback
        fVelocity[1] = floatdiv((vOrigin[1] - aOrigin[1]), fTime)*knockback
        fVelocity[2] = floatdiv((vOrigin[2] - aOrigin[2]), fTime)*knockback
        set_pev(victim, pev_velocity, fVelocity)
}


//##############################################################
// SHOTGUN RELOAD
//##############################################################
use_shotgun_sreload(id)
{
        if (g_s_sreloading[id] || g_s_reloading[id] || !g_idle[id]) return;
        if (g_idle[id] && (get_gametime()-g_idle[id]<=g_wait_act)) return;

        nst_wpn_send_weapon_anim(id, 0)
        set_weapons_timeidle(id, 1.0)
        set_player_nextattack(id, 1.0)

        g_s_sreloading[id] = 1
        if (task_exists(id+TASK_SHOTGUN_SRELOAD)) remove_task(id+TASK_SHOTGUN_SRELOAD)
        set_task(0.1, "task_shotgun_sreload", id+TASK_SHOTGUN_SRELOAD)
}
public task_shotgun_sreload(taskid)
{
        if (task_exists(taskid)) remove_task(taskid)
        new id = ID_SHOTGUN_SRELOAD
        g_s_sreloading[id] = 0
        use_shotgun_reload(id)
}
use_shotgun_reload(id)
{
        if (g_s_reloading[id] || !g_idle[id]) return;
        if (g_idle[id] && (get_gametime()-g_idle[id]<=g_wait_act)) return;

        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new szClip, szAmmo
        get_user_weapon(id, szClip, szAmmo)
        new clip_max = get_clip_weapon(id)

        if (szClip==clip_max || !szAmmo) return;
       
        // set time reload
        new Float:time_reload = c_s_timereload[CURENT_WEAPON]
        g_s_reloading[id] = 1
        if (task_exists(id+TASK_SHOTGUN_RELOAD)) remove_task(id+TASK_SHOTGUN_RELOAD)
        set_task(time_reload, "task_shotgun_reload", id+TASK_SHOTGUN_RELOAD)

        // play anim
        nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_SHOTGUN_RELOAD))
        set_weapons_timeidle(id, time_reload)
        set_player_nextattack(id, time_reload)
       
        // bar time
        bartime(id, get_bartime(time_reload))
       
        //client_print(id, print_chat, "shotgun reload %i", get_anim_num(CHANGE_WEAPON))
}
public task_shotgun_reload(taskid)
{
        new id = ID_SHOTGUN_RELOAD
       
        // set clip ammo new
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new szClip, szAmmo
        new szWeapID = get_user_weapon(id, szClip, szAmmo)
       
        if(szWeapID == CHANGE_WEAPON && CURENT_WEAPON && c_type[CURENT_WEAPON]==WEAPONS_SHOTGUN)
        {
                new clip_max = get_clip_weapon(id)
                if (szClip>=clip_max || !szAmmo) return;
               
                new clip_set = min(clip_max, szClip+szAmmo)
                new ammo_set = max(0, szAmmo-(clip_set-szClip))
               
                give_weapon(id, clip_set, ammo_set)
               
                set_player_nextattack(id, 0.0)
        }
       
        remove_shotgun_reload(id)
}
remove_shotgun_reload(id)
{
        g_s_reloading[id] = 0
        if (task_exists(id+TASK_SHOTGUN_RELOAD)) remove_task(id+TASK_SHOTGUN_RELOAD)
        bartime(id, 0)
}


//##############################################################
// LAUNCHER ATTACK
//##############################################################
use_m203_attack(id)
{
        if (nst_wpn_get_freezetime() || !g_user_nade[id] || g_l_reloading[id] || !g_idle[id] || g_changing[id]) return;
        if (g_idle[id] && (get_gametime()-g_idle[id]<=g_wait_act)) return;
               
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new Float:time_reload = c_l_timereload[CURENT_WEAPON]
       
        // launcher grenade
        launch_grenade(id)
       
        // play anim and sound
        if (g_user_nade[id] == 1) nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_LAUNCHER_SHOOT_LAST))
        else nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_LAUNCHER_SHOOT))
        set_weapons_timeidle(id, time_reload)
        set_player_nextattack(id, time_reload)
        PlayEmitSound(id, c_sound2[CURENT_WEAPON], CHAN_WEAPON)

        // set time reload
        g_l_reloading[id] = 1
        if (task_exists(id+TASK_LAUNCHER_RELOAD)) remove_task(id+TASK_LAUNCHER_RELOAD)
        set_task(time_reload, "task_launcher_reload", id+TASK_LAUNCHER_RELOAD)

        // update nade
        g_user_nade[id] -= 1
       
        //client_print(id, print_chat, "[%i]", g_user_nade[id])
}
public task_launcher_reload(taskid)
{
        new id = ID_LAUNCHER_RELOAD
        g_l_reloading[id] = 0
        if (task_exists(taskid)) remove_task(taskid)
}
launch_grenade(id)
{
        new CURENT_WEAPON = g_weapon[id]

        // get value
        new Float: fOrigin[3], Float:fAngle[3],Float: fVelocity[3]
        pev(id, pev_origin, fOrigin)
        pev(id, pev_view_ofs, fAngle)
        fOrigin[0] += fAngle[0]
        fOrigin[1] += fAngle[1]
        fOrigin[2] += fAngle[2]
        fm_velocity_by_aim(id, 2.0, fVelocity, fAngle)
        fAngle[0] *= -1.0
       
        // create ent m203
        new class_nade[32]
        format(class_nade, charsmax(class_nade), CLASS_NAME_NADE, TYPE_WPN)
       
        new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
        set_pev(ent, pev_classname, class_nade)
        engfunc(EngFunc_SetModel, ent, c_model_s[CURENT_WEAPON])
        set_pev(ent, pev_mins, Float:{-1.0, -1.0, -1.0})
        set_pev(ent, pev_maxs, Float:{1.0, 1.0, 1.0})
        set_pev(ent, pev_origin, fOrigin)
        fOrigin[0] += fVelocity[0]
        fOrigin[1] += fVelocity[1]
        fOrigin[2] += fVelocity[2]
        set_pev(ent, pev_movetype, MOVETYPE_BOUNCE)
        set_pev(ent, pev_gravity, 0.55)
        fVelocity[0] *= 1000.0
        fVelocity[1] *= 1000.0
        fVelocity[2] *= 1000.0
        set_pev(ent, pev_velocity, fVelocity)
        set_pev(ent, pev_angles, fAngle)
        set_pev(ent, pev_solid, SOLID_BBOX)        //store the enitty id
        set_pev(ent, pev_owner, id)
        set_pev(ent, pev_iuser1, CURENT_WEAPON)
       
        // create trail
        message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
        write_byte(TE_BEAMFOLLOW)
        write_short(ent)                //entity
        write_short(cache_trail)        //model
        write_byte(6)                        //10)//life
        write_byte(3)                        //5)//width
        write_byte(224)                        //r
        write_byte(224)                        //g
        write_byte(255)                        //b
        write_byte(100)                        //brightness
        message_end()                       

        //client_print(0, print_chat, "phong")
}
grenade_explode(ent)
{
        // check ent
        if (!pev_valid(ent)) return;
       
        // get attacker idweapons
        new attacker = pev(ent, pev_owner)
        new CURENT_WEAPON = entity_get_int(ent, EV_INT_iuser1)
        if (!c_wpnchange[CURENT_WEAPON]) return;
       
        // search victim
        new Float:entOrigin[3], Float:fDistance, Float:fDamage, Float:nade_damage, Float:nade_radius, Float:vOrigin[3]
        nade_damage = c_l_damage[CURENT_WEAPON]
        nade_radius = c_l_radius[CURENT_WEAPON]
        pev(ent, pev_origin, entOrigin)
        entOrigin[2] += 1.0
       
        new victim = -1
        while ((victim = engfunc(EngFunc_FindEntityInSphere, victim, entOrigin, nade_radius)) != 0)
        {
                if (attacker==victim || !pev_valid(victim)) continue;
               
                // get damage
                pev(victim, pev_origin, vOrigin)
                fDistance = get_distance_f(vOrigin, entOrigin)
                fDamage = nade_damage - floatmul(nade_damage, floatdiv(fDistance, nade_radius)) //get the damage value
                fDamage *= estimate_take_hurt(entOrigin, victim, 0) //adjust
                grenade_take_damage(attacker, victim, fDamage, CURENT_WEAPON)
        }
       
        // create effect exp
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(TE_EXPLOSION); // TE_EXPLOSION
        write_coord(floatround(entOrigin[0])); // origin x
        write_coord(floatround(entOrigin[1])); // origin y
        write_coord(floatround(entOrigin[2])); // origin z
        write_short(c_cache_nadeexp[CURENT_WEAPON]); // sprites
        write_byte(40); // scale in 0.1's
        write_byte(30); // framerate
        write_byte(14); // flags
        message_end(); // message end

        // create effect exp
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(TE_EXPLOSION); // TE_EXPLOSION
        write_coord(floatround(entOrigin[0])); // origin x
        write_coord(floatround(entOrigin[1])); // origin y
        write_coord(floatround(entOrigin[2])); // origin z
        write_short(cache_explo); // sprites
        write_byte(40); // scale in 0.1's
        write_byte(30); // framerate
        write_byte(TE_EXPLFLAG_NONE); // flags
        message_end(); // message end
       
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)  // Rauchwolke ŃĚÔĆЧąű
        write_byte(5)
        write_coord(floatround(entOrigin[0])); // origin x
        write_coord(floatround(entOrigin[1])); // origin y
        write_coord(floatround(entOrigin[2])); // origin z
        write_short(cache_smoke)
        write_byte(35)
        write_byte(5)
        message_end()
       
        // play sound exp
        PlayEmitSound(ent, c_sound_nadeexp[CURENT_WEAPON], CHAN_WEAPON)
}
grenade_take_damage(attacker, victim, Float:damage, idweapon)
{
        if (damage<0.0) return;
       
        // check friend fire
        if (get_user_team(attacker)==get_user_team(victim) && !get_pcvar_num(cvar_friendlyfire)) return;
       
        // take dama victim
        nst_wpn_take_damage(attacker, victim, damage, NST_WPN_TYPEDAMAGE_NADE)
        grenade_create_knockback(attacker, victim, damage, idweapon)
}
grenade_create_knockback(attacker, victim, Float:damage, idweapon)
{
        new Float:Velocity[3], Float:vOrigin[3], Float:aOrigin[3], Float:fDistance
        pev(victim, pev_velocity, Velocity)
        pev(victim, pev_origin, vOrigin)
        pev(attacker, pev_origin, aOrigin)
        fDistance = get_distance_f(aOrigin, vOrigin)

        new Float:knockback = c_l_knockback[idweapon]
        new Float:fTime = floatdiv(fDistance, damage)
        new Float:fVelocity[3]
        fVelocity[0] = floatdiv((vOrigin[0] - aOrigin[0]), fTime)*knockback
        fVelocity[1] = floatdiv((vOrigin[1] - aOrigin[1]), fTime)*knockback
        fVelocity[2] = floatdiv((vOrigin[2] - aOrigin[2]), fTime)*knockback
        set_pev(victim, pev_velocity, fVelocity)
}



//##############################################################
// DOUBLE WEAPON
//##############################################################
public cmd_change_wpn(id)
{
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new szClip, szAmmo
        new szWeapID = get_user_weapon( id, szClip, szAmmo )
       
        if (c_type[CURENT_WEAPON]!=WEAPONS_DOUBLE && c_type[CURENT_WEAPON]!=WEAPONS_LAUNCHER) return;
        if (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER && (c_l_type[CURENT_WEAPON] || g_l_reloading[id])) return;

        if (szWeapID==CHANGE_WEAPON && CURENT_WEAPON)
        {
                if (g_changing[id] || !g_idle[id]) return;
                if (g_idle[id] && (get_gametime()-g_idle[id]<=g_wait_act)) return;
                change_wpn(id)
        }
        //client_print(id, print_chat, "[thay doi %i %i]", change_act[id], c_l_type[CURENT_WEAPON])
}
change_wpn(id)
{
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]

        new Float:time_change
        if (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER)
        {
                if (!g_double[id]) time_change = c_l_timechange1[CURENT_WEAPON]
                else time_change = c_l_timechange2[CURENT_WEAPON]
        }
        else if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE)
        {
                if (!g_double[id]) time_change = c_d_timechange1[CURENT_WEAPON]
                else time_change = c_d_timechange2[CURENT_WEAPON]
        }
       
        if (g_double[id])
        {
                nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_LAUNCHER_CHANGE))
                if (task_exists(id+TASK_CHANGEWPN)) remove_task(id+TASK_CHANGEWPN)
                set_task(time_change, "change_wpn_a", id+TASK_CHANGEWPN)
        }
        else
        {
                nst_wpn_send_weapon_anim(id, get_weapon_anim(CHANGE_WEAPON, NST_ANI_LAUNCHER_CHANGE))
                if (task_exists(id+TASK_CHANGEWPN)) remove_task(id+TASK_CHANGEWPN)
                set_task(time_change, "change_wpn_b", id+TASK_CHANGEWPN)
        }
        set_weapons_timeidle(id, time_change)
        set_player_nextattack(id, time_change)

        g_changing[id] = 1
        bartime(id, get_bartime(time_change))
        //client_print(id, print_chat, "[chaging]")
}
public change_wpn_a(taskid)
{
        new id = ID_CHANGEWPN
        if (g_changing[id])
        {
                g_double[id] = 0
                checkModel(id)
                nst_wpn_send_weapon_anim(id, 0)
               
                new CURENT_WEAPON = g_weapon[id]
                new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
                if (c_type[CURENT_WEAPON]==WEAPONS_LAUNCHER)
                {
                        new ent = get_weapon_ent(id,CHANGE_WEAPON)
                        cs_set_weapon_ammo(ent, g_user_clip[id])
                        cs_set_user_bpammo(id, CHANGE_WEAPON, g_user_ammo[id])
                }
               
                double_weapon_reload(id)
               
                //client_print(id, print_chat, "[%i]", g_double[id])
        }
        remove_change_wpn(id)
}
public change_wpn_b(taskid)
{
        new id = ID_CHANGEWPN
        if (g_changing[id])
        {
                g_double[id] = 1
                checkModel(id)
                nst_wpn_send_weapon_anim(id, 0)
               
                double_weapon_reload(id)
                //client_print(id, print_chat, "[%i]", g_double[id])
        }
        remove_change_wpn(id)
}


//##############################################################
// FUNCTION - TASK
//##############################################################
create_info_wmodel(ent, weapon, player)
{
        engfunc(EngFunc_SetModel, ent, c_model_w[weapon])
        set_pev(ent, pev_iuser1, g_user_clip[player])
        set_pev(ent, pev_iuser2, g_user_ammo[player])
        set_pev(ent, pev_iuser3, g_double[player])
        set_pev(ent, pev_iuser4, g_user_nade[player])
        set_pev(ent, pev_euser1, g_user_light[player])
}
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;
}
get_idwpn_from_wmodel(wmodel[])
{
        new wpnname[64], idwpn
        format(wpnname, charsmax(wpnname), "weapon_%s", wmodel)
        replace(wpnname, charsmax(wpnname), ".mdl", "")
        replace(wpnname, charsmax(wpnname), "_mp5", "_mp5navy")
        strtolower(wpnname)
        idwpn = get_weaponid(wpnname)
       
        return idwpn;
}
get_idwpn_from_model(models[])
{
        strtolower(models)
        new id
        for(new i=1; i<MAX_WPN; i++)
        {
                if (equali(c_model[i], models)) g_weapon[id] = 1 ; c_wpnchange[id] = 1
        }
        return g_weapon[id]
}
get_idweapon_from_ent(ent)
{
        new i = 1, check_value = 1
        while (check_value && i<MAX_WPN)
        {
                if (c_wpnchange[i] <= 0) check_value = 0
                else
                {
                        new model[64]
                        pev(ent, pev_model, model, charsmax(model))
                        if (equal(model, c_model_w[i])) return i;
                }
                i++
        }
       
        return 0;
}
check_has_wpn(id, type=TYPE_WPN)
{
        new weapons[32], num
        get_user_weapons(id, weapons, num)

        for (new i = 0; i < num; i++)
        {
                if (nst_get_weapon_type(weapons[i])==type) g_weapon[id] = 1
        }
}
check_has_current_wpn(id)
{
        if (!g_weapon[id]) return;
       
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        new weapons[32], num
        get_user_weapons(id, weapons, num)
        for (new i = 0; i < num; i++)
        {
                if (weapons[i] == CHANGE_WEAPON) return;
        }
        g_weapon[id] = 0
       
        return;
}
PlayEmitSound(id, const sound[], type)
{
        emit_sound(id, type, sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
}
ShowStatusIcon(id, idspr, run)
{       
        HideStatusIcon(id)
        if (idspr) StatusIcon(id, idspr, run)
}
HideStatusIcon(id)
{       
        for (new i = 1; i <= 9; i++)
        {
                StatusIcon(id, i, 0)
        }

}
StatusIcon(id, idspr, run)
{       
        message_begin(MSG_ONE, g_msgStatusIcon, {0,0,0}, id)
        write_byte(run) // status (0=hide, 1=show, 2=flash)
        write_string(GetStatusIconName(idspr)) // sprite name
        write_byte(0)// red
        write_byte(160)// green
        write_byte(0)// blue
        message_end()

}
GetStatusIconName(idspr)
{
        new sprname[33]
        format(sprname, charsmax(sprname), "number_%i", idspr)
        return sprname;
}
remove_task_running(id)
{
        if (g_s_reloading[id]) remove_shotgun_reload(id)
        if (g_changing[id]) remove_change_wpn(id)
}
set_weapons_timeidle(id, Float:timeidle)
{
        new entwpn = get_weapon_ent(id, get_user_weapon(id))
        if (pev_valid(entwpn)) set_pdata_float(entwpn, m_flTimeWeaponIdle, timeidle+3.0, 4)
}
set_player_nextattack(id, Float:nexttime)
{
        set_pdata_float(id, m_flNextAttack, nexttime, 4)
}
set_player_nexprimaryattack(id, Float:nexttime)
{
        new entwpn = get_weapon_ent(id, get_user_weapon(id))
        //set_pdata_float(id, m_flNextAttack, nexttime, 4)
        set_pdata_float(entwpn, m_flNextPrimaryAttack, nexttime, 4)
        set_pdata_float(entwpn, m_flNextSecondaryAttack, nexttime, 4)
}
create_zoom(id, uc_handle, zoom_type)
{
        // don't zoom when fastrun
        if (nst_wpn_get_user_fastrun(id)) return;
       
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]

        // check sniper weapon
        if ((CSWPN_SNIPER & (1<<CHANGE_WEAPON)) || ((CSWPN_FIRSTZOOM & (1<<CHANGE_WEAPON)) && zoom_type==ZOOMTYPE_AUG)) return;

        // create zoom
        new buttons = get_uc(uc_handle, UC_Buttons)
        if ((buttons & IN_ATTACK2) && !(pev(id, pev_oldbuttons) & IN_ATTACK2))
        {
                // remove attack2 of weapon default
                if (CSWPN_FIRSTZOOM & (1<<CHANGE_WEAPON))
                {
                        buttons &= ~IN_ATTACK2
                        set_uc(uc_handle, UC_Buttons, buttons)
                }
               
                if(!g_zoom[id] == true)
                {
                        g_zoom[id] = true
                        client_cmd(id,"spk weapons/zoom")
                       
                        if (zoom_type == ZOOMTYPE_AUG)
                        {
                                cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 0)
                        }
                        else if (zoom_type == ZOOMTYPE_SNIPER)
                        {
                                cs_set_user_zoom(id, CS_SET_FIRST_ZOOM, 0)
                        }
                        else if (zoom_type == ZOOMTYPE_SIGHT && g_idle[id])
                        {
                                // set zoom
                                nst_wpn_send_weapon_anim(id, natives_get_sightanim_weapon(id, NST_ANI_SIGHT_BEGIN))
                                set_weapons_timeidle(id, 1.0)
                               
                                // set v_sight model
                                g_sight_begin[id] = get_gametime()
                                if (task_exists(id+TASK_SIGHT_BEGIN)) remove_task(id+TASK_SIGHT_BEGIN)
                                set_task(c_sight_time[CURENT_WEAPON], "task_set_model_sight_begin", id+TASK_SIGHT_BEGIN)
                        }
                }
                else if (g_zoom[id])
                {
                        if (zoom_type == ZOOMTYPE_SIGHT)
                        {
                                nst_wpn_send_weapon_anim(id, natives_get_sightanim_weapon(id, NST_ANI_SIGHT_END))
                                set_weapons_timeidle(id, 1.0)
                        }
                        reset_zoom(id)
                }
        }
               
        // remove attack2 of weapon default if zoom
        if ( (buttons & IN_ATTACK2) && (((CSWPN_FIRSTZOOM & (1<<CHANGE_WEAPON)) && zoom_type!=ZOOMTYPE_AUG) || ((CSWPN_BURST & (1<<CHANGE_WEAPON)) && zoom_type)) )
        {
                buttons &= ~IN_ATTACK2
                set_uc(uc_handle, UC_Buttons, buttons)
        }
}
public task_set_model_sight_begin(taskid)
{
        new id = ID_SIGHT_BEGIN
        checkModel(id)
        cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 0)
}
remove_zoom(id, uc_handle)
{
        reset_zoom(id)
        remove_wpnzoom(id, uc_handle)
}
reset_zoom(id)
{
        g_zoom[id] = false
        cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
}
remove_wpnzoom(id, uc_handle)
{
        // check sniper weapons
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
        if (!( (CSWPN_SNIPER & (1<<CHANGE_WEAPON)) && (CSWPN_FIRSTZOOM & (1<<CHANGE_WEAPON)) )) return;
       
        // remove zoom of sniper
        static cmd
        if ( (cmd = get_uc(uc_handle, UC_Buttons)) & IN_ATTACK2 )
        {
                cmd &= ~IN_ATTACK2
                set_uc(uc_handle, UC_Buttons, cmd)
        }
}
change_sound_attack(id)
{
        // get weapon
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]

        // check sound
        if (!c_sound[CURENT_WEAPON]) return;
       
        // change sound
        new sound[101]
        if (g_double[id] && c_sound[CURENT_WEAPON] == 2)
        {
                if (!g_silen[id][CHANGE_WEAPON]) format(sound, charsmax(sound), "%s", c_sound2[CURENT_WEAPON])
                else format(sound, charsmax(sound), "%s", c_sound2_silen[CURENT_WEAPON])
        }
        else
        {
                if (!g_silen[id][CHANGE_WEAPON]) format(sound, charsmax(sound), "%s", c_sound1[CURENT_WEAPON])
                else format(sound, charsmax(sound), "%s", c_sound1_silen[CURENT_WEAPON])
        }
        PlayEmitSound(id, sound, CHAN_WEAPON)
}
give_weapon(id, clip, ammo)
{
        if (!c_wpnchange[id]) return;

        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]
       
        // check wpn
        if (!CHANGE_WEAPON) return;
       
        // Update user clip ammo
        g_user_clip[id] = clip
        g_user_ammo[id] = ammo
       
        // give wpn
        new WpnName[32]
        get_weaponname(CHANGE_WEAPON, WpnName, charsmax(WpnName))
        fm_give_item(id, WpnName)
        cs_set_user_bpammo(id, CHANGE_WEAPON, ammo)
        new ent = get_weapon_ent(id, CHANGE_WEAPON)
        if (ent) cs_set_weapon_ammo(ent, clip)
       
}
double_weapon_reload(id)
{
        // check type weapon
        new CURENT_WEAPON = g_weapon[id]
        if (c_type[CURENT_WEAPON]!=WEAPONS_DOUBLE) return
       
        // get clip ammo new
        new szClip, szAmmo, clip_set, ammo_set, clip_max
        get_user_weapon(id, szClip, szAmmo)
        clip_max = get_clip_weapon(id)
       
        if (szClip==clip_max || !szAmmo) return;
        else if (szClip>clip_max)
        {
                clip_set = clip_max
                ammo_set = max(0, szAmmo+(szClip-clip_max))
        }
        else if (szClip<clip_max)
        {
                clip_set = min(clip_max, szClip+szAmmo)
                ammo_set = max(0, szAmmo-(clip_set-szClip))
        }
       
        // give clip ammo new
        give_weapon(id, clip_set, ammo_set)
}
remove_change_wpn(id)
{
        g_changing[id] = 0
        if (task_exists(id+TASK_CHANGEWPN)) remove_task(id+TASK_CHANGEWPN)
        bartime(id, 0)
}
get_bartime(Float:time_change)
{
        new time_change_n = floatround(time_change)
        if (float(time_change_n) < time_change) time_change_n += 1
        return time_change_n
}
bartime(id, time_run)
{
        message_begin(MSG_ONE, get_user_msgid("BarTime"), _, id)
        write_short(time_run)
        message_end()
}
get_anim_num(wpn)
{
        new num
        if (wpn == CSW_P228) num = 7
        else if (wpn == CSW_SCOUT) num = 5
        else if (wpn == CSW_XM1014) num = 7
        else if (wpn == CSW_MAC10) num = 6
        else if (wpn == CSW_AUG) num = 6
        else if (wpn == CSW_ELITE) num = 16
        else if (wpn == CSW_FIVESEVEN) num = 6
        else if (wpn == CSW_UMP45) num = 6
        else if (wpn == CSW_SG550) num = 5
        else if (wpn == CSW_GALIL) num = 6
        else if (wpn == CSW_FAMAS) num = 6
        else if (wpn == CSW_USP) num = 16
        else if (wpn == CSW_GLOCK18) num = 13
        else if (wpn == CSW_AWP) num = 6
        else if (wpn == CSW_MP5NAVY) num = 6
        else if (wpn == CSW_M249) num = 5
        else if (wpn == CSW_M3) num = 7
        else if (wpn == CSW_M4A1) num = 14
        else if (wpn == CSW_TMP) num = 6
        else if (wpn == CSW_G3SG1) num = 5
        else if (wpn == CSW_DEAGLE) num = 6
        else if (wpn == CSW_SG552) num = 6
        else if (wpn == CSW_AK47) num = 6
        else if (wpn == CSW_P90) num = 6
       
        num -= 1
       
        return num
}
get_weapon_anim(idwpn, type)
{
        new anim = get_anim_num(idwpn)
        switch (type)
        {
                case NST_ANI_M134_FIRE_READY: anim += 1
                case NST_ANI_M134_FIRE_AFTER: anim += 2
                case NST_ANI_M134_IDLE_CHANGE: anim += 3
                case NST_ANI_M134_FIRE_CHANGE: anim += 4
                case NST_ANI_KNIFE_ATTACK: anim += 1
                case NST_ANI_LIGHT_ATTACK: anim += 1
                case NST_ANI_SHOTGUN_RELOAD: anim += 1
                case NST_ANI_LAUNCHER_CHANGE: anim += 1
                case NST_ANI_LAUNCHER_SHOOT: anim += 2
                case NST_ANI_LAUNCHER_SHOOT_LAST: anim += 3
                case NST_ANI_FASTRUN_BEGIN: anim += 1
                case NST_ANI_FASTRUN_IDLE: anim += 2
                case NST_ANI_FASTRUN_END: anim += 3
                case NST_ANI_SIGHT_BEGIN: anim += 1
                case NST_ANI_SIGHT_END: anim += 2
        }
       
        return anim
}
get_nstwpn_anim(id)
{
        new anim, wpn_type
        wpn_type = c_type[g_weapon[id]]
        switch (wpn_type)
        {
                case WEAPONS_DOUBLE: anim += 1
                case WEAPONS_KNIFE: anim += 1
                case WEAPONS_LAUNCHER: anim += 3
                case WEAPONS_SHOTGUN: anim += 1
                case WEAPONS_LIGHT: anim += 1
                case WEAPONS_M134: anim += 4
        }
       
        return anim;
}
drop_weapons(id)
{
        new weapons[32], num
        get_user_weapons(id, weapons, num)
        for (new i = 0; i < num; i++)
        {
                new type_wpn = nst_get_weapon_type(weapons[i])
                new type_wpn_cr = TYPE_WPN
                if (type_wpn == type_wpn_cr)
                {
                        static wname[32]
                        get_weaponname(weapons[i], wname, sizeof wname - 1)
                        engclient_cmd(id, "drop", wname)
                }
        }
}

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);
}

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()
}
get_clip_weapon(id)
{
        new clip
        new CURENT_WEAPON = g_weapon[id]
        if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE && g_double[id]) clip = c_d_clip[CURENT_WEAPON]
        else clip = c_clip[CURENT_WEAPON]
       
        return clip;
}
public task_remove_notpickup(taskid)
{
        new id = ID_PICKUPWPN
        g_notpickup[id] = 0
        if (task_exists(id+TASK_PICKUPWPN)) remove_task(id+TASK_PICKUPWPN)
}
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)
        {
                // buy ammmo if has weapon
                if (g_weapon[id]) cmd_buyfullammo(id)
                // buy weapon if not has
                else buy_weapon(id, get_random_weapon())
        }
}


//##############################################################
// STOCK
//##############################################################
stock Float:estimate_take_hurt(Float:fPoint[3], ent, ignored)
{
        new Float:fOrigin[3]
        new tr
        new Float:fFraction
        pev(ent, pev_origin, fOrigin)
        //UTIL_TraceLine ( vecSpot, vecSpot + Vector ( 0, 0, -40 ),  ignore_monsters, ENT(pev), & tr)
        engfunc(EngFunc_TraceLine, fPoint, fOrigin, DONT_IGNORE_MONSTERS, ignored, tr)
        get_tr2(tr, TR_flFraction, fFraction)
        if ( fFraction == 1.0 || get_tr2( tr, TR_pHit ) == ent )//no valid enity between the explode point & player
                return 1.0
        return 0.6//if has fraise, lessen blast hurt
}
stock fm_velocity_by_aim(iIndex, Float:fDistance, Float:fVelocity[3], Float:fViewAngle[3])
{
        //new Float:fViewAngle[3]
        pev(iIndex, pev_v_angle, fViewAngle)
        fVelocity[0] = floatcos(fViewAngle[1], degrees) * fDistance
        fVelocity[1] = floatsin(fViewAngle[1], degrees) * fDistance
        fVelocity[2] = floatcos(fViewAngle[0]+90.0, degrees) * fDistance
        return 1
}
stock fm_set_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16) {
        new Float:RenderColor[3];
        RenderColor[0] = float(r);
        RenderColor[1] = float(g);
        RenderColor[2] = float(b);

        set_pev(entity, pev_renderfx, fx);
        set_pev(entity, pev_rendercolor, RenderColor);
        set_pev(entity, pev_rendermode, render);
        set_pev(entity, pev_renderamt, float(amount));

        return 1;
}
// only weapon index or its name can be passed, if neither is passed then the current gun will be stripped
stock bool:fm_strip_user_gun(index, wid = 0, const wname[] = "") {
        new ent_class[32];
        if (!wid && wname[0])
                copy(ent_class, sizeof ent_class - 1, wname);
        else {
                new weapon = wid, clip, ammo;
                if (!weapon && !(weapon = get_user_weapon(index, clip, ammo)))
                        return false;
               
                get_weaponname(weapon, ent_class, sizeof ent_class - 1);
        }

        new ent_weap = fm_find_ent_by_owner(-1, ent_class, index);
        if (!ent_weap)
                return false;

        engclient_cmd(index, "drop", ent_class);

        new ent_box = pev(ent_weap, pev_owner);
        if (!ent_box || ent_box == index)
                return false;

        dllfunc(DLLFunc_Think, ent_box);

        return true;
}
stock fm_find_ent_by_owner(index, const classname[], owner, jghgtype = 0) {
        new strtype[11] = "classname", ent = index;
        switch (jghgtype) {
                case 1: strtype = "target";
                case 2: strtype = "targetname";
        }

        while ((ent = engfunc(EngFunc_FindEntityByString, ent, strtype, classname)) && pev(ent, pev_owner) != owner) {}

        return ent;
}
// 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)
}


//##############################################################
// 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_set_fullammo(id)
{
        buy_full_ammo(id)
}

public natives_get_fastrunanim_weapon(id, type)
{
        new anim = get_weapon_anim(get_user_weapon(id), type)+get_nstwpn_anim(id)
       
        return anim;
}
public natives_get_sightanim_weapon(id, type)
{
        new anim = get_weapon_anim(get_user_weapon(id), type)+get_nstwpn_anim(id)
        if (c_fastrun[g_weapon[id]]) anim += 3
       
        return anim;
}
public natives_get_user_sight(id)
{
        new CURENT_WEAPON = g_weapon[id]
        new CHANGE_WEAPON = c_wpnchange[CURENT_WEAPON]

        if (!CURENT_WEAPON || get_user_weapon(id)!=CHANGE_WEAPON) return 0;
        if (g_zoom[id])
        {
                if (!g_double[id] && c_zoom[CURENT_WEAPON]==ZOOMTYPE_SIGHT) return 1;
                else if (g_double[id] && c_d_zoom[CURENT_WEAPON]==ZOOMTYPE_SIGHT) return 1;
        }
       
        return 0;
}
public natives_get_int(id, data)
{
        new CURENT_WEAPON = g_weapon[id]
        if (!CURENT_WEAPON || get_user_weapon(id)!=c_wpnchange[CURENT_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]
                case NST_WPN_DATA_FASTRUN: result = c_fastrun[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_RELOAD:
                {
                        new Float:time_reload
                        if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE && g_double[id]) time_reload = c_d_reload[CURENT_WEAPON]
                        else time_reload = c_reload[CURENT_WEAPON]
                       
                        result = time_reload
                }
                case NST_WPN_DATA_DEPLOY:
                {
                        new Float: tdeploy
                        if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE && g_double[id]) tdeploy = c_d_deploy[CURENT_WEAPON]
                        else tdeploy = c_deploy[CURENT_WEAPON]

                        result = tdeploy
                }
                case NST_WPN_DATA_DAMAGE:
                {
                        new Float:xdamage
                        if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE && g_double[id]) xdamage = c_d_damage[CURENT_WEAPON]
                        else xdamage = c_damage[CURENT_WEAPON]

                        result = xdamage
                }
                case NST_WPN_DATA_SPEED:
                {
                        new Float:speed, zoom_type
                        if (!g_double[id])
                        {
                                speed = c_speed[CURENT_WEAPON]
                                zoom_type = c_zoom[CURENT_WEAPON]
                        }
                        else if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE)
                        {
                                speed = c_d_speed[CURENT_WEAPON]
                                zoom_type = c_d_zoom[CURENT_WEAPON]
                        }
                        if (g_zoom[id])
                        {
                                if (CSWPN_FIRSTZOOM & (1<<CHANGE_WEAPON))
                                {
                                        if (zoom_type==ZOOMTYPE_SIGHT) speed *= 2/3.5
                                }
                                else if (zoom_type!=ZOOMTYPE_SIGHT) speed *= 3/2
                        }
                       
                        result = speed
                }
                case NST_WPN_DATA_RECOIL:
                {
                        new Float:recoil
                        if (!g_double[id]) recoil = c_recoil[CURENT_WEAPON]
                        else if (c_type[CURENT_WEAPON]==WEAPONS_DOUBLE) recoil = c_d_recoil[CURENT_WEAPON]
                       
                        result = recoil
                }
        }

        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 }
*/

What i must write here
PHP Code:

public ClientCommand_SelectGun()
{



Black Rose 08-01-2013 11:44

Re: Unknow Command
 
Why did you remove what was there?

cosmin200 08-02-2013 01:24

Re: Unknow Command
 
i have done... i was create a TRI(dinamic array) to identity the original weapon id


All times are GMT -4. The time now is 16:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.