Thread: [WIP] Download active player models on connect

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    46

    [WIP] Download active player models on connect

    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");
      }
    }

  2. #2
    Administrator Sniper's Avatar  
    Manager
    Join Date
    Aug 2001
    Posts
    7,121

    Re: [WIP] Download active player models on connect

    Sounds pretty fishy. Half-Life loads player models dynamically during the game when they're requested.

    Will have to research this.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    46

    Re: [WIP] Download active player models on connect

    I would like to add that the other players, in some instances, saw my character as just a small black spot on the ground after the initial map load when they downloaded the model I had selected. I didn't see this personally as I couldn't look over their shoulder (being in different locations,) but I thought it was worth mentioning in case it sparked an idea. I don't know if they were referring to the shadow being cast by the non-existent player model or if I was a model that was being rendered strangely as a small dark mass. In any case I wasn't visible as any player model until we moved around for a little while and I jumped around some.

    When they disconnected/reconnected I was rendered normally as the appropriate player model as soon as they connected.

  4. #4
    incognico nico's Avatar
    Join Date
    Aug 2015
    Posts
    447

    Re: [WIP] Download active player models on connect

    The game probably makes a list of the available models in models/player/ during the initial connect and not on map changes. You could try to play on a server, manually add a new model to models/player/ on your client and then tell someone to choose it - you won't see it if my assumption is true.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    46

    Re: [WIP] Download active player models on connect

    @nico, it appears I can confirm your suspicion. I had a couple of people try this and it does seem to be populating the available player model list on connection. The models do not show until you drop out of the current game and reconnect. I guess it re-queries the player model folder during map load or possibly pre-connection establishment.

  6. #6
    incognico nico's Avatar
    Join Date
    Aug 2015
    Posts
    447

    Re: [WIP] Download active player models on connect

    3 years late but this should work: https://github.com/incognico/svencoo...PrecacheDyn.as

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    191

    Re: [WIP] Download active player models on connect

    If only I had this idea many years ago, but this is only half of it . This should handle downloads, "if the server already has the player models", and make it a bit more efficient by only downloading the ones that are in use. You can then devise many efficient ways of sending and checking valid player.mdls to the server, then even custom ones never seen before, should then be downloaded, and sent almost on demand to any player. (probably, someone would make some inefficient piggyback plugins/modules that do the simplest thing possible, like upload to an FTP server, but whatever works I guess lol). I remember back when I started playing there were thousands of models around and a plugin like this would have been perfect. However, it's probably not worth it to make the other uploading half now just for a handful of users. I figure it would probably have to be in metamod, unless otherwise shown this can handle file uploads.

    I guess back then, you would also need to obtain (either hacky way, or some official way) to see how many precache slots are available because usually it was borderline all used and limited to 512. Here I see no check but I guess they increased it so there's no chance of hitting the limit anyway.
    Last edited by HL2 RULEZ; 27-08-2019 at 02:24 PM.
    BLEH. BLEHEG
    BLEHHEGLAH!!!!!!!!! O.o

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •