Setting player models
Can someone please take a look at this and tell my why nothing happens?
I have the folders in the correct places. Tried it with bots on listen server and no effect. No errors in console either. No compile warnings, loads fine.
I'm going crazy trying to figure out why it's not working.
It is supposed to give all the CT's one model, and all the T's models depending on which class they chose. (each class is set to one model for testing purposes)
PHP Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> #include <hamsandwich>
public plugin_init() { register_plugin("Player Models", "1.0", "vman"); register_event("HLTV", "evRoundStart", "a", "1=0", "2=0"); RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1); register_forward(FM_SetClientKeyValue, "fwSetClientKeyValue"); register_forward(FM_ClientUserInfoChanged, "fwClientUserInfoChanged"); }
public plugin_precache() { precache_model("models/player/vcmdl_ctcz-1/vcmdl_ctcz-1.mdl"); precache_model("models/player/vcmdl_tcz-1/vcmdl_tcz-1.mdl"); }
#define MODELSET_TASK 100
new Float:g_roundstarttime; new Float:g_models_targettime;
new bool:g_has_custom_model[33]; new g_player_model[33][32];
public client_putinserver(id) { g_has_custom_model[id] = false; }
public evRoundStart() { g_roundstarttime = get_gametime(); }
public fwHamPlayerSpawnPost(id) { if(is_user_alive(id)) { if(get_user_team(id) == 1) { if(task_exists(id + MODELSET_TASK)) { remove_task(id + MODELSET_TASK); } //fm_reset_user_model(id); new currentmodel[32]; fm_get_user_model(id, currentmodel, charsmax(currentmodel)); new terrmodel[32]; if(equal(currentmodel, "terror")) {terrmodel = "vcmdl_tcz-1";} else if(equal(currentmodel, "guerilla")) {terrmodel = "vcmdl_tcz-1";} else if(equal(currentmodel, "leet")) {terrmodel = "vcmdl_tcz-1";} else if(equal(currentmodel, "arctic")) {terrmodel = "vcmdl_tcz-1";} else if(equal(currentmodel, "militia")) {terrmodel = "vcmdl_tcz-1";} copy(g_player_model[id], charsmax(g_player_model[]), terrmodel); if(!equal(currentmodel, g_player_model[id])) { if(get_gametime() - g_roundstarttime < 5.0) { set_task(2.5, "fm_update_user_model", id + MODELSET_TASK); } else { fm_update_user_model(id + MODELSET_TASK); } } } else if(get_user_team(id) == 2) { if(task_exists(id + MODELSET_TASK)) { remove_task(id + MODELSET_TASK); } //fm_reset_user_model(id); copy(g_player_model[id], charsmax(g_player_model[]), "vcmdl_ctcz-1"); new currentmodel[32]; fm_get_user_model(id, currentmodel, charsmax(currentmodel)); if(!equal(currentmodel, g_player_model[id])) { if(get_gametime() - g_roundstarttime < 5.0) { set_task(2.5, "fm_update_user_model", id + MODELSET_TASK); } else { fm_update_user_model(id + MODELSET_TASK); } } } } }
public fwSetClientKeyValue(id, const infobuffer[], const key[]) { if(g_has_custom_model[id] && equal(key, "model")) { return FMRES_SUPERCEDE; } return FMRES_IGNORED; }
public fwClientUserInfoChanged(id) { if(!g_has_custom_model[id]) { return FMRES_IGNORED; } new currentmodel[32]; fm_get_user_model(id, currentmodel, charsmax(currentmodel)); if(!equal(currentmodel, g_player_model[id]) && !task_exists(id + MODELSET_TASK)) { fm_set_user_model(id + MODELSET_TASK); } return FMRES_IGNORED; }
public fm_update_user_model(taskid) { new Float:current_time; current_time = get_gametime(); if(current_time - g_models_targettime >= 0.5) { fm_set_user_model(taskid); g_models_targettime = current_time; } else { set_task((g_models_targettime + 0.5) - current_time, "fm_set_user_model", taskid); g_models_targettime = g_models_targettime + 0.5; } }
stock fm_reset_user_model(id) { dllfunc(DLLFunc_ClientUserInfoChanged, id, engfunc(EngFunc_GetInfoKeyBuffer, id)); g_has_custom_model[id] = false; }
stock fm_get_user_model(id, model[], len) { engfunc(EngFunc_InfoKeyValue, engfunc(EngFunc_GetInfoKeyBuffer, id), "model", model, len); }
public fm_set_user_model(id) { id -= MODELSET_TASK; engfunc(EngFunc_SetClientKeyValue, id, engfunc(EngFunc_GetInfoKeyBuffer, id), "model", g_player_model[id]); g_has_custom_model[id] = true; }
This is based on this tutorial
|