Something like this:
var namp;
namp = amp_get_new_party_id()
if(namp != NONE){
//Fits in party
amp_generate_monster(namp, SPECIES, LEVEL)
}
else{
namp = amp_get_new_box_id()
if(namp != NONE){
//Placed in box
amp_generate_monster(namp, SPECIES, LEVEL)
}
else{
//No room, can't be taken
}
}