AIPlayer mountImage problem

There are no stupid questions, just stupid answers.
6 posts Page 1 of 1
Code_Man
Posts: 55
Joined: Fri Jan 26, 2018 9:12 pm
by Code_Man » Sat Aug 25, 2018 2:06 pm
I cant get a bot to have a weapon, i tried in 3.10.1 and git development.

Following code is what i tried, according to the docs its all in order.

Code: Select all

function addBot() { %name = ""; %spawnPoint = pickPlayerSpawnPoint("BotDropPoints"); %bot = AIPlayer::spawnAtLocation(%name, %spawnPoint.getTransform()); %bot.clearWeaponCycle(); %bot.setInventory(Ryder, 1); %bot.setInventory(RyderClip, %bot.maxInventory(RyderClip)); %bot.setInventory(RyderAmmo, %bot.maxInventory(RyderAmmo)); // Start the gun loaded %bot.addToWeaponCycle(Ryder); %bot.mountImage(Ryder, 0); return %bot; }
Did i do something wrong or is the engine bugged?
Duion
Posts: 1132
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Sun Aug 26, 2018 12:12 pm
No idea what you are doing, but I have it working, feel free to spy on my code. Be aware that I use a new loadout and weapon selection system so there might be a whole lot of more code.
Steve_Yorkshire
Posts: 299
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Mon Aug 27, 2018 2:07 am
"Ryder" is the item class. Look in the datablock:
%bot.mountImage(RyderWeaponImage);
or
%bot.mountImage(Ryder.image);
Try these.
fLUnKnhaXYU
Posts: 53
Joined: Wed Nov 15, 2017 8:19 am
by fLUnKnhaXYU » Mon Aug 27, 2018 7:10 am
//Its been a while since i did this with TGE but , this might help you to understand .
//I am assuming the BOT uses the default player datablock . 
//
//in the file ./scripts /server/item.CS
//
//look at the function
//ItemData::createItem(%data)
//{
//   %obj = new Item()
//
//   {
//      dataBlock = %data;
//      static = true;
//      rotate = true;
//   };
//
//echo(ITEM/WEAPON CREATED = " @ %obj);//check the console for this message and you'll get the
//                                       //item ID .The Image ID >might< be this number + 1 as it it 
//                                       //was with TGE , but I havent tried it recently .
//   return %obj;
//}
//
//=====================================================
//
//in the file
//./scripts/server/player.CS
//
//
//look at the function 
//
//Player::use(%player, %data)
//{
//   // No mounting/using weapons when you're driving!
//   if (%player.isPilot())
//      return(false);
//
//   Parent::use(%player, %data);     //this data should be the ID of the item , dont remember , might be the image ID , or "name" 
//
//}
//
//=====================================================
//
//look at these files
//./scripts/server/weapon.CS and read the function weapon::onUse 
//./scripts /server/inventory.CS shows lots more about the use methodology . if you will .
//
//LONG story short , you might need to use the "use" method to make it happen .
//%obj.use(BOT ID , DATA ID ) . 
//
//
//======================================================
//!!!! check this out !!!!
//The thing to think about here is you'll need a path for the aiPlayer to follow .
//
//./scripts/server/AiPlayer.CS
//
//function AIPlayer::spawn(%path)//------------------------------this path is an ID number or "NAME" <-strings are quoted
//{
//   %player = AIPlayer::spawnOnPath("Shootme", %path);
//
//   if (isObject(%player))
//   {
//      %player.followPath(%path, -1);// ------------------1 will cause the BOT to follow the path in a continous loop , otherwise use the number where you want the bot to stop .
//
//      // slow this sucker down, I'm tired of chasing him!
//      %player.setMoveSpeed(0.5);
//
//      //%player.mountImage(xxxImage, 0);      //------------------------You should find this most interesting
//      //%player.setInventory(xxxAmmo, 1000);  //------------------------
//      //%player.think();                   
//
//      return %player;
//   }
//   else
//      return 0;
//}
//
//=========================================================
//
//So , Im really vague on this , Im a beginner with T3D as well , hope you can use something here . I could not find an addbot function .
Steve_Yorkshire
Posts: 299
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Mon Aug 27, 2018 2:08 pm
Items are for picking up and adding to the inventory. WeaponImage is a is the actual weapon that the player holds.
If you're using the stock player datablock for your AIPlayer then you can mount weapons and add items to the inventory in the same way the default player does. Check scripts/server/gameCore.cs gameCore::Loadout function for more info.
function GameCore::loadOut(%game, %player)
{
   //echo (%game @"\c4 -> "@ %game.class @" -> GameCore::loadOut");

   %player.clearWeaponCycle();
   
   %player.setInventory(Ryder, 1);
   %player.setInventory(RyderClip, %player.maxInventory(RyderClip));
   %player.setInventory(RyderAmmo, %player.maxInventory(RyderAmmo));    // Start the gun loaded
   %player.addToWeaponCycle(Ryder);

   %player.setInventory(Lurker, 1);
   %player.setInventory(LurkerClip, %player.maxInventory(LurkerClip));
   %player.setInventory(LurkerAmmo, %player.maxInventory(LurkerAmmo));  // Start the gun loaded
   %player.addToWeaponCycle(Lurker);

   %player.setInventory(LurkerGrenadeLauncher, 1);
   %player.setInventory(LurkerGrenadeAmmo, %player.maxInventory(LurkerGrenadeAmmo));
   %player.addToWeaponCycle(LurkerGrenadeLauncher);

   %player.setInventory(ProxMine, %player.maxInventory(ProxMine));
   %player.addToWeaponCycle(ProxMine);

   %player.setInventory(DeployableTurret, %player.maxInventory(DeployableTurret));
   %player.addToWeaponCycle(DeployableTurret);
   
   if (%player.getDatablock().mainWeapon.image !$= "")
   {
      %player.mountImage(%player.getDatablock().mainWeapon.image, 0);
   }
   else
   {
      %player.mountImage(Ryder, 0);
   }
}
Now the above script adds maximum values of all available items that the player datablock can carry. Note, that to be able to pick up an item, that item must have an inventory value in the player datablock. AIPlayer does not have "WeaponCycles" as that part of the player's input for selecting which weaponImage to mount.

The loadout chooses which item is the mainWeapon in the player's datablock and gets the .image of that item and mounts it to the player as a weaponImage.

For an AIPlayer try calling this function after the AIPlayer has spawned:
function AIPlayer::loadOutBot(%player)
{
   %player.setInventory(Ryder, 1);
   %player.setInventory(RyderClip, %player.maxInventory(RyderClip));
   %player.setInventory(RyderAmmo, %player.maxInventory(RyderAmmo));    // Start the gun loaded

   %player.setInventory(Lurker, 1);
   %player.setInventory(LurkerClip, %player.maxInventory(LurkerClip));
   %player.setInventory(LurkerAmmo, %player.maxInventory(LurkerAmmo));  // Start the gun loaded

   %player.setInventory(LurkerGrenadeLauncher, 1);
   %player.setInventory(LurkerGrenadeAmmo, %player.maxInventory(LurkerGrenadeAmmo));
   
   if (%player.getDatablock().mainWeapon.image !$= "")
   {
      %player.mountImage(%player.getDatablock().mainWeapon.image, 0);
   }
   else
   {
      %player.mountImage(Ryder, 0);
   }
}
Code_Man
Posts: 55
Joined: Fri Jan 26, 2018 9:12 pm
by Code_Man » Tue Sep 11, 2018 10:21 am
"Ryder" is the item class. Look in the datablock:
%bot.mountImage(RyderWeaponImage);
or
%bot.mountImage(Ryder.image);
Try these.
Yes that was it, stupid beginner mistake, thanks.
6 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests