PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <tfcx>
#define PLUGIN "MODEL SETTER"
#define VERSION "0.0.2"
#define AUTHOR "Master"
#define MODEL_NAME_LEN 14
#define MAX_MODELS 256
//precaching was edited in from "very simple precache mod"
// (- https://forums.alliedmods.net/showthread.php?t=26784 -)
// vey simple precache mod was made by hjvl
//all credit for the precaching code gotes to hjvl (- https://forums.alliedmods.net/member.php?u=7471 -)
new g_szModels[MAX_MODELS][MODEL_NAME_LEN+1]
new g_iModelsNum = 0
new g_pMenu
new g_currentmodel[33][65]
public handle_say(id)
{
new said[192]
read_args(said,192)
remove_quotes(said)
if( (containi(said, "models") != -1) && !(containi(said, "!models") != -1) || (containi(said, "model") !=-1) && !(containi(said, "!models") != -1) && !(containi(said, "!model") !=-1) ) {
client_print(id, print_chat, "[AMXX] For a menu to select your model, say !models")
client_print(id,print_chat, "[AMXX] Alternatively if you know the modelname, you can say ^"!model MODELNAME^"")
}
if(containi(said, "!model") != -1 && (containi(said, "!models") ==-1) )
{
replace(said,192,"!model ","")
if(is_valid_model(said))
{
tfc_setmodel(id, said, "1")
client_print(id,print_chat, "[AMXX] Player model set to ^"%s^"", said)
}
else if(!is_valid_model(said))
{
client_print(id,print_chat, "[AMXX] Invalid model, perhaps you should use the menu?")
}
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("amx_model","set_model",0,"<skin name>")
register_concmd("amx_modelmenu", "cmdModelMenu", 0, " - Displays Menu of possible player models.")
register_clcmd("say","handle_say")
register_clcmd("say !models","cmdModelMenu", 0, " - Displays Menu of possible player models.")
register_clcmd("say !random","random_model",0,"Sets a Random model")
register_cvar("amx_pmod_mode","0", FCVAR_SPONLY)
}
public plugin_precache()
{
new mode =(get_cvar_num("amx_pmod_mode"))
new szModelFilePath[64]
get_configsdir(szModelFilePath, sizeof(szModelFilePath) - 1)
if(mode == 2)
{
add(szModelFilePath, sizeof(szModelFilePath) - 1, "/player_models.ini")
if( file_exists(szModelFilePath) )
{
new f = fopen(szModelFilePath, "rt")
new data[20], szModelPath[64]
while( !feof(f) && g_iModelsNum < MAX_MODELS )
{
fgets(f, data, sizeof(data) - 1)
trim(data)
if( !data[0] || data[0] == ';' || data[0] == '/' && data[1] == '/' ) continue;
// Stuff here.
server_print(">>>%s<<<", data)
formatex(szModelPath, 63, "models/player/%s/%s.mdl", data, data)
if(file_exists(szModelPath))
{
server_print("File exists!!!! ^"%s^"", szModelPath)
precache_model(szModelPath)
copy(g_szModels[g_iModelsNum], MODEL_NAME_LEN, data)
g_iModelsNum++
}
else
{
server_print("DNE DNE!!!! ^"%s^"", szModelPath)
}
}
fclose(f)
}
// Build Model Menu:
g_pMenu = menu_create("Player Models", "actionModelMenu")
new str[6]
menu_additem(g_pMenu, "Off", "-1") // First option is to reset the model
for(new i = 0; i < g_iModelsNum; i++)
{
num_to_str(i, str, 5)
menu_additem(g_pMenu, g_szModels[i], str)
}
// for(new i = 0; i < 20; i++)
// { // Here just to check how pages work with the "new" menu style.
// menu_additem(g_pMenu, "Option", "-2")
// }
menu_setprop(g_pMenu, MPROP_EXIT, MEXIT_ALL)
return PLUGIN_CONTINUE
}
else if(mode == 1)
{
add(szModelFilePath, sizeof(szModelFilePath) - 1, "/pmod_lite.ini")
if( file_exists(szModelFilePath) )
{
new f = fopen(szModelFilePath, "rt")
new data[20], szModelPath[64]
while( !feof(f) && g_iModelsNum < MAX_MODELS )
{
fgets(f, data, sizeof(data) - 1)
trim(data)
if( !data[0] || data[0] == ';' || data[0] == '/' && data[1] == '/' ) continue;
// Stuff here.
server_print(">>>%s<<<", data)
formatex(szModelPath, 63, "models/player/%s/%s.mdl", data, data)
if(file_exists(szModelPath))
{
server_print("File exists!!!! ^"%s^"", szModelPath)
precache_model(szModelPath)
copy(g_szModels[g_iModelsNum], MODEL_NAME_LEN, data)
g_iModelsNum++
}
else
{
server_print("DNE DNE!!!! ^"%s^"", szModelPath)
}
}
fclose(f)
}
// Build Model Menu:
g_pMenu = menu_create("Player Models", "actionModelMenu")
new str[6]
menu_additem(g_pMenu, "Off", "-1") // First option is to reset the model
for(new i = 0; i < g_iModelsNum; i++)
{
num_to_str(i, str, 5)
menu_additem(g_pMenu, g_szModels[i], str)
}
// for(new i = 0; i < 20; i++)
// { // Here just to check how pages work with the "new" menu style.
// menu_additem(g_pMenu, "Option", "-2")
// }
menu_setprop(g_pMenu, MPROP_EXIT, MEXIT_ALL)
return PLUGIN_CONTINUE
}
else if(mode == 0)
{
return PLUGIN_CONTINUE
}
return PLUGIN_CONTINUE
}
public set_model(id)
{
new mode =(get_cvar_num("amx_pmod_mode"))
if(mode == 0)
{
client_print(id,print_console,"[AMXX] Pmod has been disabled for stability reasons!")
return PLUGIN_HANDLED
}
else if((mode == 1) || (mode == 2))
{
new szArg[MODEL_NAME_LEN+1]
read_argv(1, szArg, MODEL_NAME_LEN)
if(equal(szArg, "off"))
{
tfc_clearmodel(id)
console_print(id, "Your model is set to default.", szArg)
}
else if(is_valid_model(szArg))
{
tfc_setmodel(id, szArg, "1")
console_print(id, "Your model is set to ^"%s^"", szArg)
}
else
{
console_print(id, "Number of Models Loaded: %d", g_iModelsNum)
for(new i = 0; i < g_iModelsNum; i++)
{
console_print(id, "%d. %s", i+1, g_szModels[i])
}
}
}
return PLUGIN_HANDLED
}
bool:is_valid_model(arg[])
{
for(new i = 0; i < g_iModelsNum; i++)
{
if(equal(arg, g_szModels[i]))
{
return true
}
}
return false
}
public cmdModelMenu(id,level,cid)
{
new mode =(get_cvar_num("amx_pmod_mode"))
if(mode == 0)
{
client_print(id,print_chat,"[AMXX] Pmod has been disabled for stability reasons!")
return PLUGIN_HANDLED
}
else if((mode == 1) || (mode == 2))
{
if(!cmd_access(id,level,cid,1))
{
return PLUGIN_HANDLED
}
menu_display(id, g_pMenu, 0)
}
return PLUGIN_HANDLED
}
public actionModelMenu(id,menu,item)
{
if( item == MENU_EXIT )
{
// DO NOT DESTROY MENU
return PLUGIN_HANDLED
}
new data[6], iName[64]
new access_, callback
menu_item_getinfo(menu, item, access_, data,5, iName, 63, callback)
new iModelNum = str_to_num(data)
if(iModelNum < 0)
{
tfc_clearmodel(id)
client_print(id, print_chat, "[AMXX] Player model is now default.")
}
else
{
tfc_setmodel(id, g_szModels[iModelNum], "1")
client_print(id, print_chat, "[AMXX] Player model set to ^"%s^"", g_szModels[iModelNum])
}
return PLUGIN_HANDLED
}
public plugin_end()
{
menu_destroy(g_pMenu)
}
public random_model(id)
{
new mode =(get_cvar_num("amx_pmod_mode"))
if(mode == 0)
{
client_print(id,print_chat,"[AMXX] Pmod has been disabled for stability reasons!")
return PLUGIN_HANDLED
}
else if((mode == 1) || (mode ==2))
{
new RandID = random_num(1,MAX_MODELS-1)
if (is_valid_model(g_szModels[RandID]))
{
tfc_setmodel(id, g_szModels[RandID] , "1")
client_print(id, print_chat, "[AMXX] Model randomly selected as ^"%s^"",g_szModels[RandID])
copy(g_currentmodel[id],64,g_szModels[RandID])
}
else
{
set_task(0.1,"random_model",id)
}
}
return PLUGIN_HANDLED
}
in amxmodx/configs/maps/MAPNAME.cfg will it work properly and load the right file? or none at all, thus not precaching anything or whatnot.. just want to know.. if this will work as I expect it to.. so can someone tell me if it will or not?