Bumping this to post my AiConnection::recycle method. It prepares the bot for reuse by basically stripping it back to a vanilla AiConnection. This is what I use for my similar recycler. Simply call this whenever you would call AiConnection::delete.
function AiConnection::recycle(%this)
{
if(isObject(%this.minigame))
%this.minigame.removeMember(%this);
if(isObject(%this.camera))
%this.camera.delete();
if(isObject(%this.player))
%this.player.delete();
if(isObject(%this.tempBrick))
%this.tempBrick.delete();
if(isObject(%this.brickGroup) && %this.brickGroup.client == %this)
%this.brickGroup.client = -1;
%index = 0;
while((%field = %this.getTaggedField(%index)) !$= "")
{
//some fields cannot be changed once set.... Thanks, Badspot.
if(%lastField $= %field)
{
%index ++;
continue;
}
%lastField = %field;
%field = getField(%field,0);
//Prevent people from breaking things
if(%field !$= stripChars(%field," `~!@#$%^&*()-=+[{]}\\|;:\'\",<.>/?"))
{
error("ERROR (AiConnection::recycle): Invalid field! Skipping...");
%index ++;
continue;
}
eval(%this @ "." @ %field SPC "= \"\";");
}
if(!isObject(aiRecycler))
{
new SimSet(aiRecycler);
missionCleanup.add(aiRecycler);
}
aiRecycler.add(%this);
}
Edit: Patched a security flaw reported by Xalos.