I believe your losing it because SAMPLE_ENT is not being intialized properly in the "second()" function. I had a much better explanation a couple of hours ago before I started scripting out your problem, but its 1:30am, and my brain is fried, so I can't remember what it was,
.
Anyway, I hope you like this piece I did for you.
Code:
define maxModels, 100; // maximum models
define maxModelTypes, 10; // maximum model types
//--
define typeMONSTERS, 0;
//define up 9 more types here, must initialize to 1,2,3,4...
//--
define offset, skill1;
//--
var MODELS[maxModelTypes];
//--
// multiarray - supports 10 types of different models, up to 10 each
// i.e. typeMONSTERS with skill1 offset from 0-9
// typeTREES with skill1 offset from 0-9
// etc.
var MORPHMDLS[1000]; // 10x100 multiarray
//--
var fncMorphCheck;
//--
entity* tempPtr;
//--
string entname;
//--
function setEntName(mdlType,index)
{
if(mdlType == typeMONSTERS && index < maxModelTypes)
{
my = ptr_for_handle(MODELS[index]); // get me
}
//--
str_for_entfile(entname,my); // copy the entity into the string
//--
if(mdlType == typeMONSTERS && str_len(entname) > 0)
{
MORPHMDLS[typeMONSTERS*maxModels+index] = handle(entname); // save a handle to the string
}
// more types
//--
if(str_len(entname) == 0) { error("entname not initialized!"); }
if(index >= maxModelTypes || mdlType >= maxModelTypes){ error("Invalid type or index"); }
}
//--
function morphEntName(mdlType,index)
{
if(mdlType == typeMONSTERS && index < maxModelTypes)
{
my = ptr_for_handle(MODELS[index]); // get me
tempPtr = ptr_for_handle(MORPHMDLS[typeMONSTERS*maxModels+index]); // get ptr from name
if(tempPtr == NULL) { breakpoint; }
ent_morph(my,tempPtr); // morph me to ptr from name
}
// more types
//--
if(index >= maxModelTypes || mdlType >= maxModelTypes){ error("Invalid type or index"); }
}
//--
action entityMonster
{
if(my.offset < maxModelTypes) { MODELS[my.skill1] = handle(my); }
if(my.offset >= maxModelTypes) { error("Invalid offset!"); return; }
//--
setEntName(typeMONSTERS,my.skill1); // set the entity name
//--
//..testing
ent_morph(me,"ball.mdl");
//..
wait(-5);
morphEntName(typeMonsters,my.skill1); // get the entity name, and morph back
//--
}
Hope thats what your after, I tested it and it works great. Let em know if you have any questions.
-raiden