Radius Search Failing?
by Dreamer · in Torque Game Engine · 05/02/2005 (9:38 am) · 1 replies
I have created a function that will allow a bot who is being attack to yell for help, and if any bots are within a specific radius, they will come and jump in on the action.
Here is the relevant bits of code.
Near as I can tell there is no reason for the code above to fail unless there are no PlayerObjectType objects within the specified radius... But I'm getting failures even with a radius of 5000. I have 20 bots each is spawning in a standard playerspawn location in stronghold. Theoretically, when I attack any one bot, every bot in a 5000 unit radius should come running, but they don't instead I keep seeing this in my console.log
This is driving me batty, it looks like it may be a typemask problem, but if it is then I don't know what else to use.
Here is my AI creation function
Well any help would be appreciated, thanx!
Here is the relevant bits of code.
function DoRadiusSearch(%client,%distance,%searchMasks,%AI){
if(%AI){
%player = %client;
}else{
%player = %client.player;
}
%pos = %player.getPosition();
InitContainerRadiusSearch(%pos, %radius, %searchMasks);
while ((%targetObject = containerSearchNext()) != 0) {
%dist = containerSearchCurrRadiusDist();
%target = %targetObject.getTransform();
%id = %targetObject.getId();
%name = %targetObject.getName();
echo( "\c3 /// Container Search /// " );
echo( " Distans = " @ %dist);
echo( " Player Position = " @ %pos);
echo( " Target = " SPC %target);
echo( " Target Id = " SPC %id);
echo( " Target Name = " SPC %name);
echo( "\c3 /// --------------- /// " );
%radiusObjectVector = %radiusObjectVector SPC %targetObject;
}
if(%radiusObjectVector){
return(%radiusObjectVector);
}else{
return(0);
}
}
//This function allows a shout for help to be made which will call the closest NPC within a given radius to help.
function ShoutForHelp(%client,%targetObject,%radius){
%searchMasks = $TypeMasks::PlayerObjectType;
%AI = 1;
%radiusObjectVector = DoRadiusSearch(%client,%radius,%searchMasks,%AI);
while (getWord(%radiusObjectVector, %i) !$= "")
{
%helper = getWord(%radiusObjectVector, %i);
if(%help !$= 0)
if(%helper.getClassName() $="AIPlayer"){
%helper.setSelectedObject(%targetObject);
echo(%helper.getShapeName()@" is on the way to help");
schedule(500,%targetObject,ServerCmdAutoAttack,%helper);
}
%i ++;
}
}Near as I can tell there is no reason for the code above to fail unless there are no PlayerObjectType objects within the specified radius... But I'm getting failures even with a radius of 5000. I have 20 bots each is spawning in a standard playerspawn location in stronghold. Theoretically, when I attack any one bot, every bot in a 5000 unit radius should come running, but they don't instead I keep seeing this in my console.log
Quote:
Entering ShoutForHelp(1144, 1141, 5000)
Entering DoRadiusSearch(1144, 5000, 16384, 1)
Leaving DoRadiusSearch() - return 0
Dream.game/server/scripts/commands.cs (505): Unable to find object: '0' attempting to call function 'getClassName'
Leaving ShoutForHelp() - return
This is driving me batty, it looks like it may be a typemask problem, but if it is then I don't know what else to use.
Here is my AI creation function
// Start the AIManager
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
//AIManager.think();
for(%x=0; %x <=10; %x++){
schedule(1000 * (%x * 10),0,"MakeAI");
}
function MakeAI(){
$x++;
%aiPlayer = AIPlayer::Spawn(%x,pickspawnpoint(),"aiOrc");
//%aiPlayer.maxInv[Sword] = 1;
%aiPlayer.setInventory(Sword,1);
//%aiplayer.setInventory(CrossbowAmmo,10);
%aiPlayer.mountImage(SwordImage,0);
}Well any help would be appreciated, thanx!
Torque Owner Dreamer
Default Studio Name
//This function allows a shout for help to be made which will call the closest NPC within a given radius to help. function ShoutForHelp(%client,%targetObject,%radius){ %searchMasks = $TypeMasks::PlayerObjectType; %AI = 1; %radiusObjectVector = DoRadiusSearch(%client,%radius,%searchMasks,%AI); %i =1; while (getWord(%radiusObjectVector, %i) !$= "") { %helper = getWord(%radiusObjectVector, %i); if(%helper.getClassName() $="AIPlayer"){ if(%helper.getAimObject() != %targetObject){ %helper.setAimObject(%targetObject); echo(%helper.getShapeName()@" is on the way to help"); schedule(2000,%targetObject,ServerCmdAutoAttack,%helper); } }else{ echo(%help@" cannot help because he is an"@%helper.getClassName()); } %i++; } echo("%radiusObjectVector ="@%radiusObjectVector); echo("%helper = "@%helper); }