AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   I need help for the sound and model (https://forums.alliedmods.net/showthread.php?t=159140)

Ari Athelstan 06-13-2011 09:21

I need help for the sound and model
 
Well, I want to add more weapons by making a precaching model and the sound of the model. But I don't know how to make my firing weapons is come out. And every time I'm dead, the w_model going back to normal. :(

Code:

/*
Counter Strike: Online
HK23 Plugins
BlueStudy Corp. 2011
*/

#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <fun>
#include <hamsandwich>
#include <cstrike>
#include <engine>

// Info Weapon
#define CURENT_WEAPON CSW_M249
new V_MODEL[64] = "models/cso_wpn/v_hk23.mdl"
new P_MODEL[64] = "models/cso_wpn/p_hk23.mdl"
new W_MODEL[64] = "models/cso_wpn/w_hk23.mdl"
new class_weapon[34] = "cso_hk23"
new name_weapon[64] = "HK23"

#define is_valid_player(%1) (1 <= %1 <= 32)
new cost_by_ammo = 60
new cvar_dmgmultiplier, cvar_uclip, cvar_speed, cvar_zoom, cvar_clip, cvar_ammo, cvar_recoil, cvar_cost
new bool:G_HasWp[33]
new g_hasZoom[ 33 ]
const Wep_drop = ((1<<CURENT_WEAPON))
new szWeapon[17]
new Float:cl_pushangle[33][3]

////////////////////////////////// Ammo //////////////////////////////////

const SILENT_BS        = ((1<<CSW_USP)|(1<<CURENT_WEAPON))

// weapons offsets
const m_pPlayer                        = 41
const m_iId                                = 43
const m_fKnown                                = 44
const m_flNextPrimaryAttack        = 46
const m_flNextSecondaryAttack        = 47
const m_flTimeWeaponIdle                = 48
const m_iPrimaryAmmoType                = 49
const m_iClip                                = 51
const m_fInReload                        = 54
const m_fInSpecialReload                = 55
const m_fSilent                        = 74
const m_flNextAttack                = 83
const m_rgAmmo_player_Slot0        = 376

stock const g_iDftMaxClip[CSW_P90+1] = {
        -1,  13, -1, 10,  1,  7,    1, 30, 30,  1,  30,
                20, 25, 30, 35, 25,  12, 20, 10, 30, 100,
                8 , 30, 30, 20,  2,    7, 30, 30, -1,  50}
               
stock const g_iReloadAnims[CSW_P90+1] = {
        -1,  5, -1, 3, -1,  6,  -1, 1, 1, -1, 14,
                4,  2, 3,  1,  1,  13, 7, 4,  1,  3,
                6, 11, 1,  3, -1,    4, 1, 1, -1,  1}
               
stock const Float:g_fDelay[CSW_P90+1] = {
        0.00, 2.70, 0.00, 2.00, 0.00, 0.55,  0.00, 3.15, 3.30, 0.00, 4.50,
                2.70, 3.50, 3.35, 2.45, 3.30,  2.70, 2.20, 2.50, 2.63, 4.70,
                0.55, 3.05, 2.12, 3.50, 0.00,  2.20, 3.00, 2.45, 0.00, 3.40
}
new const AMMOID[] = { -1, 9, -1, 2, 12, 5, 14, 6, 4, 13, 10, 7, 6, 4, 4, 4, 6, 10,
                        1, 10, 3, 5, 4, 10, 2, 11, 8, 4, 2, -1, 7 }


public plugin_init()
{
        register_plugin("HK23", "1.0", "Ari Athelstan.Mc")
       
       
        cvar_dmgmultiplier = register_cvar("cso_hk416_dmg", "2")
        cvar_uclip = register_cvar("cso_hk416_uclip", "0.7")
        cvar_speed = register_cvar("cso_hk416_speed","1")
        cvar_zoom = register_cvar("cso_hk416_zoom","1")
        cvar_clip = register_cvar("cso_hk416_clip","100")
        cvar_ammo = register_cvar("cso_hk416_ammo","200")
        cvar_recoil = register_cvar("cso_hk416_recoil","0")
        cvar_cost = register_cvar("cso_hk416_cost","5000")


        register_event("DeathMsg", "Death", "a")
        register_event("CurWeapon","checkWeapon","be","1=1")
        //register_event("WeapPickup","checkModel","b","1=19")

        // Ham
        RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
        RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)
        get_weaponname(CURENT_WEAPON, szWeapon, charsmax(szWeapon))
        RegisterHam(Ham_Item_PostFrame, szWeapon, "Item_PostFrame")
        register_forward( FM_CmdStart, "fw_CmdStart" )
       
        // Recoil
        RegisterHam(Ham_Weapon_PrimaryAttack, szWeapon, "fw_primary_attack")
        RegisterHam(Ham_Weapon_PrimaryAttack, szWeapon, "fw_primary_attack_post",1)

        // Command
        register_clcmd("cso_hk23","buy_weapon")
        register_clcmd("drop","dropcmd", 0)
        register_clcmd("buyammo1","buy_ammo", 0)
        register_clcmd("primammo","buy_ammo", 0)
       
}

// Other Public
public plugin_precache()
{
        precache_model(V_MODEL)
        precache_model(P_MODEL)
        precache_model(W_MODEL)
}

public client_connect(id)
{
        G_HasWp[id] = false
}

public client_disconnect(id)
{
        G_HasWp[id] = false
}

public Death()
{
        G_HasWp[read_data(2)] = false
}

public fwHamPlayerSpawnPost(id)
{
        //G_HasWp[id] = false
}
// End Other Public


// Buy Weapon
public buy_weapon(id)
{
        new plrClip, plrAmmo
        get_user_weapon(id, plrClip , plrAmmo)

        new user_money = cs_get_user_money(id);
        new wp_cost = get_pcvar_num(cvar_cost);
        new user_clip = get_pcvar_num(cvar_clip)
        new user_ammo = get_pcvar_num(cvar_ammo)
               
        if(!is_user_alive(id))
        {
                client_print(id, print_chat, "[CSO] You can only buy Weapons when alive");
        }
        else if(user_money < wp_cost)
        {
                client_print(id, print_chat, "[CSO] You can't afford that!");
        }
        else if(G_HasWp[id])
        {
                if (plrAmmo != user_ammo && user_money >= cost_by_ammo) buy_ammo(id)
                else client_print(id, print_chat, "[CSO] You already have a hk416")
        }
        else
        {
                drop_prim(id)
                give_weapon(id, user_clip, user_ammo)
                cs_set_user_money(id, user_money-wp_cost)
                client_print(id, print_chat, "[CSO] You bought hk416")
        }

       
}
// End Buy Weapon


// Buy Ammo
public buy_ammo(id)
{
        new plrClip, plrAmmo, plrWeapId
        plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
        new user_clip = get_pcvar_num(cvar_clip)
        new user_ammo = get_pcvar_num(cvar_ammo)
        new ammo_show = (user_ammo-plrAmmo) + (user_clip-plrClip)
        new user_money = cs_get_user_money(id)
       
        if(plrWeapId == CURENT_WEAPON && G_HasWp[id] && user_money >= cost_by_ammo && plrAmmo != user_ammo)
        {
                show_hud_ammo(id, ammo_show)
                cs_set_user_money(id, user_money-cost_by_ammo)
                give_weapon(id, user_clip, user_ammo)
        }
}
// End Buy Ammo


// Show Hud Ammo
public show_hud_ammo(id,ammo)
{
        new plrClip, plrAmmo, plrWeapId
        plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
       
        message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("AmmoPickup"), _, id)
        write_byte(AMMOID[plrWeapId]) // ammo id
        write_byte(ammo) // ammo amount
        message_end()
}
// End Show Hud Ammo


