Raised This Month: $ Target: $400
 0% 

Changing weapons models = very high bandwidth usage?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-09-2009 , 16:33   Re: Changing weapons models = very high bandwidth usage?
Reply With Quote #6

You may find some usefull parts of code in this one :
(This is not a real plugin, lot of tests in it and sometimes it crashes)
PHP Code:
/*    Copyright © 2008, ConnorMcLeod

    Weapons Models is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Weapons Models; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

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

#define PLUGIN "Weapons Models"
#define AUTHOR "ConnorMcLeod"
#define VERSION "0.0.1"

#define MIN_MODEL_LENGTH    12
#define MAX_MODEL_LENGTH    64

#define MAX_WEAPONS    CSW_P90

#define    SHIELD_GUNS_BITSUM        ( (1<<CSW_P228) | (1<<CSW_FIVESEVEN) | (1<<CSW_USP) | (1<<CSW_GLOCK18) | (1<<CSW_DEAGLE))
#define    NADES_BITSUM            ( (1<<CSW_HEGRENADE) | (1<<CSW_SMOKEGRENADE) | (1<<CSW_FLASHBANG) )
#define    SHIELD_WEAPONS_BS        ( SHIELD_GUNS_BITSUM | NADES_BITSUM | (1<<CSW_KNIFE) )
#define    is_shield_weapon(%1)    (SHIELD_WEAPONS_BS & (1<<%1))
#define    is_weapon_nade(%1)        (NADES_BITSUM & (1<<%1))
#define    cs_get_user_shield(%1)    (get_pdata_int(%1, 510) & (1<<24))

#define    m_pPlayer                41 // VEN
#define    m_iId                43

#define    cs_get_weapon_owner(%1)    get_pdata_cbase(%1, m_pPlayer, 4)
#define    cs_get_weapon_id(%1)    get_pdata_int(%1, m_iId, 4)

#define MAKE_STRING(%1)    engfunc(EngFunc_AllocString, %1)

#define WEAPONBOX    1
#define GRENADE    2

#define OFFSET_WBOX_AMMO_ID_CODE_WIN32 41
new const OFFSET_WBOX_CB_WEAP_ENT_WIN32[] = {03536373839// 39 works for c4 //38 works on cz //37 Oo
new g_iFhSetModelg_iEntToSetModel[2]

new 
g_iVModel[MAX_WEAPONS+1], g_iPModel[MAX_WEAPONS+1]
new 
g_iShieldVModel[MAX_WEAPONS+1], g_iShieldPModel[MAX_WEAPONS+1]
new 
g_szWorldModel[MAX_WEAPONS+1][MAX_MODEL_LENGTH]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
plugin_precache()
{
    if( !
cvar_exists("server_startup") )
    {
        
register_cvar("server_startup""1")
        
server_cmd("restart")
        
server_exec()
        return
    }
    new 
szDatas[MAX_MODEL_LENGTH*6]
    
get_localinfo("amxx_configsdir"szDatascharsmax(szDatas))
    
format(szDatascharsmax(szDatas), "%s/weapons_models.ini"szDatas)

    new 
iFile fopen(szDatas"rt")
    if(!
iFile)
    {
        return
    }

    new 
szCswName[20], iCswIdbool:bRegisterDeploybool:bRegisterGrenadeSpawnbool:bRegisterWeaponBoxSpawn,
        
szVModel[MAX_MODEL_LENGTH], szPModel[MAX_MODEL_LENGTH], szShieldVModel[MAX_MODEL_LENGTH], 
            
szShieldPModel[MAX_MODEL_LENGTH], szWModel[MAX_MODEL_LENGTH]
        
    new 
szModName[16], bCzero
    get_modname
(szModNamecharsmax(szModName))
    
bCzero equal(szModName"czero")

    while(!
feof(iFile))
    {
        
fgets(iFileszDatascharsmax(szDatas))
        
trim(szDatas)
        if(!
szDatas[0] || szDatas[0] == ';' || szDatas[0] == '#' || (szDatas[0] == '/' && szDatas[1] == '/'))
            continue

        
szVModel[0] = 0
        szPModel
[0] = 0
        szWModel
[0] = 0
        szShieldVModel
[0] = 0
        szShieldPModel
[0] = 0
        szCswName
[0] = 0

        parse
(szDatasszCswNamecharsmax(szCswName), szVModelcharsmax(szVModel), szPModelcharsmax(szPModel),
        
szWModelcharsmax(szWModel), szShieldVModelcharsmax(szShieldVModel), szShieldPModelcharsmax(szShieldPModel))
        if( !
szVModel[0] && !szPModel[0] && !szShieldVModel[0] && !szShieldPModel[0] && !szWModel[0] )
            continue

        if( !(
iCswId get_weaponid(szCswName)) )
        {
            
UTIL_Log_To_File("^"%s^" is not an existing weapon name"szCswName)
            continue
        }

        
bRegisterDeploy false

        
if( szVModel[0] )
        {
            if( 
Check_FileszVModel ) )
            {
                
bRegisterDeploy true
                precache_model
(szVModel)
                
g_iVModel[iCswId] = MAKE_STRING(szVModel)
            }
        }

        if( 
szPModel[0] )
        {
            if( 
Check_FileszPModel ) )
            {
                
bRegisterDeploy true
                precache_model
(szPModel)
                
g_iPModel[iCswId] = MAKE_STRING(szPModel)
            }
        }

        if( 
is_shield_weapon(iCswId) && szShieldVModel[0] )
        {
            if( 
Check_FileszShieldVModel ) )
            {
                
bRegisterDeploy true
                precache_model
(szShieldVModel)
                
g_iShieldVModel[iCswId] = MAKE_STRING(szShieldVModel)
            }
        }

        if( 
is_shield_weapon(iCswId) && szShieldPModel[0] )
        {
            if( 
Check_FileszShieldPModel ) )
            {
                
bRegisterDeploy true
                precache_model
(szShieldPModel)
                
g_iShieldPModel[iCswId] = MAKE_STRING(szShieldPModel)
            }
        }

        if( 
szWModel[0] )
        {
            if( 
Check_FileszWModel ) )
            {
                
precache_model(szWModel)
                
formatex(g_szWorldModel[iCswId], MAX_MODEL_LENGTH-1szWModel)
                if( 
is_weapon_nade(iCswId) )
                {
                    
bRegisterGrenadeSpawn true

                    
if( bCzero )
                    {
                        
bRegisterWeaponBoxSpawn true
                    
}
                }
                else if( 
iCswId == CSW_C4 )
                {
                    
RegisterHam(Ham_Item_Kill"weapon_c4""WeaponC4_Kill")
                    
bRegisterWeaponBoxSpawn true
                
}
                else
                {
                    
bRegisterWeaponBoxSpawn true
                
}
            }
        }

        if( 
bRegisterDeploy )
        {
            
RegisterHam(Ham_Item_DeployszCswName"Item_Deploy"1)
        }

    }
    
fclose(iFile)

    if( 
bRegisterGrenadeSpawn )
    {
        
RegisterHam(Ham_Spawn"grenade""Grenade_Spawn"1)
    }
    if( 
bRegisterWeaponBoxSpawn )
    {
        
RegisterHam(Ham_Spawn"weaponbox""WeaponBox_Spawn"1)
    }
}

Check_File( const szFile[] )
{
    new 
iLen strlen(szFile)
    if( 
iLen MIN_MODEL_LENGTH )
    {
        
UTIL_Log_To_File("File name ^"%s^" is not valid"szFile)
    }
    if( !
equal(szFile[iLen-4], ".mdl") )
    {
        
UTIL_Log_To_File("File ^"%s^" has a wrong extension %s (.mdl required)"szFileszFile[iLen-4])
        return 
0
    
}
    else if( !
file_exists(szFile) )
    {
        
UTIL_Log_To_File("File ^"%s^" doesn't exist"szFile)
        return 
0
    
}
    return 
1
}

public 
Item_Deploy(iEnt)
{
    new 
iCswId cs_get_weapon_id(iEnt)

    new 
id cs_get_weapon_owner(iEnt)

    new 
iVModeliPModel

    
if( is_shield_weapon(iCswId) && cs_get_user_shield(id) )
    {
        
iVModel g_iShieldVModel[iCswId]
        
iPModel g_iShieldPModel[iCswId]
    }
    else
    {
        
iVModel g_iVModel[iCswId]
        
iPModel g_iPModel[iCswId]
    }

    if( 
iVModel )
    {
        
set_pev(idpev_viewmodeliVModel)
    }

    if( 
iPModel )
    {
        
set_pev(idpev_weaponmodeliPModel)
    }
}

public 
Grenade_SpawniEnt )
{
    
g_iEntToSetModel[0] = iEnt
    g_iEntToSetModel
[1] = GRENADE
    g_iFhSetModel 
register_forward(FM_SetModel"SetModel")
}

public 
WeaponBox_SpawniWeaponBox )
{
    
g_iEntToSetModel[0] = iWeaponBox
    g_iEntToSetModel
[1] = WEAPONBOX
    g_iFhSetModel 
register_forward(FM_SetModel"SetModel")
}

public 
SetModeliEnt )
{
    if( 
iEnt != g_iEntToSetModel[0] )
        return 
FMRES_IGNORED

    
new iCswId
    
switch( g_iEntToSetModel[1] )
    {
        case 
WEAPONBOX:
        {
            new 
iOtherEnt
            
for(new 1<= sizeof OFFSET_WBOX_CB_WEAP_ENT_WIN32; ++i)
            {
                if( 
==     sizeof OFFSET_WBOX_CB_WEAP_ENT_WIN32 )
                    return 
FMRES_IGNORED
                iOtherEnt 
get_pdata_cbase(iEntOFFSET_WBOX_CB_WEAP_ENT_WIN32[i], 4)
                if(
pev_valid(iOtherEnt) && pev(iOtherEntpev_owner) == iEnt && ExecuteHam(Ham_Item_ItemSlotiOtherEnt) == i)
                    break
            }

            
iCswId cs_get_weapon_id(iOtherEnt)
            
unregister_forward(FM_SetModelg_iFhSetModel)
            if( 
g_szWorldModel[iCswId][0] )
            {
                
engfuncEngFunc_SetModeliEntg_szWorldModel[iCswId] )
                
unregister_forward(FM_SetModelg_iFhSetModel)
                return 
FMRES_SUPERCEDE
            
}
        }
        case 
GRENADE:
        {
            
iCswId cs_get_grenade_typeiEnt )
            if( 
g_szWorldModel[iCswId][0] )
            {
                
engfuncEngFunc_SetModeliEntg_szWorldModel[iCswId] )
                
unregister_forward(FM_SetModelg_iFhSetModel)
                return 
FMRES_SUPERCEDE
            
}
        }
    }
    return 
FMRES_IGNORED
}

cs_get_grenade_typeiEnt // VEN
{
    new 
iBits get_pdata_int(iEnt114)
    if (
iBits & (1<<0))
    {
        return 
CSW_HEGRENADE
    
}
    else if (
iBits & (1<<1))
    {
        return 
CSW_SMOKEGRENADE
    
}
    else if (!
iBits)
    {
        return 
CSW_FLASHBANG
    
}
    return 
0
}

public 
WeaponC4_Killindex )
{
    new 
iEnt engfuncEngFunc_FindEntityByString FM_NULLENT "classname" "grenade" )
    while( 
iEnt )
    {
        if( 
get_pdata_int(iEnt96) & (1<<8) )
        {
            
engfuncEngFunc_SetModeliEntg_szWorldModel[CSW_C4])
            break
        }
        
iEnt engfuncEngFunc_FindEntityByString iEnt "classname" "grenade" )
    }
}

UTIL_Log_To_File(const fmt[], any:...) // from shptools
{
    static 
string[512]
    
vformat(stringcharsmax(string), fmt2)

    static 
date[16], time[16], fp
    get_time
("%H:%M:%S"timecharsmax(time))

    static 
logfile[192]
    if(
logfile[0] == 0)
    {
        new 
basedir[64]
        
get_localinfo("amxx_basedir"basedircharsmax(basedir))
        
get_time("%m%d"datecharsmax(date))
        
formatex(logfilecharsmax(logfile), "%s/logs/weapons_models_%s.log"basedirdate)
    }

    
get_time("%m/%d/%Y"datecharsmax(date))
    
fp fopen(logfile"a")
    
fprintf(fp"L %s - %s: %s^n"datetimestring)
    
fclose(fp)

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:58.


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