PDA

View Full Version : Save custom player model and retrieve



Toxys
2nd November 2020, 13:47
I have a mod which set the player's model to custom models if you select that in the menu

An example from the ui_mp/objects1.menu


execKey "a" { play "mouse_click"; scriptMenuResponse "xmodel/brush_desertshrubgroup01"; close objects1 }

itemDef
{
name "button_a"
visible 1
rect 0 0 128 20
origin ORIGIN_CHOICEA
forecolor GLOBAL_UNFOCUSED_COLOR
type ITEM_TYPE_BUTTON
text "@OBJ_OBJ1_1"
textfont UI_FONT_NORMAL
textscale .3
textstyle ITEM_TEXTSTYLE_SHADOWED
textaligny 20
action
{
play "mouse_click";
scriptMenuResponse "xmodel/brush_desertshrubgroup01";
close objects1
}
}



This is set a custom player model on mouse click or button_a, if I'm right.

Now I want to make this model to invisible I found a script which was made by IzNoGoD:


makeInvisible(arg)
{
if(!isdefined(self.isInv)) self.isInv= false;

if((arg) && (!self.isInv))
{
self detachall();
self setmodel("");
self.isInv= true;
}
else
{
if(!isdefined(self.pers["savedmodel"]))
maps\mp\gametypes\_teams::model();
else
maps\mp\_utility::loadModel(self.pers["savedmodel"]);
self.isInv= false;
}
}

Okay, this is make the model to invisible if I'm calling makeInvisible(true); but after that I can't set the model back which was before... (xmodel/brush_desertshrubgroup01) I'm always getting back the default allies model

I see in the maps\mp\_utility.gsc have 2 functions which save and load model but how can I save these models like that if the script changing the custom models in a menu file?


saveModel()
{
info["model"] = self.model;
info["viewmodel"] = self getViewModel();
attachSize = self getAttachSize();
info["attach"] = [];

for(i = 0; i < attachSize; i++)
{
info["attach"][i]["model"] = self getAttachModelName(i);
info["attach"][i]["tag"] = self getAttachTagName(i);
info["attach"][i]["ignoreCollision"] = self getAttachIgnoreCollision(i);
}

return info;
}

loadModel(info)
{
self detachAll();
self setModel(info["model"]);
self setViewModel(info["viewmodel"]);

attachInfo = info["attach"];
attachSize = attachInfo.size;

for(i = 0; i < attachSize; i++)
self attach(attachInfo[i]["model"], attachInfo[i]["tag"], attachInfo[i]["ignoreCollision"]);
}

IzNoGoD
2nd November 2020, 19:46
Do you savemodel after you setmodel at spawn?

Toxys
2nd November 2020, 19:50
I don't set the model at spawn as I said this script is setting the model when I click on a button in the menu... a .menu file handling the setmodel or I'm wrong?


execKey "a" { play "mouse_click"; scriptMenuResponse "xmodel/brush_desertshrubgroup01"; close objects1 }

itemDef
{
name "button_a"
visible 1
rect 0 0 128 20
origin ORIGIN_CHOICEA
forecolor GLOBAL_UNFOCUSED_COLOR
type ITEM_TYPE_BUTTON
text "@OBJ_OBJ1_1"
textfont UI_FONT_NORMAL
textscale .3
textstyle ITEM_TEXTSTYLE_SHADOWED
textaligny 20
action
{
play "mouse_click";
scriptMenuResponse "xmodel/brush_desertshrubgroup01";
close objects1
}
}

maxdamage99
3rd November 2020, 06:37
I don't set the model at spawn as I said this script is setting the model when I click on a button in the menu... a .menu file handling the setmodel or I'm wrong?


execKey "a" { play "mouse_click"; scriptMenuResponse "xmodel/brush_desertshrubgroup01"; close objects1 }

itemDef
{
name "button_a"
visible 1
rect 0 0 128 20
origin ORIGIN_CHOICEA
forecolor GLOBAL_UNFOCUSED_COLOR
type ITEM_TYPE_BUTTON
text "@OBJ_OBJ1_1"
textfont UI_FONT_NORMAL
textscale .3
textstyle ITEM_TEXTSTYLE_SHADOWED
textaligny 20
action
{
play "mouse_click";
scriptMenuResponse "xmodel/brush_desertshrubgroup01";
close objects1
}
}

1. try search code from .gsc like:


/* ... */

self waittill("menuresponse", menu, response);

if (menu == "objects1")
self setmodel(response);

/* ... */


2. try


makeInvisible(arg)
{
if(!isdefined(self.isInv)) self.isInv= false;

if((arg) && (!self.isInv))
{
//save model before invi
self maps\mp\_utility::saveModel();

self detachall();
self setmodel("");
self.isInv = true;
}
else
{
if(!isdefined(self.pers["savedmodel"]))
maps\mp\gametypes\_teams::model();
else
maps\mp\_utility::loadModel(self.pers["savedmodel"]);
self.isInv= false;
}
}