Admin Models

Created Diff never expires
9 removals
118 lines
19 additions
123 lines
// Copyright © 2016 Vaqtincha
// Copyright © 2016 Vaqtincha


#include <amxmodx>
#include <amxmodx>
#include <reapi>
#include <reapi>


enum player_models { szTTModel[64], szCTModel[64], iFlag }
enum player_models { szTTModel[64], szCTModel[64], iFlag }




/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG START ■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG START ■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/


#define SET_MODELINDEX
#define SET_MODELINDEX
#define MAX_MODEL_PATH_LEN 128
#define MAX_MODEL_PATH_LEN 128


/// FORMAT: "Terrorist Model" "Counter-Terrorist Model" "Access Flag"
/// FORMAT: "Terrorist Model" "Counter-Terrorist Model" "Access Flag"


new const g_eModelsData[][player_models] =
new const g_eModelsData[][player_models] =
{
{
{ "snowleet", "lolgign", ADMIN_LEVEL_B },
{ "vip_t_server500", "vip_ct_server500", ADMIN_LEVEL_H },
{ "viptt", "vipct", ADMIN_LEVEL_H },
//{ "new_year_t", "new_year_ct", ADMIN_LEVEL_H },
{ "bomjtt", "bomjct", ADMIN_ALL },
// { "viptt", "vipct", ADMIN_LEVEL_H },
// { "bomjtt", "bomjct", ADMIN_ALL },


/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG END ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG END ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/


{"", "", -1} // don't touch it!!
{"", "", -1} // don't touch it!!
}
}


#define IsValidArrayIndex(%1) (0 <= %1 <= sizeof(g_eModelsData)-1)
#define IsValidArrayIndex(%1) (0 <= %1 <= sizeof(g_eModelsData)-1)


#if defined SET_MODELINDEX
#if defined SET_MODELINDEX
new g_iTTModelIndex[sizeof(g_eModelsData)], g_iCTModelIndex[sizeof(g_eModelsData)]
new g_iTTModelIndex[sizeof(g_eModelsData)], g_iCTModelIndex[sizeof(g_eModelsData)]
#endif
#endif




public plugin_precache()
public plugin_precache()
{
{
if(g_eModelsData[0][iFlag] == -1)
if(g_eModelsData[0][iFlag] == -1)
{
{
set_fail_state("Array g_eModelsData are empty!")
set_fail_state("Array g_eModelsData are empty!")
return
return
}
}


for(new i = 0; i < sizeof(g_eModelsData)-1; i++)
for(new i = 0; i < sizeof(g_eModelsData)-1; i++)
{
{
#if defined SET_MODELINDEX
#if defined SET_MODELINDEX
g_iTTModelIndex = precache_player_model(g_eModelsData[szTTModel])
g_iTTModelIndex[i] = precache_player_model(g_eModelsData[i][szTTModel])
g_iCTModelIndex = precache_player_model(g_eModelsData[szCTModel])
g_iCTModelIndex[i] = precache_player_model(g_eModelsData[i][szCTModel])
#else
#else
precache_player_model(g_eModelsData[szTTModel])
precache_player_model(g_eModelsData[i][szTTModel])
precache_player_model(g_eModelsData[szCTModel])
precache_player_model(g_eModelsData[i][szCTModel])
#endif
#endif
}
}
}
}


public plugin_init()
public plugin_init()
{
{
register_plugin("[ReAPI] Admin Models", "0.0.2", "Vaqtincha")
register_plugin("[ReAPI] Admin Models", "0.0.2", "Vaqtincha")


RegisterHookChain(RG_CBasePlayer_SetClientUserInfoModel, "SetClientUserInfoModel", .post = false)
RegisterHookChain(RG_CBasePlayer_SetClientUserInfoModel, "SetClientUserInfoModel", .post = false)
}
}




public SetClientUserInfoModel(const pPlayer, infobuffer[], szNewModel[])
public SetClientUserInfoModel(const pPlayer, infobuffer[], szNewModel[])
{
{
new iArrayIndex = get_user_model_by_flag(get_user_flags(pPlayer))
new iArrayIndex = get_user_model_by_flag(get_user_flags(pPlayer))


if(!IsValidArrayIndex(iArrayIndex))
if(!IsValidArrayIndex(iArrayIndex))
return HC_CONTINUE
return HC_CONTINUE
switch(get_member(pPlayer, m_iTeam))
switch(get_member(pPlayer, m_iTeam))
{
{
case TEAM_TERRORIST: {
case TEAM_TERRORIST: {
#if defined SET_MODELINDEX
#if defined SET_MODELINDEX
set_member(pPlayer, m_modelIndexPlayer, g_iTTModelIndex[iArrayIndex])
set_member(pPlayer, m_modelIndexPlayer, g_iTTModelIndex[iArrayIndex])
#endif
#endif
SetHookChainArg(3, ATYPE_STRING, g_eModelsData[iArrayIndex][szTTModel])
SetHookChainArg(3, ATYPE_STRING, g_eModelsData[iArrayIndex][szTTModel])
}
}
case TEAM_CT: {
case TEAM_CT: {
#if defined SET_MODELINDEX
#if defined SET_MODELINDEX
set_member(pPlayer, m_modelIndexPlayer, g_iCTModelIndex[iArrayIndex])
set_member(pPlayer, m_modelIndexPlayer, g_iCTModelIndex[iArrayIndex])
#endif
#endif
SetHookChainArg(3, ATYPE_STRING, g_eModelsData[iArrayIndex][szCTModel])
SetHookChainArg(3, ATYPE_STRING, g_eModelsData[iArrayIndex][szCTModel])
}
}
default: return HC_CONTINUE
default: return HC_CONTINUE
}
}


return HC_CONTINUE
return HC_CONTINUE
}
}




get_user_model_by_flag(const iUserFlags)
get_user_model_by_flag(const iUserFlags)
{
{
const INVALID_INDEX = -1
const INVALID_INDEX = -1


if(iUserFlags & (1<<29)) {
return INVALID_INDEX
}

for(new i = 0; i < sizeof(g_eModelsData)-1; i++)
for(new i = 0; i < sizeof(g_eModelsData)-1; i++)
{
{
if(iUserFlags & g_eModelsData[iFlag] || g_eModelsData[iFlag] == ADMIN_ALL)
if(iUserFlags & g_eModelsData[i][iFlag] || g_eModelsData[i][iFlag] == ADMIN_ALL)
return i
return i
}
}


return INVALID_INDEX // non admin player
return INVALID_INDEX // non admin player
}
}


precache_player_model(const szModel[])
precache_player_model(const szModel[])
{
{
new szFileToPrecache[MAX_MODEL_PATH_LEN], szErrMsg[MAX_MODEL_PATH_LEN + 64]
new szFileToPrecache[MAX_MODEL_PATH_LEN], szErrMsg[MAX_MODEL_PATH_LEN + 64]


formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%s.mdl", szModel, szModel)
formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%s.mdl", szModel, szModel)


if(!file_exists(szFileToPrecache))
if(!file_exists(szFileToPrecache))
{
{
formatex(szErrMsg, charsmax(szErrMsg), "[Admin Models] ERROR: Model ^"%s^" not found!", szFileToPrecache)
formatex(szErrMsg, charsmax(szErrMsg), "[Admin Models] ERROR: Model ^"%s^" not found!", szFileToPrecache)
set_fail_state(szErrMsg)
set_fail_state(szErrMsg)
return 0
return 0
}
}


return precache_model(szFileToPrecache)
return precache_model(szFileToPrecache)
}
}