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(i = 0; i < game["playermodels"].size; i++) {
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(i = 0; i < attachSize; i++)
self attach(attachInfo[i]["model"], attachInfo[i]["tag"], attachInfo[i]["ignoreCollision"]);
}
[...]