Raised This Month: $51 Target: $400
 12% 

Model Remplacement And Sounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
666
Senior Member
Join Date: Mar 2015
Old 04-20-2019 , 13:02   Model Remplacement And Sounds
Reply With Quote #1

Could you help me by adding sound replacement to this plugin

PHP Code:
// #define SET_MODELINDEX


#define MAX_MODEL_LEN        64
#define MAX_PATH_LEN         128
#define MAX_PLAYERS            32
#define MAX_BUFFER_LEN        MAX_MODEL_LEN + MAX_MODEL_LEN


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

#define VERSION "0.0.2"

#define UserValidTeam(%1)             (CS_TEAM_TT <= get_pdata_int(%1, m_iTeam) <= CS_TEAM_CT)
#define AllocString(%1)             engfunc(EngFunc_AllocString,%1)
#define SetModel(%1,%2)             engfunc(EngFunc_SetModel,%1,%2)
#define IsPlayer(%1)                (1 <= %1 <= g_iMaxPlayers)

#define SetUserModeled(%1)            g_bModeled |= 1<<(%1 & 31)
#define SetUserNotModeled(%1)        g_bModeled &= ~( 1<<(%1 & 31))
#define IsUserModeled(%1)            (g_bModeled &  1<<(%1 & 31))

#define SetUserConnected(%1)        g_bConnected |= 1<<(%1 & 31)
#define SetUserNotConnected(%1)        g_bConnected &= ~( 1<<(%1 & 31))
#define IsUserConnected(%1)            (g_bConnected &  1<<(%1 & 31))

const ClCorpse_ModelName 1
const ClCorpse_PlayerID 12
const CS_TEAM_TT 1
const CS_TEAM_CT 2
// offsets
const m_iTeam 114
const m_pPlayer 41
const g_ulModelIndexPlayer 491

new const MODEL[] = "model"
new const g_szMapEntitys[][] = {"cycler_sprite""cycler""armoury_entity"}

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

new const 
g_szWeaponNames[CSW_P90+1][] = {"","p228","","scout","hegrenade","xm1014","c4","mac10",
    
"aug","smokegrenade","elite","fiveseven","ump45","sg550","galil","famas","usp","glock18","awp",
    
"mp5navy","m249","m3","m4a1","tmp","g3sg1","flashbang","deagle","sg552","ak47","knife","p90"
}

new 
g_iWeaponIds[CSW_P90+1]

new 
Trie:g_tDefaultModelsTrie:g_tModelIndexesTrie:g_tMapModels
new Trie:g_tViewModelsTrie:g_tWeaponModelsTrie:g_tWorldModels

new g_bConnectedg_bModeledg_iMaxPlayersbool:g_bPlayerModels
new g_szCurrentModel[MAX_PLAYERS+1][MAX_MODEL_LEN]


public 
plugin_init()
{
    
register_plugin("Models Replacement"VERSION"ConnorMcLeod | Vaqtincha")

    if(
g_bPlayerModels)
    {
        
register_forward(FM_SetClientKeyValue"SetClientKeyValue_Pre"0)
        
register_message(get_user_msgid("ClCorpse"), "Message_ClCorpse")
    }
    if(
g_tWorldModels)
    {
        
register_forward(FM_SetModel"SetModel_Pre"0)
    }
    if(
g_tMapModels)
    {
        
SetMapModels()
    }
    
g_iMaxPlayers get_maxplayers()
}

