Author Topic: randomMove();  (Read 1191 times)

D= It's not working, it was but now it's just spamming the console with unkown command.

Code: [Select]
function civilianBots(){
if($CivilianSpawn $= ""){ echo("*---Terrorist Pack---* \n No Civilian Spawn \n --------------------"); return; }
deleteBots($CivilianAmount);
for(%i=0;%i<$CivilianAmount;%i++){
echo(%i);
$CivilianBot[%i] = new AIPlayer(){
datablock = playerNoJet;
position = vectorAdd($CivilianSpawn,"0 0 5");
};
%bot = $CivilianBot[%i];
blockhead(%bot);
%bot.setShapeName("Civilian " @ %i); 
if(%i){
%bot.setMoveDestination(vectorAdd($CivilianBot[%i-1].getTransform(),"4 4 0"));
}
schedule(1000,0,"KeepMoving",%bot);
}
}

function KeepMoving(%bot){
if(isObject(%bot)){
%bot.randomMove();
schedule(1000,0,"KeepMoving",%bot);
}
}


Where do you define AIPlayer::randomMove()?

%bot.randomMove();

Random move is already an existing command.


Code: [Select]
blockhead(%bot);
???

It's a function that sets the object to the blockhead apperance that I borrowed from Space's bot code.

I don;t know what I've done because it was working and now randomMove(); seems to of deleted itself from existance.

just get its location(x & y) and set its move destination to
%bot.x+getrand(-25,25),%bot.y+getrand(-25,25),%bot.z
or w/e

From the above idea, some code:

Code: [Select]
function AIPlayer::randomMove(%player)
{
 %loc = vectorAdd(%player.getTransform(),getRandom(-25,25) SPC getRandom(-25,25) SPC 0);
 %player.setMoveDestination(%loc);
 %player.setAimLocation(%loc);
}

Add anywhere in the file. It might mess up other AIPlayer stuff if other bots use it, though...

Thanks Space, that's better than what I had originally, thanks.