Other bots not spawning
by Matt Cuda · in Technical Issues · 03/05/2008 (1:15 pm) · 3 replies
Could someone look at this code and tell me what in the world is wrong?
This code should spawn three Guard bots but it only spawns one. I can see where the Guards are being created and there are no errors in the console.
Here is my code...
datablock PlayerData(Watcher : AIElfBody)
{
maxForwardSpeed = 2.2;
maxBackwardSpeed =2.2;
maxSideSpeed = 2;
shootingDelay = 2000;
};
function spawnbot(%index,%role)
{
DebugPrint( "%index:"@%index@"%role:"@%role@"~", spawnbot);
%me = null;
%me = new AIPlayer() {
dataBlock = Watcher;
aiPlayer = true;
};
%me.look = 0;
%me.range = 100;
%spawn=pickAISpawn(%index,%role);
%me.index = %index;
%me.setTransform(%spawn);
%me.setEnergyLevel(60);
%me.role = %role;
%me.setShapeName(%me.getName() SPC %me.role);
%me.attentionLevel = 0;
%me.nextBlockCheck = 0;
%me.conformToGround = 0;
%me.Equip(Axe01,PlayerBowAmmo);
%me.setMoveSpeed($STATIONARY);
MissionCleanup.add(%me);
AIGroup.add(%me);
echo("Added [" SPC %me SPC "] :" SPC %me.role SPC "#" SPC %me.index );
//%me.setAimLocation( $cardinalDirection[%me.look]);
//%me.getDataBlock().schedule(2000, "doScan", %me);
return %me;
}
function AIPlayer::Equip(%this,%weaponDBName,%ammoDBName)
{
DebugPrint( "%this:"@%this@"~AIPlayer::Equip", Equip);
%weapon = new Item() {
dataBlock = %weaponDBName;
};
// %ammo = new Item() {
// dataBlock = %ammoDBName;
// };
DebugPrint("weapon:"@%weaponDBName, "Equip");
DebugPrint("ammo:"@%ammoDBName, "Equip");
MissionCleanup.add(%weapon);
MissionCleanup.add(%ammo);
%weaponImageName = %weaponDBName @"Image";
%this.mountImage(%weaponImageName,0);
%this.use(%weaponDBName);
}
function CreateBots()
{
new SimSet (AIGroup);
warn("# # # # # # # # # # # # Creating NPC characters # # # # # # # # # # # # ");
if ( (%role=nameToID("MissionGroup/AIDrpPts/Guard")) >= 0 )
{
%count=%role.getCount();
for ( %i = 0; %i < %count; %i++)
{
spawnbot(%i,"Orison Watcher");
}
}
}
function pickAISpawn(%index,%role)
{
%groupName = "MissionGroup/AIDrpPts/Guard";
%group = nameToID(%groupName);
if (%group != -1)
{
%count = %group.getCount();
if (%count != 0)
{
//%index = getRandom(%count-1);
%spawn = %group.getObject(%index);
return getTerrainLevel(%spawn.position,%spawn.radius);
}
else
DebugPrint("No spawn points found in " @ %groupName, "pickAISpawn");
}
else
DebugPrint("Missing spawn points group " @ %groupName, "pickAISpawn");
return %spawn;
}
function getTerrainLevel(%pos,%rad)
{
while(%retries < 500)
{
%x = getWord(%pos, 0) + mFloor(getRandom(%rad * 2) - %rad);
%y = getWord(%pos, 1) + mFloor(getRandom(%rad * 2) - %rad);
%z = getWord(%pos, 2) + mFloor(getRandom(%rad * 2) - %rad);
%start = %x @ " " @ %y @ " 5000";
%end = %x @ " " @ %y @ " -1";
%ground = containerRayCast(%start, %end, $TypeMasks::TerrainObjectType, 0);
%z = getWord(%ground, 3);
error ("Spawn Position : " @ %x SPC %y);
error ("Ground Level : " @ %z);
%z += 3.5;
%position = %x @ " " @ %y @ " " @ %z;
%mask = ($TypeMasks::VehicleObjectType |
$TypeMasks::MoveableObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::ForceFieldObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::ItemObjectType);
if (ContainerBoxEmpty(%mask,%position,3.5))
{
error ("Spawn Position Is Good");
return %position;
}
else
%retries++;
}
return "0 0 300 1 0 0 0";
}
This code should spawn three Guard bots but it only spawns one. I can see where the Guards are being created and there are no errors in the console.
Here is my code...
datablock PlayerData(Watcher : AIElfBody)
{
maxForwardSpeed = 2.2;
maxBackwardSpeed =2.2;
maxSideSpeed = 2;
shootingDelay = 2000;
};
function spawnbot(%index,%role)
{
DebugPrint( "%index:"@%index@"%role:"@%role@"~", spawnbot);
%me = null;
%me = new AIPlayer() {
dataBlock = Watcher;
aiPlayer = true;
};
%me.look = 0;
%me.range = 100;
%spawn=pickAISpawn(%index,%role);
%me.index = %index;
%me.setTransform(%spawn);
%me.setEnergyLevel(60);
%me.role = %role;
%me.setShapeName(%me.getName() SPC %me.role);
%me.attentionLevel = 0;
%me.nextBlockCheck = 0;
%me.conformToGround = 0;
%me.Equip(Axe01,PlayerBowAmmo);
%me.setMoveSpeed($STATIONARY);
MissionCleanup.add(%me);
AIGroup.add(%me);
echo("Added [" SPC %me SPC "] :" SPC %me.role SPC "#" SPC %me.index );
//%me.setAimLocation( $cardinalDirection[%me.look]);
//%me.getDataBlock().schedule(2000, "doScan", %me);
return %me;
}
function AIPlayer::Equip(%this,%weaponDBName,%ammoDBName)
{
DebugPrint( "%this:"@%this@"~AIPlayer::Equip", Equip);
%weapon = new Item() {
dataBlock = %weaponDBName;
};
// %ammo = new Item() {
// dataBlock = %ammoDBName;
// };
DebugPrint("weapon:"@%weaponDBName, "Equip");
DebugPrint("ammo:"@%ammoDBName, "Equip");
MissionCleanup.add(%weapon);
MissionCleanup.add(%ammo);
%weaponImageName = %weaponDBName @"Image";
%this.mountImage(%weaponImageName,0);
%this.use(%weaponDBName);
}
function CreateBots()
{
new SimSet (AIGroup);
warn("# # # # # # # # # # # # Creating NPC characters # # # # # # # # # # # # ");
if ( (%role=nameToID("MissionGroup/AIDrpPts/Guard")) >= 0 )
{
%count=%role.getCount();
for ( %i = 0; %i < %count; %i++)
{
spawnbot(%i,"Orison Watcher");
}
}
}
function pickAISpawn(%index,%role)
{
%groupName = "MissionGroup/AIDrpPts/Guard";
%group = nameToID(%groupName);
if (%group != -1)
{
%count = %group.getCount();
if (%count != 0)
{
//%index = getRandom(%count-1);
%spawn = %group.getObject(%index);
return getTerrainLevel(%spawn.position,%spawn.radius);
}
else
DebugPrint("No spawn points found in " @ %groupName, "pickAISpawn");
}
else
DebugPrint("Missing spawn points group " @ %groupName, "pickAISpawn");
return %spawn;
}
function getTerrainLevel(%pos,%rad)
{
while(%retries < 500)
{
%x = getWord(%pos, 0) + mFloor(getRandom(%rad * 2) - %rad);
%y = getWord(%pos, 1) + mFloor(getRandom(%rad * 2) - %rad);
%z = getWord(%pos, 2) + mFloor(getRandom(%rad * 2) - %rad);
%start = %x @ " " @ %y @ " 5000";
%end = %x @ " " @ %y @ " -1";
%ground = containerRayCast(%start, %end, $TypeMasks::TerrainObjectType, 0);
%z = getWord(%ground, 3);
error ("Spawn Position : " @ %x SPC %y);
error ("Ground Level : " @ %z);
%z += 3.5;
%position = %x @ " " @ %y @ " " @ %z;
%mask = ($TypeMasks::VehicleObjectType |
$TypeMasks::MoveableObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::ForceFieldObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::ItemObjectType);
if (ContainerBoxEmpty(%mask,%position,3.5))
{
error ("Spawn Position Is Good");
return %position;
}
else
%retries++;
}
return "0 0 300 1 0 0 0";
}
About the author
#2
{
%count=%role.getCount();
for ( %i = 0; %i < %count; %i++)
{
spawnbot(%i,"Orison Watcher");
}
}
It is supposed to be looping through three spawn spheres and spawning a watcher for each sphere.
03/08/2008 (5:42 pm)
If ( (%role=nameToID("MissionGroup/AIDrpPts/Guard")) >= 0 ){
%count=%role.getCount();
for ( %i = 0; %i < %count; %i++)
{
spawnbot(%i,"Orison Watcher");
}
}
It is supposed to be looping through three spawn spheres and spawning a watcher for each sphere.
#3
I would definitely slap a bunch of echo's of the variables and values in there. I'm sure you'll see the problem.
03/08/2008 (5:49 pm)
IIII seee. I was looking for three of something or the number 3.I would definitely slap a bunch of echo's of the variables and values in there. I'm sure you'll see the problem.
Torque Owner Lee Latham
Default Studio Name