| Mini_Midget |
10-18-2010 08:00 |
Randomizing player models with correct hitboxes
I'm having problems trying to read from my .ini file and to set the correct model hitboxes or not.
So far it is reading from the file and precaching the correct files and setting it randomly on spawn.
But what I'm having problems with is setting it to either use the model hitboxes or the default CS hitboxes.
The reason why I'm doing this is because I have models that are not normal size (such as headcrabs) and some which are.
The .ini file looks like this.
Code:
;Put your list of custom models here and 0 or 1 after it to decide if the
;model should use the default CS model hitboxes or the custom model hitboxes
;The line below would load the model and use the custom_model_default hitboxes rather than the default CS ones
;custom_model_hitboxes 1
;The line below would low the custom model but use the default CS model hitboxes
;custom_model_default 0
;zombie_swarm 1
zombie_original 1
;dotd_classic 1
;dotd_torso 0
headcrab 1
PHP Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fakemeta> #include <engine> #include <hamsandwich>
new const OFFSET_MODELINDEX = 491 new const OFFSET_LINUX = 5
#define TASKID_MODEL 3810
new model_name[256][256]; new model_index[256]; new model_index_bool[256]; new models_count;
new g_CurrentModel[33][32]; // new g_ModelIndex[sizeof g_ZombiePlayerModels]; new g_DefaultModelIndex; new bool: b_Model[33];
new Float: g_flCounter;
public plugin_init() { register_plugin("PLUGIN", "VERSION", "AUTHOR") RegisterHam(Ham_Spawn, "player", "bacon_Spawn_Post", 1) register_forward(FM_SetClientKeyValue, "fw_SetClientKeyValue") register_forward(FM_ClientUserInfoChanged, "fw_ClientUserInfoChanged") register_logevent("Round_End" , 2, "1=Round_End")
}
public plugin_precache() { precache_ParseINI; for(new i = 0 ; i < models_count ; i++) { new ZombieModel[256] format(ZombieModel, charsmax(ZombieModel), "models/player/%s/%s.mdl", model_name[i], model_name[i]); if(file_exists(ZombieModel)) { model_index[i] = precache_model(ZombieModel); log_amx("%s precached!!!", model_name[i]); } else log_amx("%s does not exist!! Fail.", model_name[i]); } g_DefaultModelIndex = precache_model("models/player.mdl");
}
public precache_ParseINI() { static configs_dir[256], file_name[256], zswarm_dir[256]; get_configsdir(configs_dir, sizeof configs_dir - 1); formatex(zswarm_dir, sizeof zswarm_dir - 1,"%s/Zombie_Swarm",configs_dir); formatex(file_name, sizeof file_name - 1, "%s/zswarm_models.ini",zswarm_dir); if(!dir_exists(zswarm_dir)) mkdir(zswarm_dir); if(!file_exists(file_name)) write_file(file_name,""); static iLine, iLength, file_text[256]; static file_model_name[256]; static file_model_index static ZombieModel[256]; static zombie_index_bool[256]; while(read_file(file_name, iLine++, file_text, sizeof file_text - 1, iLength)) { if((file_text[0]== ';') || !iLength) continue; //zombie_swarm 1 parse(file_text, file_model_name, charsmax(file_model_name), file_model_index, 1); ZombieModel = file_model_name; log_amx("Parse %s. Success!!!", ZombieModel); zombie_index_bool[models_count] = file_model_index; format(model_name[models_count], charsmax(model_name), "%s", ZombieModel); format(model_index_bool[models_count], 1, "%s", zombie_index_bool); models_count++; } }
public Round_End() g_flCounter = 0.0
public bacon_Spawn_Post(id) { if (!is_user_alive(id)) return
static CsTeams: team ; team = cs_get_user_team(id) new currentmodel[32];
if (team == CS_TEAM_CT) // CT { copy(g_CurrentModel[id], charsmax(g_CurrentModel[]), model_name[random(models_count)]);
fm_get_user_model(id, currentmodel, charsmax(currentmodel) );
if(!equal(currentmodel, g_CurrentModel[id]) && !b_Model[id]) { set_task(0.5 + g_flCounter, "Task_Model", id + TASKID_MODEL); g_flCounter += 0.1; } } }
public fw_SetClientKeyValue(id, infobuffer, key[], value[]) { if (b_Model[id] && equal(key, "model")) return FMRES_SUPERCEDE
return FMRES_IGNORED }
public fw_ClientUserInfoChanged(id, infobuffer) { if (!b_Model[id]) return FMRES_IGNORED
new currentmodel[32]; fm_get_user_model(id, currentmodel, charsmax(currentmodel) );
if(!equal(currentmodel, g_CurrentModel[id])) fm_set_user_model(id, g_CurrentModel[id])
return FMRES_IGNORED }
public Task_Model(task) { new id = task - TASKID_MODEL
fm_set_user_model(id, g_CurrentModel[id]) client_print(id, print_chat, "CHANGING MODEL"); }
stock fm_set_user_model(player, modelname[]) { engfunc(EngFunc_SetClientKeyValue, player, engfunc(EngFunc_GetInfoKeyBuffer, player), "model", modelname) for(new i = 0 ; i < sizeof model_name ; i++) { if(!equal(modelname, model_name[i])) set_pdata_int(player, OFFSET_MODELINDEX, g_DefaultModelIndex, OFFSET_LINUX) if(model_index_bool[i]) { set_pdata_int(player, OFFSET_MODELINDEX, model_index[i], OFFSET_LINUX) } }
b_Model[player] = true }
stock fm_get_user_model(player, model[], len) { engfunc(EngFunc_InfoKeyValue, engfunc(EngFunc_GetInfoKeyBuffer, player), "model", model, len) }
|