mind if I do it?

also, how do I check an AIPlayer's line of sight to its target, and how do I tell it to fire once I have checked it?

[edit]
not real intelligent yet, but thats for tomorrow Wink


Code:
function createFighterBot(%target)
{
   %who = new AIPlayer() {
      dataBlock = LightMaleHumanArmor;
      aiPlayer = true;
   };

   MissionCleanup.add(%who);
   echo("ID :"@%who);
   // Player setup
   %who.setMoveSpeed(1);
   %who.setTransform(pickSpawnPoint());
   %who.setEnergyLevel(60);
   %who.setShapeName(%target.namebase@"'s Evil Twin");
   %who.setSkinName(%target.colorSkin);
   %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(%target.player.getmountedimage(0),$rightHandSlot);
   echo(%who.namebase);
   echo(%target.namebase);
   schedule(1000,0,mybotreaim,%who,%target);
}
function mybotreaim(%who,%target)
{
   
   %who.setAimObject(%target);
   %who.setImageTrigger(0,1);
   
   %targetlocation = %target.player.getTransform();
   %targetx = getWord(%targetlocation, 0);
   %targety = getWord( %targetlocation, 1);
   %targetz = getWord( %targetlocation, 2) + 1;
   %who.setMoveDestination((%targetx - 10)@" "@(%targety - 10)@" "@%targetz);
   %who.setAimLocation(%targetx@" "@%targety@" "@%targetz);
   schedule(1000,0,mybotreaim,%who,%target);
}
LOS is hard to calculate; just make it fire regardless of whether it has the LOS or not. Make the firing condition whether or not it has a target.
you missed my edit. I decided to screw LOS. for some reason it will only take a weapon if its copying someone elses. couldn't get it to use one as a parameter, even with nametoid() so I just had it copy the targets
You're not specifying the wep image name correctly, I believe. Are you sure you passed it a valid parameter, such as 'MissileLauncher'?
[edit]

*smacks self* its supposed to be missilelauncherimage, not missilelauncher. and it seems to torque script is case insensitive
Hmm, I'll have to work on that for a bit tomorrow then and see what I can come up with.
it works great now. the bot is still pretty stupid, but here's the code so far:


Code:
function createFighterBot(%wep,%target)
{
   %who = new AIPlayer() {
      dataBlock = LightMaleHumanArmor;
      aiPlayer = true;
   };

   MissionCleanup.add(%who);
   echo("ID :"@%who);
   // Player setup
   %who.setMoveSpeed(1);
   %who.setTransform(pickSpawnPoint());
   %who.setEnergyLevel(60);
   %who.setShapeName(%target.namebase@"'s Evil Twin");
   %who.setSkinName(%target.colorSkin);
   %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);
   echo(%who.namebase);
   echo(%target.namebase);
   schedule(1000,0,mybotreaim,%who,%target);
}
function mybotreaim(%who,%target)
{
   
   %who.setAimObject(%target);
   %who.setImageTrigger(0,1);
   
   %targetlocation = %target.player.getTransform();
   %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(((%whox <= %targetx) ? %targetx - 4 : %targetx + 4)@" "@((%whox <= %targety) ? %targety - 4 : %targety + 4)@" "@%targetz);
   %who.setAimLocation(%targetx@" "@%targety@" "@%targetz);
   if(isobject(%who))
      schedule(1000,0,mybotreaim,%who,%target);
}
Laughing I gave you the wrong wepimage. 0x5.
test it out with acidgunimage Very Happy lol
Wow, nicely done elfprince! I like it.
thanks.

here's a slightly more interesting version, although it still cant handle water. this borrows some of the navigation algorithm from dtb\scripts\server\killbots.cs.


