I had a thread going in the Server Hole, but I decided it would be more appropriate/get better visibility here.
Basically what I have is partially working, but I have some weirdness going on. The script adds the player's current model when they connect to the server to an array. On the next map change the array is parsed and everything is run through g_Game.PrecacheModel(). [This is done to avoid panicking the engine due to late precache]
Currently this is working with one small exception. The client has to disconnect and reconnect to the server even though the model is downloaded during the map change. I can't figure out why this is, but I've tested with several people and each of them had to perform a disconnect/reconnect before the model was visible, but they saw the model download during the map change and verified it was on their harddrive.
Code:
void PluginInit() {
g_Module.ScriptInfo.SetAuthor("lunchbox");
g_Module.ScriptInfo.SetContactInfo("noreply@oijfa.cloudns.pro");
g_Hooks.RegisterHook( Hooks::Player::ClientPutInServer, @ClientPutInServer);
}
CClientCommand g_ListPrecacheModels("listprecacheplayermodels", "List precached player model list", @ListPrecachePlayerModels);
array g_ModelPrecacheList(0);
//Add player models on connect
HookReturnCode ClientPutInServer(CBasePlayer@ pPlayer)
{
//Add newly joined player's model to model precache list if it doesn't already exist
KeyValueBuffer@ p_PlayerInfo = g_EngineFuncs.GetInfoKeyBuffer(pPlayer.edict());
if( g_ModelPrecacheList.find(p_PlayerInfo.GetValue("model")) < 0) {
g_Game.AlertMessage(at_console,"Adding model to precache:" + p_PlayerInfo.GetValue("model"));
g_ModelPrecacheList.insertLast(p_PlayerInfo.GetValue("model"));
}
return HOOK_HANDLED;
}
//Precache models for all connected players
void MapInit() {
//Parse model precache list on mapinit
for (uint i = 0; i < g_ModelPrecacheList.length(); i++) {
g_Game.AlertMessage(at_console,"Loading model" + "models/player/" + g_ModelPrecacheList[i] + "/" + g_ModelPrecacheList[i] + ".mdl");
g_Game.PrecacheModel("models/player/" + g_ModelPrecacheList[i] + "/" + g_ModelPrecacheList[i] + ".mdl");
}
//Clear list
g_ModelPrecacheList.resize(0);
}
//Debug list for precached models
void ListPrecachePlayerModels(const CCommand@ pArgs) {
CBasePlayer@ pCaller = g_ConCommandSystem.GetCurrentPlayer();
g_PlayerFuncs.ClientPrint(pCaller, HUD_PRINTCONSOLE, "Current player precache list:\n");
for (uint i = 0; i < g_ModelPrecacheList.length(); i++) {
g_PlayerFuncs.ClientPrint(pCaller, HUD_PRINTCONSOLE, g_ModelPrecacheList[i] + "\n");
}
}