this just pwns. bodyguards become regular soldiers when the person they are protecting dies. bots can now use any weapons.
Code: //----------------------------------------AI PLAYER SCRIPT
//written by members of Cemetech.net including Kerm Martian, elfprince13, & jpez
///////////////////
/// server commands
///////////////////
function serverCmdcFA(%client,%wep,%number,%color)
{
createFighterArmy(%client,%wep,%number,%color);
}
function serverCmdrVB(%client,%numred,%numblue)
{
createRandomFighterArmy(%numred,"red");
createRandomFighterArmy(%numblue,"blue");
}
function serverCmdcRFA(%client,%number,%color)
{
createRandomFighterArmy(%number,%color);
}
function servercmdAddfbot(%client){
addbot(%client);
}
function servercmdSetTeam(%client,%color){
%firstword = getword(%client.player.getshapename(),0);
if(%firstword $= "") %firstword = "namelesswonder";
%client.player.setshapename(%firstword SPC "army" SPC %color);
}
function serverCmdCbg(%client){
createBodyGuard(%client.namebase);
}
///////////////////
///end of server commands
///////////////////
///////////
///general
///////////
$botlist[0] = "DUMMY";
$numbots = 0;
function blist(){
for(%i = 0; %i < $numbots; %i++){
%bot = $botlist[%i];
echo(%bot SPC %bot.getName());
}
}
function clearthebots(){
MessageBoxYesNo( "Bot Genocide", "Do you really want to kill all the robots?", "clearbotstwo();", "");
}
function clearbotstwo(){
MessageBoxYesNo( "You are a horrible person!", "Even the really cute ones?", "clearbots();", "");
}
//clearbots() server command
function serverCmdcB()
{
clearbots();
}
function clearbots(){
$gdelbots = 1;
$botlist[0] = "DUMMY";
$numbots = 0;
echo("killing bots...");
}
function randomWeapon(){
%index = getRandom(41) + 1;
%index = ($weapon[%index].getname() $= 'nuke' || $weapon[%index].getname() $= 'flashlight')? 41 : %index;
return $weapon[%index].getname();
}
function randomPlayer(){
%index = getRandom(ClientGroup.getCount() - 1);
return ClientGroup.getObject(%index);
}
function move(%who,%targetlocation){
%targetx = getWord( %targetlocation, 0);
%targety = getWord( %targetlocation, 1);
%targetz = getWord( %targetlocation, 2);
%whox = getWord( %who.getTransform(), 0);
%whoy = getWord( %who.getTransform(), 1);
%whoz = getWord( %who.getTransform(), 2);
%who.setMoveDestination(%targetlocation);
if ( %whoz < %targetz)
{
%bvel = %who.getVelocity();
%xvel = getWord(%bvel, 0);
%yvel = getWord(%bvel, 0);
%zvel = getWord(%bvel, 0);
%who.setVelocity(%xvel SPC %yvel SPC (%zvel + 17));
}
if (inWater(%who) != 0){
%who.playThread(0,crouch);
if(%whoz > %targetz){
%bvel = %who.getVelocity();
%xvel = getWord(%bvel, 0);
%yvel = getWord(%bvel, 0);
%zvel = getWord(%bvel, 0);
%who.setVelocity(%xvel SPC %yvel SPC (%zvel - 20));
}
} else{
%who.stopThread(0);
}
}
function listplayers(){
%center = "0 0 0";
initContainerRadiusSearch(%center,1000000000.0,$TypeMasks::PlayerObjectType);
%next = containerSearchNext();
while(isObject(%next)){
echo("ID:" SPC %next SPC "NAME:" SPC %next.getshapename());
echo(" "@getarmy(%next));
%next = containerSearchNext();
}
}
function inWater(%bot){
if(isObject(%bot)){
%bt = %bot.getTransform();
%center = getWords(%bt, 0 ,2);
initContainerRadiusSearch(%center,1.0,$TypeMasks::WaterObjectType);
return containerSearchNext();
}
return 0;
}
///////////
///end of general
///////////
////////////////////////////////
/// team stuff
///////////////////////////////
function createFighterArmy(%client,%wep,%number,%color)
{
createFighterBot(%wep,%client.namebase,%color);
%number--;
if (%number > 0)
{
schedule(2000,0,createFighterArmy,%client,%wep,%number,%color);
}
}
function createRandomFighterArmy(%number,%color)
{
cfb(%color);
%number--;
if (%number > 0)
{
schedule(2000,0,createRandomFighterArmy,%number,%color);
}
}
function cfb(%army){
%randomplayer = ClientGroup.getObject(getRandom(ClientGroup.getCount() - 1));
createFighterBot(randomWeapon(),%randomplayer.namebase,%army);
}
function createFighterBot(%wep,%targetName,%armyName)
{
$gdelbots = 0;
%who = new AIPlayer() {
dataBlock = LightMaleHumanArmor;
aiPlayer = true;
};
if(%wep $= "") %wep = "sword";
%wep = %wep@"Image";
%target = getPlayerByName(%targetName);
MissionCleanup.add(%who);
echo("ID :"@%who);
// Player setup
%who.setMoveSpeed(1);
%who.setTransform(pickSpawnPoint());
%who.setEnergyLevel(60);
%name = getWord(%targetname,0) SPC "Bot" SPC %armyName;
echo(%name);
%who.setName(%name);
%who.setshapename(%name);
%who.setSkinName(%armyName); //bots wear their army color
%who.mountImage(%target.headCode, $headSlot, 1, %target.headCodeColor);
%who.mountImage(%target.visorCode, $visorSlot, 1, %target.visorCodeColor);
%who.mountImage(%target.backCode, $backSlot, 1, %target.backCodeColor);
%who.mountImage(%target.leftHandCode, $leftHandSlot, 1, %target.leftHandCodeColor);
%who.mountImage(%target.chestCode, $chestSlot, 1, %target.chestdecalcode);
%who.mountImage(%target.faceCode, $faceSlot, 1, %target.facedecalcode);
%who.mountImage(nametoid(%wep),$rightHandSlot);
$botlist[$numbots] = %who;
$numbots++;
schedule(1000,0,mybotreaim,%who,%name);
}
function mybotreaim(%who,%name)
{
if(isobject(%who)){
if($gdelbots == 1){
%who.kill();
return;
}
%target = findClosestEnemy(%who);
%whox = getWord( %who.getTransform(), 0 );
%whoy = getWord( %who.getTransform(), 1 );
%whoz = getWord( %who.getTransform(), 2 );
if (isobject(%target) && getarmy(%bot) !$= getarmy(%target))
{
%who.setAimObject(%target);
%who.setImageTrigger(0,1);
%targetlocation = getWords(%target.getTransform(),0,2);
} else{
%who.clearaim();
%whox = %whox + getrandom(2) - 1;
%whoy = %whox + getrandom(2) - 1;
%targetlocation = %whox SPC %whoy SPC %whoz;
}
%targetx = getWord( %targetlocation, 0);
%targety = getWord( %targetlocation, 1);
%targetz = getWord( %targetlocation, 2);
%who.setShapeName(%name);
move(%who,%targetlocation);
%who.setAimLocation(%targetx@" "@%targety@" "@%targetz);
schedule(1000,0,mybotreaim,%who,%name);
}
}
function getPlayerByName(%playername){
for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++) {
%victim = ClientGroup.getObject( %clientIndex );
if (%victim.namebase $= %playername) return %victim;
}
return 0;
}
function getArmy(%who){
if(isobject(%who)){
return getWord( %who.getShapeName(), 2);
}
return "";
}
//finds the closest member of a non-friendly army
function findClosestEnemy(%bot){
if(isobject(%bot)){
%center = getwords(%bot.getTransform(),0,2);
initContainerRadiusSearch(%center,1000000000.0,$TypeMasks::PlayerObjectType);
%next = containerSearchNext();
while(isObject(%next)){
if(getarmy(%next) !$= getarmy(%bot)) return %next;
%next = containerSearchNext();
}
}
return 0;
}
/////////////////////////////////////////
///end of team stuff
/////////////////////////////////////////
////////////////////////////////////////
////begin bodyguard stuff
////////////////////////////////////////
function createBodyGuard(%targetName)
{
if(!isobject(getPlayerByName(%targetname))) return 0;
$gdelbots = 0;
%who = new AIPlayer() {
dataBlock = LightMaleHumanArmor;
aiPlayer = true;
};
%target = getPlayerByName(%targetName);
MissionCleanup.add(%who);
echo("ID :"@%who);
// Player setup
%who.setMoveSpeed(1);
%tt = %target.player.getTransform();
%who.setTransform((getwords(%tt,0) + 3) SPC getwords(%t,1) SPC getwords(%tt,2));
%who.setEnergyLevel(60);
%name = getWord(%targetname,0)@"'s bodyguard" SPC getarmy(%target.player);
echo(%name);
%who.setName(%name);
%who.setshapename(%name);
%who.setSkinName(%armyName); //bots wear their army color
%who.mountImage(%target.headCode, $headSlot, 1, %target.headCodeColor);
%who.mountImage(%target.visorCode, $visorSlot, 1, %target.visorCodeColor);
%who.mountImage(%target.backCode, $backSlot, 1, %target.backCodeColor);
%who.mountImage(%target.leftHandCode, $leftHandSlot, 1, %target.leftHandCodeColor);
%who.mountImage(%target.chestCode, $chestSlot, 1, %target.chestdecalcode);
%who.mountImage(%target.faceCode, $faceSlot, 1, %target.facedecalcode);
%who.mountImage(nametoid(flamethrowerimage),$rightHandSlot);
$botlist[$numbots] = %who;
$numbots++;
schedule(1000,0,bodyguardreaim,%who,%target.player);
}
function bodyguardreaim(%who,%owner)
{
if(isobject(%who)){
if($gdelbots == 1){
%who.kill();
return;
}
if(isobject(%owner)){
%target = findThreat(%who,%owner);
%whox = getWord( %who.getTransform(), 0 );
%whoy = getWord( %who.getTransform(), 1 );
%whoz = getWord( %who.getTransform(), 2 );
if (isobject(%target) && isobject(%owner) && isValidTarget(%bot,%owner,%target))
{
%who.setAimObject(%target);
%who.setImageTrigger(0,1);
%targetlocation = %target.getTransform();
} else{
%who.clearaim();
%whox = %whox + getrandom(2) - 1;
%whoy = %whox + getrandom(2) - 1;
%targetlocation = %whox SPC %whoy SPC %whoz;
}
if(isobject(%owner) && isobject(%who)){
%who.setShapeName(getword(%owner.getshapename(),0)@"'s bodyguard" SPC getarmy(%owner));
%targetx = getWord( %targetlocation, 0);
%targety = getWord( %targetlocation, 1);
%targetz = getWord( %targetlocation, 2);
move(%who,%owner.getTransform());
%who.setAimLocation(%targetx@" "@%targety@" "@%targetz);
schedule(1000,0,bodyguardreaim,%who,%owner);
}
}
}
if(!isObject(%owner)){
%army = getarmy(%who) $= "" ? "red" : getarmy(%who);
%name = "exbodyguard bot" SPC %army;
schedule(1000,0,mybotreaim,%who,%name);
}
}
function findThreat(%bot,%owner){
if(isobject(%bot)){
%center = getwords(%bot.getTransform(),0,2);
initContainerRadiusSearch(%center,1000000000.0,$TypeMasks::PlayerObjectType);
%next = containerSearchNext();
while(isObject(%next)){
if(isValidTarget(%bot,%owner,%next)) return %next;
%next = containerSearchNext();
}
}
return 0;
}
function isValidTarget(%bot,%owner,%next){
if(isobject(%bot) && isobject(%bot) && isobject(%next)) return (%next != %owner) && (%next.getshapename() !$= %bot.getshapename()) && ((getarmy(%bot) !$= getarmy(%next) && getarmy(%owner) !$= "") || (getarmy(%owner) $= ""));
return 0;
}
////////////////////////////////////////
////end bodyguard stuff
////////////////////////////////////////
//////////////////
//overrides
//////////////////
function tbmcollison(%tbmthis,%tbmobj,%tbmcol,%tbmfade,%tbmpos,%tbmnormal) {
if (%tbmcol.getClassName() !$= "Player" && %tbmcol.getClassName() !$= "AIplayer")
return;
%colData = %tbmcol.getDataBlock();
%colDataClass = %colData.classname;
if ( %tbmcol.getClassName() $= "AIPlayer") {
%tbmcol.damage(%tbmobj,%tbmpos,%tbmthis.directDamage,%tbmobj.getdatablock().damagemsg);
return;
}
if (%tbmcol.getClassName() $= "Player" ) {
%dmg = %tbmthis.directDamage;
%dmg = %tbmcol.client.DMShield? 0 : (%tbmcol.client.DMArmor == 1? 0.25 * %dmg : %dmg);
%tbmcol.damage(%tbmobj,%tbmpos,%dmg,%tbmobj.getdatablock().damagemsg);
return;
}
return;
}