public 
plugin_precache()
{
    new 
szConfigFile[MAX_PATH_LEN]
    
get_localinfo("amxx_configsdir"szConfigFilecharsmax(szConfigFile))
    
add(szConfigFilecharsmax(szConfigFile), "/models_replacement.ini")

    if(
file_exists(szConfigFile))
    {
        new 
iFile fopen(szConfigFile"rt")
        if(!
iFile)
        {
            
set_fail_state("[MODELS_REPLACEMENT] ERROR: Failed reading file!")
            return
        }
        new 
szDatas[MAX_BUFFER_LEN 10], szWeaponClass[32], iIdc
        
new szOldModel[MAX_MODEL_LEN], szNewModel[MAX_MODEL_LEN]

        new 
Trie:tRegisterWeaponDeploy TrieCreate()
        new 
Trie:tWeaponsIds TrieCreate()
        
g_tModelIndexes TrieCreate()
        
g_tDefaultModels TrieCreate()

        for(new 
1i<sizeof(g_szDefaultModels); i++)
        {
            
TrieSetCell(g_tDefaultModelsg_szDefaultModels[i], i)
        }
        for(new 
CSW_P228<= CSW_P90i++)
        {
            
TrieSetCell(tWeaponsIdsg_szWeaponNames[i], g_iWeaponIds[i])
        }

        while(!
feof(iFile))
        {
            
fgets(iFileszDatascharsmax(szDatas))
            
trim(szDatas)

            if(!(
szDatas[0]) || == ';' || == '#')
            {
                continue
            }
            if(
parse(szDatasszOldModelcharsmax(szOldModel), szNewModelcharsmax(szNewModel)) != 2)
            {
                continue
            }
            if(!
szOldModel[0] || !szNewModel[0] || equal(szNewModelszOldModel))
            {
                continue
            }
            if(
TrieKeyExists(g_tDefaultModelsszOldModel))
            {
                if(
PrecachePlayerModel(szNewModel))
                {
                    
TrieSetString(g_tDefaultModelsszOldModelszNewModel)
                    
g_bPlayerModels true
                
}
            }else{
                if(((
szOldModel[0]) == 'p' || == 'v' ) && szOldModel[1] == '_')
                {
                    if(
equal(szOldModel[2], "mp5"3))
                    {
                        
copy(szWeaponClasscharsmax(szWeaponClass), "weapon_mp5navy")
                    }else{
                        
formatex(szWeaponClasscharsmax(szWeaponClass), "weapon_%s"szOldModel[2])
                    }

                    if(!
TrieGetCell(tWeaponsIdsszWeaponClass[7], iId))
                    {
                        
server_print("[MODELS_REPLACEMENT] WARNING: Invalid weapon class ^"%s^" will be skipped!"szWeaponClass)
                        continue
                    }
                    if(!
TrieKeyExists(tRegisterWeaponDeployszWeaponClass))
                    {
                        
TrieSetCell
                        
(
                            
tRegisterWeaponDeploy,
                            
szWeaponClass,
                            
RegisterHam(Ham_Item_DeployszWeaponClass"ItemDeploy_Post"true)
                        )
                    }

                    
format(szNewModelcharsmax(szNewModel), "models/%s.mdl"szNewModel)
                    if(
== 'v')
                    {
                        if(!
g_tViewModels)
                        {
                            
g_tViewModels TrieCreate()
                        }
                        if(
PrecacheWeaponModel(szNewModel))
                        {
                            
TrieSetCell(g_tViewModelsszWeaponClassAllocString(szNewModel))
                        }
                    }else{
                        if(!
g_tWeaponModels)
                        {
                            
g_tWeaponModels TrieCreate()
                        }
                        if(
PrecacheWeaponModel(szNewModel))
                        {
                            
TrieSetCell(g_tWeaponModelsszWeaponClassAllocString(szNewModel))
                        }
                    }
                }else{
                    
format(szOldModelcharsmax(szOldModel), "models/%s.mdl"szOldModel)
                    
format(szNewModelcharsmax(szNewModel), "models/%s.mdl"szNewModel)

                    if(
== 'w')
                    {
                        if(!
g_tWorldModels)
                        {
                            
g_tWorldModels TrieCreate()
                        }
                        else if(
TrieKeyExists(g_tWorldModelsszOldModel))
                        {
                            continue
                        }
                        if(
PrecacheWeaponModel(szNewModel))
                        {
                            
TrieSetString(g_tWorldModelsszOldModelszNewModel)
                        }
                    }
                }
                if(!
g_tMapModels)
                {
                    
g_tMapModels TrieCreate()
                }
                if(
PrecacheWeaponModel(szNewModel))
                {
                    
TrieSetString(g_tMapModelsszOldModelszNewModel)
                }
            }
        }

        
fclose(iFile)
        
TrieDestroy(tRegisterWeaponDeploy)
        
TrieDestroy(tWeaponsIds)
    }else{
        new 
iFile fopen(szConfigFile"w")
        if(!
iFile)
        {
            
set_fail_state("[MODELS_REPLACEMENT] ERROR: Failed creating file!")
            return
        }

        
fputs(iFile"^n; Format: ^"old model^" ^"new model^" (without 'models/' & '.mdl')^n;^n; Examples:^n")
        
fputs(iFile"^n; ^"arctic^" ^"vip^"^n; ^"chick^" ^"winebottle^"")
        
fputs(iFile"^n; ^"v_awp^" ^"custom/v_awp^"^n; ^"p_awp^" ^"custom/p_awp^"^n; ^"w_awp^" ^"custom/w_awp^"")

        
fclose(iFile)
    }
}