Code:
function createFighterBot(%wep,%target)
{
    %who = new AIPlayer() {
        dataBlock = LightMaleHumanArmor;
        aiPlayer = true;
    };

    MissionCleanup.add(%who);
    echo("ID :"@%who);
    // Player setup
    %who.setMoveSpeed(1);
    %who.setTransform(pickSpawnPoint());
    %who.setEnergyLevel(60);
    %who.setShapeName(%target.namebase@"'s Evil Twin");
    %who.setSkinName(%target.colorSkin);
    %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);
    echo(%who.namebase);
    echo(%target.namebase);
    schedule(1000,0,mybotreaim,%who,%target);
}
function mybotreaim(%who,%target)
{
   
    %who.setAimObject(%target);
    %who.setImageTrigger(0,1);
   
    %targetlocation = %target.player.getTransform();
    %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(((%whox <= %targetx) ? %targetx - 1 : %targetx + 1)@" "@((%whox <= %targety) ? %targety - 1 : %targety + 1)@" "@%targetz);
    %xdiff = mabs(getWord( %target.player.getTransform(), 0 ) - getWord( %who.getTransform(), 0 ));
    %ydiff = mabs(getWord( %target.player.getTransform(), 1 ) - getWord( %who.getTransform(), 1 ));
    %whotol = (%xdiff > %ydiff)? %xdiff/2 : %ydiff/2;
     
    if ( %whoz <  %targetz)
    {
        %who.setimagetrigger(2,1);
        %who.setimagetrigger(4,1);
    } else if ( %targetz + %whotol <  %whoz)
         %who.setMoveSpeed(1);
   else if (%whotol > 20 || %whotol < 5 && ( %targetz <=  %whoz)
    {
      %who.setimagetrigger(2,0);
       %who.setimagetrigger(4,0);
   }
         
   
    %who.setAimLocation(%targetx@" "@%targety@" "@%targetz);
    if(isobject(%who))
        schedule(1000,0,mybotreaim,%who,%target);
}
You might also like this:

Code:
function createFighterArmy(%wep,%target,%number)
{
   createFighterBot(%wep,%target);
   %number--;
   if (%number > 0)
   {
      schedule(2000,0,createFighterArmy,%wep,%target,%number);
   }
}
lol, I was thinking of something like that. Do you know how to make AIPlayers swim?
elfprince13 wrote:
0x5, I was thinking of something like that. Do you know how to make AIPlayers swim?
Nope, but I'm working on it. I'm brainstorming a scoring system and making the bots attack everyone _except_ you instead of only you. Ideas?
check inside a certain radius for players to fire at?
My idea is this. Somehow get them to check through the player list to find the closest player, then fire at that until it dies or the bot dies. Then, when the target disappears, repeat the process. I'm debating whether or not bots should respawn when they're killed...
is there a way to make the bots actually be treated like normal players? sort of a simulated local client connection?

Code:
function serverCmdcFA(%client,%wep,%number)
{
   createFighterArmy(%wep,%client,%number);
}
function createFighterArmy(%wep,%target,%number)
{
   createFighterBot(%wep,%target);
   %number--;
   if (%number > 0)
   {
      schedule(2000,0,createFighterArmy,%wep,%target,%number);
   }
}
function createFighterBot(%wep,%target)
{
    %who = new AIPlayer() {
        dataBlock = LightMaleHumanArmor;
        aiPlayer = true;
    };

    MissionCleanup.add(%who);
    echo("ID :"@%who);
    // Player setup
    %who.setMoveSpeed(1);
    %who.setTransform(pickSpawnPoint());
    %who.setEnergyLevel(60);
    %who.setShapeName(%target.namebase@"'s Evil Twin");
    %who.setSkinName(%target.colorSkin);
    %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);
    echo(%who.namebase);
    echo(%target.namebase);
    schedule(1000,0,mybotreaim,%who,%target);
}
function mybotreaim(%who,%target)
{
   
    %who.setAimObject(%target);
    %who.setImageTrigger(0,1);
   
   if (isobject(%target))
   {
      %targetlocation = %target.player.getTransform();
      %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(((%whox <= %targetx) ? %targetx - 1 : %targetx + 1)@" "@((%whox <= %targety) ? %targety - 1 : %targety + 1)@" "@%targetz);
      %xdiff = mabs(getWord( %target.player.getTransform(), 0 ) - getWord( %who.getTransform(), 0 ));
      %ydiff = mabs(getWord( %target.player.getTransform(), 1 ) - getWord( %who.getTransform(), 1 ));
      %whotol = (%xdiff > %ydiff)? %xdiff/2 : %ydiff/2;
      
      if ( %whoz <  %targetz)
      {
         %who.setimagetrigger(2,1);
         %who.setimagetrigger(4,1);
      } else if ( %targetz + %whotol <  %whoz)
          %who.setMoveSpeed(1);
      else if (%whotol > 20 || %whotol < 5 && ( %targetz <=  %whoz))
      {
        %who.setimagetrigger(2,0);
         %who.setimagetrigger(4,0);
      }
   }
   
    %who.setAimLocation(%targetx@" "@%targety@" "@%targetz);
    if(isobject(%who))
        schedule(1000,0,mybotreaim,%who,%target);
}

Code:
function serverCmdcFA(%client,%wep,%number)
{
   createFighterArmy(%wep,%client,%number);
}
function createFighterArmy(%wep,%target,%number)
{
   createFighterBot(%wep,%target);
   %number--;
   if (%number > 0)
   {
      schedule(2000,0,createFighterArmy,%wep,%target,%number);
   }
}
function createFighterBot(%wep,%target)
{
    %who = new AIPlayer() {
        dataBlock = LightMaleHumanArmor;
        aiPlayer = true;
    };

    MissionCleanup.add(%who);
    echo("ID :"@%who);
    // Player setup
    %who.setMoveSpeed(1);
    %who.setTransform(pickSpawnPoint());
    %who.setEnergyLevel(60);
    %who.setShapeName(%target.namebase@"'s Evil Twin");
    %who.setSkinName(%target.colorSkin);
    %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);
    echo(%who.namebase);
    echo(%target.namebase);
    schedule(1000,0,mybotreaim,%who,%target);
}
function mybotreaim(%who,%target)
{
   
    %who.setAimObject(%target);
    %who.setImageTrigger(0,1);
   
   if (isobject(%target))
   {
      %targetlocation = %target.player.getTransform();
      %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(((%whox <= %targetx) ? %targetx - 1 : %targetx + 1)@" "@((%whox <= %targety) ? %targety - 1 : %targety + 1)@" "@%targetz);
      %xdiff = mabs(getWord( %target.player.getTransform(), 0 ) - getWord( %who.getTransform(), 0 ));
      %ydiff = mabs(getWord( %target.player.getTransform(), 1 ) - getWord( %who.getTransform(), 1 ));
      %whotol = (%xdiff > %ydiff)? %xdiff/2 : %ydiff/2;
      
      if ( %whoz <  %targetz)
      {
         %who.setimagetrigger(2,1);
         %who.setimagetrigger(4,1);
      } else if ( %targetz + %whotol <  %whoz)
          %who.setMoveSpeed(1);
      else if (%whotol > 20 || %whotol < 5 && ( %targetz <=  %whoz))
      {
        %who.setimagetrigger(2,0);
         %who.setimagetrigger(4,0);
      }
   }
   
    %who.setAimLocation(%targetx@" "@%targety@" "@%targetz);
    if(isobject(%who))
        schedule(1000,0,mybotreaim,%who,%target);
}
I think were gonna want to put some sort of permissioning on that to keep it from being abused <_<
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3, 4, 5 ... 10, 11, 12  Next
» View previous topic :: View next topic  
Page 4 of 12
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement