View Single Post
SoulWeaver16
Senior Member
Join Date: May 2021
Location: Uruguay
Old 04-16-2023 , 14:45   Re: Extended Arm Weapon Skin 2.0 [CS/CZ] {22 Aug 2022}
Reply With Quote #27

Quote:
Originally Posted by lexzor View Post
i can't install the plugin on my server, saying the native from setviewentitybody2 does not exists even if i installed it correctly

anyways, the above problem can be cause by stopping precaching default models from the game.

tried to avoid unprecaching default models when this feature is enabled


PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define SHIELD_SUPPORT
//Shield can be disabled by changing code: //#define SHIELD_SUPPORT

#define DEFAULT_MODE
//This add the ability of the players to toggle if the plugin is active for them or not

#if defined DEFAULT_MODE
    #include <amxconst>
    #include <nvault>

    
new const CHAT_TAG[] = "^4[ARM SKIN]^1" //Tag chat when toggle the weapon skinn view
    
new const PRUNE_DAYS 30 //After how many days the inactive entries will be deleted
    
new const bool:DEFAULT_VALUE true //Default value for players that never toggled model changer. True means that players skin will be changed by default until they disable it
#endif

//Linux diff
const XO_WEAPON 4

// CBasePlayerItem
const m_pPlayer 41 // CBasePlayer *

native cs_set_viewmodel_body(iPlayeriValue);    //This will set v_ .mdl body (PlayerIndex, Bodygroup number)

enum _:BodyID
{
    
Arctic,
    
Gign,
    
GSG9,
    
Guerilla,
    
Leet,
    
SAS,
    
Terror,
    
Urban,
    
VIP,
    
Militia,
    
Spetsnaz
}

new const 
g_szModelName[BodyID][] =
{
    
"arctic",
    
"gign",
    
"gsg9",
    
"guerilla",
    
"leet",
    
"sas",
    
"terror",
    
"urban",
    
"vip",
    
"militia",
    
"spetsnaz"
}

new const 
g_szUserInfoModel[] = "model"
new const g_szWeaponNameMp5Navy[] = "weapon_mp5navy"
new const g_szNewWeaponDirectoryMp5Navy[] = "models/extended/v_mp5.mdl"

new const g_szWeaponNamePrefix[] = "weapon_"
new const g_szNewWeaponDirectory[] = "models/extended/v_"
new const g_szModelNameExtension[] = ".mdl"

new Trie:g_tModels

#if defined DEFAULT_MODE
    
new const g_szVaultName[] = "extended_arm_weapon_skin"
    
new g_iVault
    
new bool:g_bActive[MAX_PLAYERS+1]
    new 
g_szAuthID[MAX_PLAYERS+1][MAX_AUTHID_LENGTH]
#endif

//Weapon ents
new g_szWeaponNames[][] = {"weapon_knife""weapon_glock18""weapon_ak47""weapon_aug""weapon_awp""weapon_c4""weapon_deagle""weapon_elite""weapon_famas"
    
"weapon_fiveseven""weapon_flashbang""weapon_g3sg1""weapon_galil""weapon_hegrenade""weapon_m3""weapon_xm1014""weapon_m4a1""weapon_m249""weapon_mac10"
    
"weapon_mp5navy""weapon_p90""weapon_p228""weapon_scout""weapon_sg550""weapon_sg552""weapon_smokegrenade""weapon_tmp""weapon_ump45""weapon_usp" }

//Old models to unprecache
new g_szOldModels[][] = {"models/v_knife.mdl""models/v_glock18.mdl""models/v_ak47.mdl""models/v_aug.mdl""models/v_awp.mdl""models/v_c4.mdl" "models/v_deagle.mdl"
    
"models/v_elite.mdl""models/v_famas.mdl""models/v_fiveseven.mdl""models/v_flashbang.mdl""models/v_g3sg1.mdl""models/v_galil.mdl""models/v_hegrenade.mdl"
    
"models/v_m3.mdl""models/v_xm1014.mdl""models/v_m4a1.mdl""models/v_m249.mdl""models/v_mac10.mdl""models/v_mp5.mdl""models/v_p90.mdl""models/v_p228.mdl"
    
"models/v_scout.mdl""models/v_sg550.mdl""models/v_sg552.mdl""models/v_smokegrenade.mdl""models/v_tmp.mdl""models/v_ump45.mdl""models/v_usp.mdl" }

//New models to precache
new g_szNewModels[][] = {"models/extended/v_knife.mdl""models/extended/v_glock18.mdl""models/extended/v_ak47.mdl""models/extended/v_aug.mdl""models/extended/v_awp.mdl"
    
"models/extended/v_c4.mdl" "models/extended/v_deagle.mdl""models/extended/v_elite.mdl""models/extended/v_famas.mdl""models/extended/v_fiveseven.mdl"
    
"models/extended/v_flashbang.mdl""models/extended/v_g3sg1.mdl""models/extended/v_galil.mdl""models/extended/v_hegrenade.mdl""models/extended/v_m3.mdl"
    
"models/extended/v_xm1014.mdl""models/extended/v_m4a1.mdl""models/extended/v_m249.mdl""models/extended/v_mac10.mdl""models/extended/v_mp5.mdl""models/extended/v_p90.mdl"
    
"models/extended/v_p228.mdl""models/extended/v_scout.mdl""models/extended/v_sg550.mdl""models/extended/v_sg552.mdl""models/extended/v_smokegrenade.mdl""models/extended/v_tmp.mdl"
    
"models/extended/v_ump45.mdl""models/extended/v_usp.mdl"}

