Results 1 to 4 of 4

Thread: COD2 MP: defining setPlayerModels - based on player's multiplayer name.

  1. #1
    Private
    Join Date
    Mar 2021
    Location
    Netherlands
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post

    COD2 MP: defining setPlayerModels - based on player's multiplayer name.

    I have been unsuccesfully trying to setup a custom MP model for each of my online LAN players - based on their multiplayer name.
    I've tried a number of variations, searched online and checked out other mods, but I just dont't get the self.name/multiplayer name part to work. (clearly I have little coding knowledge.. )
    Do I need to precache something, and/or define the player names beforehand ?

    Any help would be appreciated!
    Regards,
    Michel (Knokploeg sound mod maker, back in the day..)


    --> maps\mp\gametypes dm.gsc --> thread maps\mp\gametypes\_teams::init();
    --> _teams.gsc
    --> setPlayerModels()

    {
    switch(game["allies"])
    {
    case "british":

    if(isdefined(game["british_soldiertype"]) && game["british_soldiertype"] == "africa") && (self.name["playername1"])
    {
    mptype\mp_british_africa_playername1recache();
    game["allies_model"] = mptype\mp_british_africa_playername1::main;
    }
    else if(isdefined(game["british_soldiertype"]) && game["british_soldiertype"] == "africa") && (self.name["playername2"])
    {
    mptype\mp_british_africa_playername2recache();
    game["allies_model"] = mptype\mp_british_africa_playername2::main;
    }

    and so forth..

  2. #2
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    The function 'setPlayerModels()' precaches and sets which model are used for which team (global initialization).
    The function 'model()' is run on the player and determines which model is used.

    So you want something like this:

    PHP Code:
    setPlayerModels()
    {
        switch(
    game["allies"])
        {
            case 
    "british":
                if(
    isdefined(game["british_soldiertype"]) && game["british_soldiertype"] == "africa")
                {
                    
    mptype\british_africa::precache();
                    
    game["allies_model"] = mptype\british_africa::main;
                }
                else
                {
                    
    mptype\british_normandy::precache();
                    
    game["allies_model"] = mptype\british_normandy::main;
                }
                break;
        
            case 
    "russian":
                if(
    isdefined(game["russian_soldiertype"]) && game["russian_soldiertype"] == "padded")
                {
                    
    mptype\russian_padded::precache();
                    
    game["allies_model"] = mptype\russian_padded::main;
                }
                else
                {
                    
    mptype\russian_coat::precache();
                    
    game["allies_model"] = mptype\russian_coat::main;
                }
                break;
        
            case 
    "american":
            default:
                
    mptype\american_normandy::precache();
                
    game["allies_model"] = mptype\american_normandy::main;
        }

        
    // Here we initialize the player models we want for player one and two.
        
    mptype\german_winterdark::precache();
        
    mptype\german_winterlight::precache();
        
    game["axis_model_playerone"] = mptype\german_winterdark::main;
        
    game["axis_model_playertwo"] = mptype\german_winterlight::main;
        
        if(
    isdefined(game["german_soldiertype"]) && game["german_soldiertype"] == "winterdark")
        {
            
    game["axis_model"] = mptype\german_winterdark::main;
        }
        else if(
    isdefined(game["german_soldiertype"]) && game["german_soldiertype"] == "winterlight")
        {
            
    game["axis_model"] = mptype\german_winterlight::main;
        }
        else if(
    isdefined(game["german_soldiertype"]) && game["german_soldiertype"] == "africa")
        {
            
    mptype\german_africa::precache();
            
    game["axis_model"] = mptype\german_africa::main;
        }
        else
        {
            
    mptype\german_normandy::precache();
            
    game["axis_model"] = mptype\german_normandy::main;    
        }

    PHP Code:
    model()
    {
        
    self detachAll();
        
        if(
    self.pers["team"] == "allies") {
            [[
    game["allies_model"] ]]();
        } else if(
    self.pers["team"] == "axis") {
            if (
    self.name == "Player One") {
                [[
    game["axis_model_playerone"] ]]();
            } else if (
    self.name == "Player Two") {
                [[
    game["axis_model_playertwo"] ]]();
            } else {
                [[
    game["axis_model"] ]]();
            }
        }

        
    self.pers["savedmodel"] = maps\mp\_utility::saveModel();

    Last edited by Mitch; 4th March 2021 at 20:00. Reason: Fixed code spacing

  3. #3
    Private pollo's Avatar
    Join Date
    Jul 2012
    Location
    Spain
    Posts
    116
    Thanks
    93
    Thanked 69 Times in 35 Posts
    Precache your models only once in the gametype file, and basically call setModel("modelname") on a player entity.

    In your <gametype>.gsc (tdm.gsc) call a precache() function (don't thread it, otherwise it will keep going and might crash due to using un-precached stuff later), and inside there add all the precaches needed. Then change the behaviour of the loadModel function inside maps/mp/_utility.gsc to set the model to your needs. At last, do the check of the name and call that said loadModel function.

    Might have script errors, but the general idea is this (also the one that Mitch posted above):

    dm.gsc

    PHP Code:
    [...]

    Callback_StartGametype() {
        
    precache();
        
    // rest of stuff
        
    thread bla1();
        
    thread bla2();
        
    thread bla3();
    }

    [...]

    precache() {
        
    game["playermodels"] = [];
        
    game["playermodels"][0] = [];
        
    game["playermodels"][0]["model"] = "xmodel/model_0";
        
    game["playermodels"][0]["viewmodel"] = "xmodel/viewmodel_0";
        
        
    game["playermodels"][1] = [];
        
    game["playermodels"][1]["model"] = "xmodel/model_1";
        
    game["playermodels"][1]["viewmodel"] = "xmodel/viewmodel_1";

        
    game["playermodels"][2] = [];
        
    game["playermodels"][2]["model"] = "xmodel/model_2";
        
    game["playermodels"][2]["viewmodel"] = "xmodel/viewmodel_2";
        

        
        for(
    0game["playermodels"].sizei++) {
            
    precacheModel(game["playermodels"][i]["model"]);
            
    precacheModel(game["playermodels"][i]["viewmodel"]);
        }
    }

    [...]


    loadModel(info)
    {
        
    self detachAll();
        
        
    // get the saved model, then do the name check
        
    model undefined;
        
    viewmodel undefined;
        switch(
    self.name) {
            
    // add a case for each name check
            
    case "I will have model 0":
                
    model game["playermodels"][0]["model"];
                
    viewmodel game["playermodels"][0]["viewmodel"];
                break;
            case 
    "I will have model 1":
                
    model game["playermodels"][1]["model"];
                
    viewmodel game["playermodels"][1]["viewmodel"];
                break;
            case 
    "I will have model 2":
                
    model game["playermodels"][2]["model"];
                
    viewmodel game["playermodels"][2]["viewmodel"];
                break;
            default:
                
    // he will have the saved info["model"] that loads in setPlayerModels() (default one for each team)
                
    model info["model"];
                
    viewmodel info["viewmodel"];
        }
        
        
    self setModel(model);
        
    self setViewModel(viewmodel);

        
    // attach the rest of models
        
    attachInfo info["attach"];
        
    attachSize attachInfo.size;
        
        for(
    0attachSizei++)
            
    self attach(attachInfo[i]["model"], attachInfo[i]["tag"], attachInfo[i]["ignoreCollision"]);
    }

    [...] 
    Last edited by pollo; 4th March 2021 at 20:15.

  4. #4
    Private
    Join Date
    Mar 2021
    Location
    Netherlands
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post
    Oh yes! Mitch and Pollo, thank you so much for your help! I was quite stuck on this one and now it works like a charm! I have it working for DM (each MP player has their own unique model) and in TDM they have the correct allied/axis uniform + their own head
    Thanks again champs!

  5. The Following User Says Thank You to michelboonstra74 For This Useful Post:

    pollo (5th March 2021)

Tags for this Thread

Posting Permissions

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