public 
client_putinserver(id)
{
    if(!
is_user_hltv(id))
    {
        
SetUserConnected(id)
    }
}

public 
client_disconnect(id)
{
    
SetUserNotModeled(id)
    
SetUserNotConnected(id)
}

public 
ItemDeploy_Post(wEnt)
{
    if(
wEnt <= 0)
    {
        return
    }
    
    new 
id get_pdata_cbase(wEntm_pPlayer, .linuxdiff 4)
    if(
IsPlayer(id))
    {
        new 
iszNewModelszWeaponClass[32]
        
pev(wEntpev_classnameszWeaponClasscharsmax(szWeaponClass))

        if(
g_tViewModels && TrieGetCell(g_tViewModelsszWeaponClassiszNewModel))
        {
            
set_pev(idpev_viewmodeliszNewModel)
        }
        if(
g_tWeaponModels && TrieGetCell(g_tWeaponModelsszWeaponClassiszNewModel))
        {
            
set_pev(idpev_weaponmodeliszNewModel)
        }
    }
}

public 
SetModel_Pre(iEnt, const szModel[])
{
    
/* if(!pev_valid(iEnt))
    {
        return FMRES_IGNORED
    } */

    
new szNewModel[MAX_MODEL_LEN]
    if(
TrieGetString(g_tWorldModelsszModelszNewModelcharsmax(szNewModel)))
    {
        
SetModel(iEntszNewModel)
        return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED
}

public 
SetClientKeyValue_Pre(id, const szInfoBuffer[], const szKey[], const szValue[])
{
    if(!
equal(szKeyMODEL) || !IsUserConnected(id) || !UserValidTeam(id))
    {
        return 
FMRES_IGNORED
    
}

    new 
szSupposedModel[MAX_MODEL_LEN]
    if(
TrieGetString(g_tDefaultModelsszValueszSupposedModelcharsmax(szSupposedModel)))
    {
        if(
szSupposedModel[0])
        {
            if(!
IsUserModeled(id) || !equal(g_szCurrentModel[id], szSupposedModel) || !equal(szValueszSupposedModel))
            {
                
copy(g_szCurrentModel[id], MAX_MODEL_LEN-1szSupposedModel)
                
SetUserModeled(id)
                
set_user_info(idMODELszSupposedModel)
            
#if defined SET_MODELINDEX
                
new iModelIndex
                TrieGetCell
(g_tModelIndexesszSupposedModeliModelIndex)
                
// set_pev(id, pev_modelindex, iModelIndex); // is this needed ?
                
set_pdata_int(idg_ulModelIndexPlayeriModelIndex)
            
#endif
                
return FMRES_SUPERCEDE
            
}
        }

        if(
IsUserModeled(id))
        {
            
SetUserNotModeled(id)
            
g_szCurrentModel[id][0] = 0
        
}
    }
    return 
FMRES_IGNORED
}

public 
Message_ClCorpse()
{
    new 
id get_msg_arg_int(ClCorpse_PlayerID)
    if(
IsUserModeled(id))
    {
        
set_msg_arg_string(ClCorpse_ModelNameg_szCurrentModel[id])
    }
}

public 
plugin_end()
{
    if(
g_tModelIndexes)
    {
        
TrieDestroy(g_tModelIndexes)
    }
    if(
g_tViewModels)
    {
        
TrieDestroy(g_tViewModels)
    }
    if(
g_tWeaponModels)
    {
        
TrieDestroy(g_tWeaponModels)
    }
    if(
g_tWorldModels)
    {
        
TrieDestroy(g_tWorldModels)
    }
    if(
g_tMapModels)
    {
        
TrieDestroy(g_tMapModels)
    }
}

SetMapModels()
{
    new 
iEnt FM_NULLENT
    
new szSupposedModel[MAX_MODEL_LEN], szModel[MAX_MODEL_LEN]

    for(new 
0<sizeof(g_szMapEntitys); i++)
    {
        while((
iEnt engfunc(EngFunc_FindEntityByStringiEnt"classname"g_szMapEntitys[i])))
        {
            
pev(iEntpev_modelszModelcharsmax(szModel))
            if(
TrieGetString(g_tMapModelsszModelszSupposedModelcharsmax(szSupposedModel)))
            {
                
SetModel(iEntszSupposedModel)
            }
        }
    }
}

PrecacheWeaponModel(const szModel[])
{
    new 
szMsg[MAX_MODEL_LEN 64]

    if(!
file_exists(szModel))
    {
        
formatex(szMsgcharsmax(szMsg), "[MODELS_REPLACEMENT] ERROR: Model ^"%s^" not found!"szModel)
        
set_fail_state(szMsg)
        return 
0
    
}
    
precache_model(szModel)
    return 
1
}

PrecachePlayerModel(const szModel[])
{
    if(
TrieKeyExists(g_tModelIndexesszModel) || TrieKeyExists(g_tDefaultModelsszModel))
    {
        return 
1
    
}
    new 
szFileToPrecache[64], szMsg[MAX_MODEL_LEN 64]
    
formatex(szFileToPrecachecharsmax(szFileToPrecache), "models/player/%s/%s.mdl"szModelszModel)

    if(!
file_exists(szFileToPrecache))
    {
        
formatex(szMsgcharsmax(szMsg), "[MODELS_REPLACEMENT] ERROR: Player model ^"%s^" not found!"szFileToPrecache)
        
set_fail_state(szMsg)
        return 
0
    
}

    
TrieSetCell(g_tModelIndexesszModelprecache_model(szFileToPrecache))

    
formatex(szFileToPrecachecharsmax(szFileToPrecache), "models/player/%s/%st.mdl"szModelszModel)
    if(
file_exists(szFileToPrecache))
    {
        
precache_model(szFileToPrecache)
        return 
1
    
}
    
formatex(szFileToPrecachecharsmax(szFileToPrecache), "models/player/%s/%sT.mdl"szModelszModel)
    if(
file_exists(szFileToPrecache))
    {
        
precache_model(szFileToPrecache)
        return 
1
    
}
    return 
1

__________________
666 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-20-2019 , 13:05   Re: Model Remplacement And Sounds
Reply With Quote #2

Which sound exactly? You can't just replace any sound in the game.
__________________

Last edited by OciXCrom; 04-20-2019 at 13:05.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
666
Senior Member
Join Date: Mar 2015
Old 04-20-2019 , 14:04   Re: Model Remplacement And Sounds
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
Which sound exactly? You can't just replace any sound in the game.
The sounds that I want to replace are those of the players and the weapons, I am aware that the sound of gun shots can not be changed, but other sounds if, for example, c4_beep1, knife_deploy1, flashbang-1, etc.
__________________
666 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 04-20-2019 , 14:32   Re: Model Remplacement And Sounds
Reply With Quote #4

https://forums.alliedmods.net/showthread.php?t=43979
thEsp is offline
666
Senior Member
Join Date: Mar 2015
Old 04-23-2019 , 17:38   Re: Model Remplacement And Sounds
Reply With Quote #5

Quote:
Originally Posted by thEsp View Post
I don't like how that complement works
__________________
666 is offline
Reply



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 19:11.


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