View Single Post
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-10-2021 , 09:26   Re: All new Back weapon
Reply With Quote #10

here you go, doesn't require a custom model

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <xs>

#define PLUGIN "Weapon Backpack"
#define VERSION "1.0"
#define AUTHOR "Natsheh"

#define BACKPACK_BONE 52

static Float:fBACKPACK_ORIGIN[3], ENT_PLAYER[33];

public 
plugin_precache() {
    new 
mdl_index precache_model("models/player/terror/terror.mdl");
    new 
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    
    if(
ent 0)
    {
        
engfunc(EngFunc_SetModelent"models/player/terror/terror.mdl");
        
set_pev(entpev_modelindexmdl_index);
        
        new 
Float:null[3];
        
engfunc(EngFunc_GetBonePositionentBACKPACK_BONEfBACKPACK_ORIGINnull)
        
        
set_pev(entpev_flagsFL_KILLME);
        
dllfunc(DLLFunc_Thinkent);
    }
    else
    {
        
set_fail_state("Couldn't Create an entity");
    }
}


public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("DeathMsg""fw_deathmsg""a");
    
    
RegisterHam(Ham_Spawn"player""fw_player_spawn"1);
    
    for(new 
i=CSW_P228szClassname[32]; <= CSW_P90i++)
    {
        if((
get_weaponname(iszClassnamecharsmax(szClassname)) > 7) && ((1<<i) & (CSW_ALL_PISTOLS|CSW_ALL_GRENADES|(1<<CSW_KNIFE))))
        {
            
RegisterHam(Ham_Item_DeployszClassname"fw_weapon_deploy"true);
        }
        else if(
szClassname[0] != 0)
        {
            
RegisterHam(Ham_Item_DeployszClassname"fw_weapon_remove"true);
        }
    }
    
    
register_forward(FM_PlayerPreThink"fw_player_prethink");
}

public 
fw_player_prethink(id)
{
    if(
ENT_PLAYER[id] == 0) return;
    
    static 
entFloat:fOrigin[3], Float:fOrigin2[3], Float:fAngles[3];
    
ent ENT_PLAYER[id];
    
    
pev(idpev_originfOrigin);
    
pev(idpev_anglesfAngles);
    
    
fOrigin2[0] = fBACKPACK_ORIGIN[0] * floatcos(fAngles[1],degrees) - fBACKPACK_ORIGIN[1] * floatsin(fAngles[1],degrees);
    
fOrigin2[1] = fBACKPACK_ORIGIN[0] * floatsin(fAngles[1],degrees) + fBACKPACK_ORIGIN[1] * floatcos(fAngles[1],degrees);
    
fOrigin2[2] = fBACKPACK_ORIGIN[2];
    
xs_vec_add(fOriginfOrigin2fOrigin);
    
    
engfunc(EngFunc_SetOriginentfOrigin);
    
    
fAngles[0] = -90.0;
    
set_pev(entpev_anglesfAngles);
}

public 
fw_weapon_remove(iEnt)
{
    new 
id pev(iEntpev_owner), ent;
    
    if(
id && (ent=ENT_PLAYER[id]) > 0)
    {
        
engfunc(EngFunc_SetModelent"");
    }
}

public 
fw_weapon_deploy(iEnt)
{
    new 
id pev(iEntpev_owner), ent;
    
    if(
id && (ent=ENT_PLAYER[id]) > 0)
    {
        
engfunc(EngFunc_SetModelent"");
        
        new 
aWeapons[32], wpnum 0currwpn;
        
get_user_weapons(idaWeaponswpnum);
        
        
currwpn = (1<<get_ent_data(iEnt"CBasePlayerItem""m_iId")); // get used weapon...
        
        
for(new 0szString[64], szClassname[32]; wpnumi++)
        {
            if( ( (
1<<aWeapons[i]) & ( 0x7FFFFFFE & ~(currwpn|CSW_ALL_PISTOLS|CSW_ALL_GRENADES|(1<<CSW_KNIFE)) ) ) > 0)
            {
                if(
get_weaponname(aWeapons[i], szClassnamecharsmax(szClassname)) > 7) {
                    if(
aWeapons[i] == CSW_MP5NAVYszClassname[11] = 0;
                    
formatex(szStringcharsmax(szString), "models/w_%s.mdl"szClassname[7]);
                    
engfunc(EngFunc_SetModelentszString);
                    break;
                }
            }
        }
    }
}

public 
fw_player_spawn(id)
{
    if(!
is_user_alive(id) || ENT_PLAYER[id] > 0) return;
    
    new 
ent ENT_PLAYER[id] = engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    
    if(
ent 0)
    {
        new 
Float:fOrigin[3];
        
pev(idpev_originfOrigin);
        
        
fOrigin[0] += fBACKPACK_ORIGIN[0];
        
fOrigin[1] += fBACKPACK_ORIGIN[1];
        
fOrigin[2] += fBACKPACK_ORIGIN[2];
        
        
engfunc(EngFunc_SetOriginentfOrigin);
        
        
set_pev(entpev_movetypeMOVETYPE_NONE);
        
set_pev(entpev_solidSOLID_NOT);
    }
}

public 
client_disconnect(vic)
{
    new 
ent;
    if(!
pev_valid((ent=ENT_PLAYER[vic]))) return;
    
    
set_pev(entpev_flagsFL_KILLME);
    
dllfunc(DLLFunc_Thinkent);
    
    
ENT_PLAYER[vic] = 0;
}

public 
fw_deathmsg()
{
    const 
DEATHMSG_VICTIM_ARGUMENT 2;
    
    new 
vic read_data(DEATHMSG_VICTIM_ARGUMENT);
    
    new 
ent;
    if(!
pev_valid((ent=ENT_PLAYER[vic]))) return;
    
    
set_pev(entpev_flagsFL_KILLME);
    
dllfunc(DLLFunc_Thinkent);
    
    
ENT_PLAYER[vic] = 0;

making something already been made is kind useless and waste of time, if you think of making something more unique would be alot better.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-18-2021 at 07:03. Reason: fixed mp5 crash.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh