void switchToAlly(int player, int allyNumber, int spawnIfDead){
int subjectToScreen = getindexedvar("subjectToScreen");
void vSelf = getplayerproperty(player, "entity");
void ally = getindexedvar("ally" + allyNumber);
if(spawnIfDead && isDead(ally)){
setindexedvar("selectGrid", allyNumber);
setindexedvar("allyCaller", player);
togglePause(1);
return 1;
}
char allyModel = getentityproperty(ally, "model");
char allyDModel = getentityproperty(ally, "defaultmodel");
char allyName = getentityproperty(ally, "name");
int allyMap = getentityproperty(ally, "map");
int allyHealth = getentityproperty(ally, "health");
int allyX = getentityproperty(ally, "x");
int allyY = getentityproperty(ally, "y");
int allyZ = getentityproperty(ally, "z");
int allyDir = getentityproperty(ally, "direction");
int allyAnim = getentityproperty(ally, "animationid");
int allyAnimPos = getentityproperty(ally, "animpos");
int allyOrder = getentityvar(ally, "order");
int allyHoldPosition = getentityvar(ally, "holdPosition");
int allyHoldPositionZ = getentityvar(ally, "holdPositionZ");
int allyTarget = getentityvar(ally, "bindTarget");
changeentityproperty(ally, "model", getentityproperty(vSelf, "model"), 1);
changeentityproperty(ally, "name", getentityproperty(vSelf, "name"));
changeentityproperty(ally, "map", getentityproperty(vSelf, "map"));
changeentityproperty(ally, "health", getentityproperty(vSelf, "health"));
changeentityproperty(ally, "x", getentityproperty(vSelf, "x"));
changeentityproperty(ally, "y", getentityproperty(vSelf, "y"));
changeentityproperty(ally, "z", getentityproperty(vSelf, "z"));
changeentityproperty(ally, "direction", getentityproperty(vSelf, "direction"));
changeentityproperty(ally, "animation", getentityproperty(vSelf, "animationid"));
updateframe(ally, getentityproperty(vSelf, "animpos"));
setentityvar(ally, "order", getentityvar(vSelf, "order"));
setentityvar(ally, "holdPosition", getentityvar(vSelf, "holdPosition"));
setentityvar(ally, "holdPositionZ", getentityvar(vSelf, "holdPositionZ"));
setentityvar(ally, "movingToSpot", NULL());
releaseTargetEnt(ally);
setentityvar(ally, "bindTarget", getentityvar(vSelf, "bindTarget"));
changeentityproperty(ally, "hostile", openborconstant("TYPE_ENEMY"));
changeentityproperty(vSelf, "model", allyModel, 1);
changeentityproperty(vSelf, "name", allyName);
changeentityproperty(vSelf, "map", allyMap);
changeentityproperty(vSelf, "health", allyHealth);
changeentityproperty(vSelf, "x", allyX);
changeentityproperty(vSelf, "y", allyY);
changeentityproperty(vSelf, "z", allyZ);
changeentityproperty(vSelf, "direction", allyDir);
changeentityproperty(vSelf, "animation", allyAnim);
updateframe(vSelf, allyAnimPos);
setentityvar(vSelf, "order", allyOrder);
setentityvar(vSelf, "holdPosition", allyHoldPosition);
setentityvar(vSelf, "holdPositionZ", allyHoldPositionZ);
setentityvar(vSelf, "movingToSpot", NULL());
releaseTargetEnt(vSelf);
setentityvar(vSelf, "bindTarget", allyTarget);
changeplayerproperty(player, "name", allyName);
changeplayerproperty(player, "colourmap", allyMap);
if(subjectToScreen != NULL() && subjectToScreen == 0){
changeentityproperty(vSelf, "parent", NULL());
changeentityproperty(ally, "parent", NULL());
changeentityproperty(vSelf, "subject_to_screen", 0);
changeentityproperty(ally, "subject_to_screen", 0);
}
if(getentityproperty(vSelf, "aiflag", "walking") || getentityproperty(vSelf, "aiflag", "running") ||
getentityproperty(ally, "animationID") == openborconstant("ANI_run") || getentityproperty(ally, "animationID") == openborconstant("ANI_walk") || getentityproperty(vSelf, "aiflag", "blocking") || getentityproperty(ally, "animationID") == openborconstant("ANI_freespecial2")){
setidle(ally);
}
if(allyAnim == openborconstant("ANI_run") || allyAnim == openborconstant("ANI_walk") || allyAnim == openborconstant("ANI_backwalk") || allyAnim == openborconstant("ANI_follow21")){
setidle(vSelf);
}
init_NPC_WOT(ally);
refreshLifeBars();
}