// Check Weapon
public checkModel(id)
{

        new szWeapID = read_data(2)
       
        if ( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
        {
                set_pev(id, pev_viewmodel2, V_MODEL)
                set_pev(id, pev_weaponmodel2, P_MODEL)
        }
        return PLUGIN_HANDLED
}

public checkWeapon(id)
{
        new plrClip, plrAmmo, plrWeapId
        plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
       
        if (plrWeapId == CURENT_WEAPON && G_HasWp[id])
        {
                checkModel(id)

                // Speed
                new Ent = get_weapon_ent(id,plrWeapId)
                new Float:N_Speed
                if(Ent)
                {
                        N_Speed = get_pcvar_float(cvar_speed)
                        new Float:Delay = get_pdata_float( Ent, 46, 4) * N_Speed       
                        if (Delay > 0.0) {
                                set_pdata_float( Ent, 46, Delay, 4)
                        }
                }
        }
       
        return PLUGIN_HANDLED
}
// End Check Weapon


// Control Damage
public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
    if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CURENT_WEAPON && G_HasWp[attacker] )
    {
        SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
    }
}
// End Control Damage



// Zoom Wepaon
public fw_CmdStart( id, uc_handle, seed )
{
        if( !is_user_alive( id ) )
                return PLUGIN_HANDLED
       
       
        new szClip, szAmmo
        new szWeapID = get_user_weapon( id, szClip, szAmmo )
       
        if( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
        {
                // UClip
                if (get_pcvar_num(cvar_uclip))
                {
                        new ent = get_weapon_ent(id,CURENT_WEAPON)
                        cs_set_weapon_ammo(ent, get_pcvar_num(cvar_clip))
                }
        }
       
        if (g_hasZoom[ id ] && (pev(id, pev_button) & IN_RELOAD))
        {
                g_hasZoom[ id ] = false
                cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
        }
       
       
        return PLUGIN_HANDLED
}
// End Zoom Wepaon


// Recoil of Weapon
public fw_primary_attack(ent)
{
        new id = pev(ent,pev_owner)
        pev(id,pev_punchangle,cl_pushangle[id])
       
        return HAM_IGNORED
}
public fw_primary_attack_post(ent)
{
        new id = pev(ent,pev_owner)
        new szClip, szAmmo
        new szWeapID = get_user_weapon( id, szClip, szAmmo )
       
        if( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
        {
                new Float:push[3]
                pev(id,pev_punchangle,push)
                xs_vec_sub(push,cl_pushangle[id],push)
               
                xs_vec_mul_scalar(push,get_pcvar_float(cvar_recoil),push)
                xs_vec_add(push,cl_pushangle[id],push)
                set_pev(id,pev_punchangle,push)
        }
       
        return HAM_IGNORED
}
// End Recoil of Weapon


// Drop Weapon
public dropcmd(id)
{
        new plrClip, plrAmmo
        new plrWeapId
        plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
       
        if(plrWeapId == CURENT_WEAPON && G_HasWp[id] && is_user_alive(id)) {
                new Float:Aim[3],Float:origin[3]
                VelocityByAim(id, 64, Aim)
                entity_get_vector(id,EV_VEC_origin,origin)
               
                origin[0] += 2*Aim[0]
                origin[1] += 2*Aim[1]
               
                new sec_c = get_systime()
                new classname[32]
                format (classname ,32, "%s_%i", class_weapon, sec_c);
                new cso_cre_class = create_entity("info_target")
                entity_set_string(cso_cre_class,EV_SZ_classname,classname)
                entity_set_model(cso_cre_class,W_MODEL)       
               
                entity_set_size(cso_cre_class,Float:{-2.0,-2.0,-2.0},Float:{5.0,5.0,5.0})
                entity_set_int(cso_cre_class,EV_INT_solid,1)
               
                entity_set_int(cso_cre_class,EV_INT_movetype,6)
                entity_set_int(cso_cre_class, EV_INT_iuser1, plrClip)
                entity_set_int(cso_cre_class, EV_INT_iuser2, plrAmmo)
                entity_set_vector(cso_cre_class,EV_VEC_origin,origin)
                G_HasWp[id] = false
                remowegun(id)
               
                return PLUGIN_HANDLED
        }
        return PLUGIN_CONTINUE
}
// End Drop Weapon


// Weapon Pickup
public pfn_touch(ptr, ptd) {
        if(is_valid_ent(ptr)) {
                new len_classwp = strlen(class_weapon)
                new classname[32], classname_l[33], classname_r[33]
                entity_get_string(ptr,EV_SZ_classname,classname,31)
                strbreak(classname,classname_l,len_classwp,classname_r,3)
               
                if(equal(classname_l, class_weapon)) {
                        if(is_valid_ent(ptd)) {
                                new id = ptd
                                if(id > 0 && id < 34) {
                                        new has_wpn1 = check_wpn1(id)
                                        if(!has_wpn1 && !G_HasWp[id] && is_user_alive(id)) {
                                                give_weapon(id,entity_get_int(ptr, EV_INT_iuser1), entity_get_int(ptr, EV_INT_iuser2))
                                                remove_entity(ptr)
                                        }
                                }
                        }
                }
        }
}
// End Weapon Pickup


// Remove gun and save all guns
public remowegun(id) {
        new wpnList[32]
        new number
        get_user_weapons(id,wpnList,number)
        for (new i = 0;i < number ;i++) {
                if (wpnList[i] == CURENT_WEAPON) {
                        fm_strip_user_gun(id, wpnList[i])
                }
        }
}

//Give wpn
public give_weapon(id, clip, ammo){
        G_HasWp[id] = true
        give_item(id,szWeapon)
        cs_set_user_bpammo(id, CURENT_WEAPON, ammo)
        new ent = get_weapon_ent(id,CURENT_WEAPON)
        cs_set_weapon_ammo(ent, clip)
}


// Give Ammo Clip
public Item_PostFrame(iEnt)
{
        static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)
        new plrClip, plrAmmo, plrWeapId
        plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
       
        if (plrWeapId == CURENT_WEAPON && G_HasWp[id])
        {

        static iId ; iId = get_pdata_int(iEnt, m_iId, 4)
        static iMaxClip ; iMaxClip = get_pcvar_num(cvar_clip)
        static fInReload ; fInReload = get_pdata_int(iEnt, m_fInReload, 4)
        static Float:flNextAttack ; flNextAttack = get_pdata_float(id, m_flNextAttack, 5)

        static iAmmoType ; iAmmoType = m_rgAmmo_player_Slot0 + get_pdata_int(iEnt, m_iPrimaryAmmoType, 4)
        static iBpAmmo ; iBpAmmo = get_pdata_int(id, iAmmoType, 5)
        static iClip ; iClip = get_pdata_int(iEnt, m_iClip, 4)


        if( fInReload && flNextAttack <= 0.0 )
        {
                new j = min(iMaxClip - iClip, iBpAmmo)
                set_pdata_int(iEnt, m_iClip, iClip + j, 4)
                set_pdata_int(id, iAmmoType, iBpAmmo-j, 5)               
                set_pdata_int(iEnt, m_fInReload, 0, 4)
                fInReload = 0
        }
       
        static iButton ; iButton = pev(id, pev_button)
        if(        (iButton & IN_ATTACK2 && get_pdata_float(iEnt, m_flNextSecondaryAttack, 4) <= 0.0)
        ||        (iButton & IN_ATTACK && get_pdata_float(iEnt, m_flNextPrimaryAttack, 4) <= 0.0)        )
        {
                return
        }
       
        if( iButton & IN_RELOAD && !fInReload )
        {
                if( iClip >= iMaxClip )
                {
                        set_pev(id, pev_button, iButton & ~IN_RELOAD)
                        if( SILENT_BS & (1<<iId) && !get_pdata_int(iEnt, m_fSilent, 4) )
                        {
                                SendWeaponAnim( id, iId == CSW_USP ? 8 : 7 )
                        }
                        else
                        {
                                SendWeaponAnim(id, 0)
                        }
                }
                else if( iClip == g_iDftMaxClip[iId] )
                {
                        if( iBpAmmo )
                        {
                                set_pdata_float(id, m_flNextAttack, g_fDelay[iId], 5)

                                if( SILENT_BS & (1<<iId) && get_pdata_int(iEnt, m_fSilent, 4) )
                                {
                                        SendWeaponAnim( id, iId == CSW_USP ? 5 : 4 )
                                }
                                else
                                {
                                        SendWeaponAnim(id, g_iReloadAnims[iId])
                                }
                                set_pdata_int(iEnt, m_fInReload, 1, 4)

                                set_pdata_float(iEnt, m_flTimeWeaponIdle, g_fDelay[iId] + 0.5, 4)
                        }
                }
        }
       
        }
}
SendWeaponAnim(id, iAnim)
{
        set_pev(id, pev_weaponanim, iAnim)

        message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, id)
        write_byte(iAnim)
        write_byte(pev(id,pev_body))
        message_end()
}
// End Give Ammo Clip


