The code works fine, but feels hardcoded, i still have problems with arrays, like if i dont -1 at random numbers i get default models.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#define VERSION "1.0"
#define PLUGIN "Models"
#define AUTHOR "Artorias"
new const g_szModels[64][64];
new g_szLine;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("ResetHUD", "resetModel", "bf")
}
public plugin_precache() {
new path[128];
new szLineData[33];
get_configsdir(path, charsmax(path))
format(path, charsmax(path), "%s/models.ini", path)
if(!file_exists(path)){
log_amx("Error: file does not exist (%s).", path)
return
}
new file = fopen(path, "rt")
if(!file){
log_amx("Error: Could not open file (%s).", path)
return
}
while(!feof(file))
{
fgets(file, szLineData, charsmax(szLineData))
replace(szLineData, charsmax(szLineData), "^n", "")
if (szLineData[0] == ';' || !szLineData[0] || equal(szLineData[0],"")) continue
g_szModels[g_szLine] = szLineData
g_szLine++
}
fclose(file)
for(new i = 0; i <= g_szLine;i++)
{
if(equal(g_szModels[i],""))
continue;
formatex(path, charsmax(path), "models/player/%s/%s.mdl", g_szModels[i], g_szModels[i]);
precache_model(path);
formatex(path, charsmax(path), "models/player/%s/%sT.mdl", g_szModels[i], g_szModels[i]);
if(file_exists(path))
precache_model(path);
}
}
public resetModel(id, level, cid) {
new rand = random_num(0, g_szLine - 1);
if (cs_get_user_team(id) == CS_TEAM_T && is_user_connected(id)){
cs_set_user_model(id, g_szModels[rand]);
}
}