#if defined SHIELD_SUPPORT
// Old shield models to unprecache:
new g_szOldShieldModels[][] = {"models/shield/v_shield_usp.mdl""models/shield/v_shield_fiveseven.mdl""models/shield/v_shield_deagle.mdl",
    
"models/shield/v_shield_p228.mdl""models/shield/v_shield_knife.mdl""models/shield/v_shield_glock18.mdl",
    
"models/shield/v_shield_flashbang.mdl""models/shield/v_shield_hegrenade.mdl""models/shield/v_shield_smokegrenade.mdl"}

//New shield models to precache
new g_szNewShieldModels[][] = {"models/extended/v_shield_knife.mdl""models/extended/v_shield_glock18.mdl""models/extended/v_shield_deagle.mdl",
    
"models/extended/v_shield_fiveseven.mdl""models/extended/v_shield_flashbang.mdl""models/extended/v_shield_hegrenade.mdl",
    
"models/extended/v_shield_p228.mdl""models/extended/v_shield_smokegrenade.mdl""models/extended/v_shield_usp.mdl"}
    
new const 
g_szNewWeaponDirectoryShield[] = "models/extended/v_shield_"
#endif

new bool:IsUserAdmin[MAX_PLAYERS+1], g_pcvAdminFlagg_pcvAdminSking_pcvDefaultSkin

public plugin_init()
{
    
register_plugin("Extended Arm Weapon Skin""2.0""KayDee")
    
    
g_pcvAdminFlag register_cvar("eaws_admin_flag""")
    
g_pcvAdminSkin register_cvar("eaws_admin_skin""8")
    
g_pcvDefaultSkin register_cvar("eaws_default_skin""3")
    
    for(new 
isizeof g_szWeaponNamesi++)
    {
        
RegisterHam(Ham_Item_Deployg_szWeaponNames[i], "ItemDeployPost"1)
    }

    
g_tModels TrieCreate()
    
    for(new 
0BodyIDi++)
    {
        
TrieSetCell(g_tModelsg_szModelName[i], i)
    }

    
#if defined DEFAULT_MODE
    
if((g_iVault nvault_open(g_szVaultName)) == INVALID_HANDLE)
    {
        
set_fail_state("Vault file ^"%s^" coudln't be opened!"g_szVaultName)
    }

    
nvault_prune(g_iVault0get_systime() - (PRUNE_DAYS 86400))

    
register_clcmd("say /armskin""toggleCmd")
    
register_clcmd("say_team /armskin""toggleCmd")
    
register_clcmd("amx_armskin""toggleCmd")
    
#endif
}

#if defined DEFAULT_MODE
public plugin_end()
{
    
nvault_close(g_iVault)
}

public 
toggleCmd(id)
{
    
g_bActive[id] = !g_bActive[id]

    
client_print_color(idprint_team_default"%s You^4 %s^1 arm skin!"CHAT_TAGg_bActive[id] ? "enabled" "disabled")

    
nvault_set(g_iVaultg_szAuthID[id], fmt("%i"g_bActive[id] ? "1" "0"))
}
#endif

public plugin_precache()
{
    
register_forward(FM_PrecacheModel"Forward_PrecacheModel"0)    //Unprecache old viewmodels

    
for(new isizeof g_szNewModelsi++)
    {
        
precache_model(g_szNewModels[i])    //Precache now new viewmodels
    
}

    
#if defined SHIELD_SUPPORT
    
for(new isizeof g_szNewShieldModelsi++)
    {
        
precache_model(g_szNewShieldModels[i])    //Precache now new shield viewmodels
    
}
    
#endif
}

public 
Forward_PrecacheModel(const szModel[])
{
    
#if !defined DEFAULT_MODE
    
for(new isizeof g_szOldModelsi++) 
    { 
        if(
equal(szModelg_szOldModels[i]))  
        {  
            
forward_return(FMV_CELL0)
            return 
FMRES_SUPERCEDE
        
}  
    }
    
#endif 

    #if defined SHIELD_SUPPORT
    
for(new isizeof g_szOldShieldModelsi++) 
    { 
        if(
equal(szModelg_szOldShieldModels[i]))  
        {
            
forward_return(FMV_CELL0)
            return 
FMRES_SUPERCEDE
        
}  
    }
    
#endif
    
return FMRES_IGNORED
}