// Stock
stock drop_prim(id)
{
        new weapons[32], num
        get_user_weapons(id, weapons, num)
        for (new i = 0; i < num; i++) {
                if (weapons[i] == CSW_SCOUT || weapons[i] == CSW_XM1014 || weapons[i] == CSW_MAC10 || weapons[i] == CSW_AUG || weapons[i] == CSW_UMP45 || weapons[i] == CSW_SG550 || weapons[i] == CSW_GALIL || weapons[i] == CSW_FAMAS || weapons[i] == CSW_AWP || weapons[i] == CSW_MP5NAVY || weapons[i] == CSW_M249 || weapons[i] == CSW_M3 || weapons[i] == CSW_M4A1 || weapons[i] == CSW_TMP || weapons[i] == CSW_G3SG1 || weapons[i] == CSW_SG552 || weapons[i] == CSW_AK47 || weapons[i] == CSW_P90)
                {
                        static wname[32]
                        get_weaponname(weapons[i], wname, sizeof wname - 1)
                        engclient_cmd(id, "drop", wname)
                        G_HasWp[id] = false
                }
        }
}
//get weapon id
stock get_weapon_ent(id,wpnid=0,wpnName[]="")
{
        // who knows what wpnName will be
        static newName[24];

        // need to find the name
        if(wpnid) get_weaponname(wpnid,newName,23);

        // go with what we were told
        else formatex(newName,23,"%s",wpnName);

        // prefix it if we need to
        if(!equal(newName,"weapon_",7))
                format(newName,23,"weapon_%s",newName);

        return fm_find_ent_by_owner(get_maxplayers(),newName,id);
}

check_wpn1(id)
{
        new weapons[32], num, wpn1 = 0
        get_user_weapons(id, weapons, num)
        for (new i = 0; i < num; i++) {
                if (weapons[i] == CSW_SCOUT || weapons[i] == CSW_XM1014 || weapons[i] == CSW_MAC10 || weapons[i] == CSW_AUG || weapons[i] == CSW_UMP45 || weapons[i] == CSW_SG550 || weapons[i] == CSW_GALIL || weapons[i] == CSW_FAMAS || weapons[i] == CSW_AWP || weapons[i] == CSW_MP5NAVY || weapons[i] == CSW_M249 || weapons[i] == CSW_M3 || weapons[i] == CSW_M4A1 || weapons[i] == CSW_TMP || weapons[i] == CSW_G3SG1 || weapons[i] == CSW_SG552 || weapons[i] == CSW_AK47 || weapons[i] == CSW_P90)
                {
                        wpn1 = 1
                }

        }
        return wpn1
}

Will I'm using NST script for learning :wink:
Can anyone help me for this ? :( I really need your help guys. I'm new on this :(


All times are GMT -4. The time now is 23:25.

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