public 
client_authorized(id)
{
    static 
szAdminFlags[16]
    if(
get_user_flags(id) & get_pcvar_string(g_pcvAdminFlagszAdminFlagscharsmax(szAdminFlags)))
        
IsUserAdmin[id] = true
    
else
        
IsUserAdmin[id] = false

    
#if defined DEFAULT_MODE
    
static szData[8], iTs
    get_user_authid
(idg_szAuthID[id], charsmax(g_szAuthID[]))

    if(
nvault_lookup(g_iVaultg_szAuthID[id], szDatacharsmax(szData), iTs))
    {
        
g_bActive[id] = bool:str_to_num(szData)
    }
    else
    {
        
g_bActive[id] = DEFAULT_VALUE
    
}
    
#endif
}  

public 
ItemDeployPost(iWeapon)
{    
    static 
id
    id 
get_pdata_cbase(iWeaponm_pPlayerXO_WEAPON)

    if(!
is_user_alive(id))
    {
        return 
HAM_IGNORED
    
}

    
#if defined DEFAULT_MODE
    
if(!g_bActive[id])
    {
        return 
HAM_IGNORED
    
}
    
#endif

    
static szModelInfo[9]
    
get_user_info(idg_szUserInfoModelszModelInfocharsmax(szModelInfo))
   
    new 
iNum;
    
// Admin Model
    
if(IsUserAdmin[id])
    {
        
cs_set_viewmodel_body(idget_pcvar_num(g_pcvAdminSkin))
    }
    
// Real Model
    
else if(TrieGetCell(g_tModelsszModelInfoiNum))
    {
        
cs_set_viewmodel_body(idiNum)
    }
    
// Custom Model
    
else
    {
        
cs_set_viewmodel_body(idget_pcvar_num(g_pcvDefaultSkin))
    }

    
set_task(0.1"SetSkin"id//this task is needed

    
return HAM_IGNORED
}

#if defined SHIELD_SUPPORT
const m_bOwnsShield 2043
new const ShieldPossible = (<< CSW_HEGRENADE) | (<< CSW_SMOKEGRENADE) | (<< CSW_FLASHBANG) | (<< CSW_KNIFE) |(<< CSW_USP) | (<< CSW_P228) | (<< CSW_GLOCK18) | (<< CSW_FIVESEVEN) | (<< CSW_DEAGLE)
#endif

public SetSkin(id)
{
    if(!
is_user_alive(id))
        return
    
    new 
iWeapon get_user_weapon(id)
        
    if(!
iWeapon)
        return
        
    static 
szWeapon[64]
    
get_weaponname(iWeaponszWeaponcharsmax(szWeapon))
    
    if(
equal(szWeapong_szWeaponNameMp5Navy))
    {
        
replace(szWeaponcharsmax(szWeapon), szWeapong_szNewWeaponDirectoryMp5Navy)
    }
    
#if defined SHIELD_SUPPORT
    
else if(ShieldPossible & (<< iWeapon) && get_pdata_bool(idm_bOwnsShield))
    {
        
replace(szWeaponcharsmax(szWeapon), g_szWeaponNamePrefixg_szNewWeaponDirectoryShield)
        
formatex(szWeaponcharsmax(szWeapon), "%s%s"szWeapong_szModelNameExtension)
    }
    
#endif
    
else
    {
        
replace(szWeaponcharsmax(szWeapon), g_szWeaponNamePrefixg_szNewWeaponDirectory)
        
formatex(szWeaponcharsmax(szWeapon), "%s%s"szWeapong_szModelNameExtension)
    }    
    
set_pev(idpev_viewmodel2szWeapon)

also i suggest you to put the shield models and skin arm models in same archieve in an folder called "extended".

most of server owners doesn't know a grain of coding and it's easier to install

i added this too:
PHP Code:
#if defined SHIELD_SUPPORT
const m_bOwnsShield 2043
new const ShieldPossible = (<< CSW_HEGRENADE) | (<< CSW_SMOKEGRENADE) | (<< CSW_FLASHBANG) | (<< CSW_KNIFE) |(<< CSW_USP) | (<< CSW_P228) | (<< CSW_GLOCK18) | (<< CSW_FIVESEVEN) | (<< CSW_DEAGLE)
#endif 
due to a not used variable when not using shield support


and what do you mean by "the bots are still visible"? shall they not be?
Hello, thanks for your input and suggestion.
And the thing about the bots is still visible, it was a bad translation from Google Translator hahah, it meant that for the bots the weapon is still visible in first person.
-o-
The Extended folder already contains the v_ and Shield models in the same folder
The reason I'm putting it apart is for those who don't use Shield support, which seems to be the majority of servers, besides it had been an optional feature, we didn't know if it would cause too many problems and we would end up removing it, at the moment it seems to be stable, that's why it stayed that way.
-o-
Your code makes g_szOldModels unusable
PHP Code:
C:\Program Files (x86)\Steam\steamapps\common\Half-Life\czero\addons\amxmodx\scripting\EAWSv2.1.sma(84) : warning 203symbol is never used"g_szOldModels" 
__________________
Extended Arm Weapon Skin v2.1 {16/Apr/23}
(Detect which class is and associate it with the corresponding arms)
SideWeapons v0.2 {01/Sep/22}
(New version of Back Weapons v1.87)


Last edited by SoulWeaver16; 04-16-2023 at 15:56.
SoulWeaver16 is offline