Jump to content

Playerbot (archive)


Recommended Posts

I am at present looking at Tasssadar's Vehicle branch and looking to see if there is a worhty way of updating it... really dont feel like doing it at the moment though.

I am thinking I could attempt to rebase vehicles and go through the long ardorous merge process and HOPE it works out in the end.. or I can annoy Wojita to get it fixed... currently the bulk of my energy is focused on the latter but I *am* dabbling between bong hits *loL*

Link to comment
Share on other sites

  • Replies 1.8k
  • Created
  • Last Reply

Top Posters In This Topic

Just FYI. I have started to look at getting the bot to interact with NPCs better. I will start with vendors so it can buy and sell items, potentially giving an instruction to sell junk automatically and repair automatically. The next step will be to buy items and finally to train individual or all spells.

Firstly does anyone have any issue with this, or has anyone already started looking at it? Secondly, does anyone know (from memory) how to establish the location of an NPC/Creature so I can get the bot to walk towards it? I was thinking of getting the bot to target the NPC and if it is within a certain distance to move there. The trouble is how do I convert an name supplied on whisper to an NPC? There seems to be some position data on the creature struct which I thought I might be able to use.

Link to comment
Share on other sites

Just FYI. I have started to look at getting the bot to interact with NPCs better. I will start with vendors so it can buy and sell items, potentially giving an instruction to sell junk automatically and repair automatically. The next step will be to buy items and finally to train individual or all spells.

Firstly does anyone have any issue with this, or has anyone already started looking at it? Secondly, does anyone know (from memory) how to establish the location of an NPC/Creature so I can get the bot to walk towards it? I was thinking of getting the bot to target the NPC and if it is within a certain distance to move there. The trouble is how do I convert an name supplied on whisper to an NPC? There seems to be some position data on the creature struct which I thought I might be able to use.

Hi klunk,

Sound like a good project. To locate and NPC such as a vendor. Do a database query on the WorldDatabase. Query the 'entry' field from the 'creature_template' table and cross reference this with the 'id' field from the 'creature' table. The 'creature' table then contains the x, y, z map locations for this NPC. The 'creature_template' table also contains the 'name' of the NPC.

Hope this helps

Link to comment
Share on other sites

this may have been asked already, or unreasonable, but would it be possible fpr a player to 'become the bot' and have the original char line up as a bot itself, somewhat of posession from one to the other?

I read that idea somewhere but no one really commented on it.

klunk that sounds like a great addition if you can pull it off.

blueboy, bizkut and I are going to port your code to evo-X-Core and see how it does over there as well, bizkut has already ported mangchat to evo-x-core

Link to comment
Share on other sites

this may have been asked already, or unreasonable, but would it be possible fpr a player to 'become the bot' and have the original char line up as a bot itself, somewhat of posession from one to the other?

I am not sure that will be possible, I think that will probably require a change in the client.

Link to comment
Share on other sites

Does anyone have a routine that gets a Creature object from a guid?

I am trying to write a routine that will buy from an NPC, I can get the bot to accept the message and I am trying to run :

       Creature* const creature = fromPlayer.GetNPCIfCanInteractWith(playerSelection, TYPEMASK_UNIT);

I have also tried using a pointer m_bot instead of fromPlayer, the method gets called correctly once and I step over the next line, only to jump back to the line above when I continue. I dont understand why it is doing that, I can only presume it is a threading issue of some sort.

Link to comment
Share on other sites

Does anyone have a routine that gets a Creature object from a guid?

I am trying to write a routine that will buy from an NPC, I can get the bot to accept the message and I am trying to run :

       Creature* const creature = fromPlayer.GetNPCIfCanInteractWith(playerSelection, TYPEMASK_UNIT);

I have also tried using a pointer m_bot instead of fromPlayer, the method gets called correctly once and I step over the next line, only to jump back to the line above when I continue. I dont understand why it is doing that, I can only presume it is a threading issue of some sort.

For some reason edit post does not work for me, so here is the code I am trying to add to the HandleCommand method of PlayerbotAI.cpp, anywhere in the if statements to handle the various comands.

    // SJW - Conversation with NPC will go here
   else if ((text == "buy") || (text == "buy ") || (text.size() > 4 && text.substr(0, 4) == "buy "))
   {
       const uint64 playerSelection = fromPlayer.GetSelection( );
          Object* const pNpc = ObjectAccessor::GetObjectByTypeMask(*m_bot, playerSelection, TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
       if (!pNpc)
       {
           SendWhisper ("Selected player is not an NPC I can talk to.", fromPlayer);
           return;
       } 

       Creature* const creature = fromPlayer.GetNPCIfCanInteractWith(playerSelection, TYPEMASK_UNIT);
       if (text == "buy" || text =="buy ") {
           std::ostringstream itemsOut;
           if (!creature) {
               SendWhisper ("Barf.", fromPlayer);
               return;
           }
           const VendorItemData* items = creature->GetVendorItems ();
           if (items->Empty()) {
               SendWhisper("This vendor does not have items I can buy.", fromPlayer);
           }
           uint64 index = 0;
           for (index = 0; index < items->GetItemCount ();++index) {
               const VendorItem* item = items->GetItem(index);
               itemsOut << item->item << "|r";
           }
           ChatHandler ch(&fromPlayer);
           SendWhisper("Here are the items I can buy", fromPlayer);
           ch.SendSysMessage(itemsOut.str().c_str());
//            SendWhisper("Buying!!!", fromPlayer);
       }
       SendWhisper("I dont know how to do that yet!!!", fromPlayer);
   }

Link to comment
Share on other sites

I am not sure that will be possible, I think that will probably require a change in the client.

ok that is understandable, what about something similar to 'use actionbar1' to make him use what ever is bound to the '1' key from that char?

also along the lines of your buying function, could it be possible to make the bot become a vendor and allow me, or others, to purchase items from its inv?

p.s.

also if someone whispers a bot could the whisper be routed to me..

and i could do something like,,

[bot] whispers: billy said:gief gols!!!

/w (bot) say lol wth?

[bot] says: lol wth?

Link to comment
Share on other sites

ok that is understandable, what about something similar to 'use actionbar1' to make him use what ever is bound to the '1' key from that char?

also along the lines of your buying function, could it be possible to make the bot become a vendor and allow me, or others, to purchase items from its inv?

p.s.

also if someone whispers a bot could the whisper be routed to me..

and i could do something like,,

[bot] whispers: billy said:gief gols!!!

/w (bot) say lol wth?

[bot] says: lol wth?

You could achieve the action bar effect with macros saying /w bot cast x or /w bot use x and binding them to your keys

Link to comment
Share on other sites

Hi klunk,

I have copied the block of code, and will try it on my server. I find it better to see the issue first hand. Are you getting a real GUID value for 'playerSelection'? I presume you do, otherwise you would never get a 'pNpc', and it would exit in the

 if (!pNpc)
       {
           SendWhisper ("Selected player is not an NPC I can talk to.", fromPlayer);
           return;
       } 

each time. I'll get back to you.

Link to comment
Share on other sites

For some reason edit post does not work for me, so here is the code I am trying to add to the HandleCommand method of PlayerbotAI.cpp, anywhere in the if statements to handle the various comands.

    // SJW - Conversation with NPC will go here
   else if ((text == "buy") || (text == "buy ") || (text.size() > 4 && text.substr(0, 4) == "buy "))
   {
       const uint64 playerSelection = fromPlayer.GetSelection( );
          Object* const pNpc = ObjectAccessor::GetObjectByTypeMask(*m_bot, playerSelection, TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
       if (!pNpc)
       {
           SendWhisper ("Selected player is not an NPC I can talk to.", fromPlayer);
           return;
       } 

       Creature* const creature = fromPlayer.GetNPCIfCanInteractWith(playerSelection, TYPEMASK_UNIT);
       if (text == "buy" || text =="buy ") {
           std::ostringstream itemsOut;
           if (!creature) {
               SendWhisper ("Barf.", fromPlayer);
               return;
           }
           const VendorItemData* items = creature->GetVendorItems ();
           if (items->Empty()) {
               SendWhisper("This vendor does not have items I can buy.", fromPlayer);
           }
           uint64 index = 0;
           for (index = 0; index < items->GetItemCount ();++index) {
               const VendorItem* item = items->GetItem(index);
               itemsOut << item->item << "|r";
           }
           ChatHandler ch(&fromPlayer);
           SendWhisper("Here are the items I can buy", fromPlayer);
           ch.SendSysMessage(itemsOut.str().c_str());
//            SendWhisper("Buying!!!", fromPlayer);
       }
       SendWhisper("I dont know how to do that yet!!!", fromPlayer);
   }

Hi klunk,

I got it working with a little adjustment. If the player selects a valid Vendor, and you type

/p buy

the bots will all list items they can buy, if not, they will whisper 'Barf'.

  else if ((text == "buy") || (text == "buy ") || (text.size() > 4 && text.substr(0, 4) == "buy "))
   {
       const uint64 playerSelection = fromPlayer.GetSelection( );
       Object* const pNpc = ObjectAccessor::GetObjectByTypeMask(*m_bot, playerSelection, TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
       if (!pNpc)
       {
           SendWhisper ("Selected player is not an NPC I can talk to.", fromPlayer);
           return;
       } 
       Creature *creature = GetPlayer()->GetNPCIfCanInteractWith(playerSelection, UNIT_NPC_FLAG_VENDOR);
       // Changed from TYPEMASK_UNIT
       sLog.outDebug("[PlayerbotAI] pNpc TypeId %u", pNpc->GetTypeId()); // TypeID from Object.h
       sLog.outDebug("[PlayerbotAI] playerSelection is (GUID:%u)",uint32(GUID_LOPART(playerSelection))); 
       // 'guid' from 'creature' table. Then use 'id' to find 'entry' in 'creature_template' table

       if (text == "buy" || text =="buy ") {
           std::ostringstream itemsOut;
           if (!creature) {
               SendWhisper ("Barf.", fromPlayer);
               return;
           }
           const VendorItemData* items = creature->GetVendorItems ();
           if (items->Empty()) {
               SendWhisper("This vendor does not have items I can buy.", fromPlayer);
           }
           uint64 index = 0;
           for (index = 0; index < items->GetItemCount ();++index) {
               const VendorItem* item = items->GetItem(index);
               itemsOut << item->item << "|r";
           }
           ChatHandler ch(&fromPlayer);
           SendWhisper("Here are the items I can buy", fromPlayer);
           ch.SendSysMessage(itemsOut.str().c_str());
//          SendWhisper("Buying!!!", fromPlayer);
       }
       SendWhisper("I dont know how to do that yet!!!", fromPlayer);
   }

Hope this helps

Link to comment
Share on other sites

Blueboy, I dunno how to put this to ya.....but as of 10:45pm my time I put together a whole new MaNGOS repo with in order, ahbot, Dual Spec, Valhalla, playerbot, then cleaned only 4 files and it compiled with no problem! I've got the new core up and online now but I'm going to test tomorrow. I can only figure with the new commits from the core over the last 2 days it fixed whatever was causing the incompatibility because just before wojta fixed his repo I got a clean build with out playerbot, but after he/she fixed Valhalla I was able to get a clean build with playerbot, you go figure it out...I'm too dang tired tonight. So the end result is I got a fully updated core with everything I want in it finally and all I can say is....about time I got it right!

Link to comment
Share on other sites

Blueboy, I dunno how to put this to ya.....but as of 10:45pm my time I put together a whole new MaNGOS repo with in order, ahbot, Dual Spec, Valhalla, playerbot, then cleaned only 4 files and it compiled with no problem! I've got the new core up and online now but I'm going to test tomorrow. I can only figure with the new commits from the core over the last 2 days it fixed whatever was causing the incompatibility because just before wojta fixed his repo I got a clean build with out playerbot, but after he/she fixed Valhalla I was able to get a clean build with playerbot, you go figure it out...I'm too dang tired tonight. So the end result is I got a fully updated core with everything I want in it finally and all I can say is....about time I got it right!

Nice one! The development of the 'Valhalla Project' is very fluid at present. One commit its working, the next it is not. I just tried using a patch created from a later release of Valhalla, and the compiler bombed out saying forbidden use of variable name. I then traced this back to the vehicle patch. I might wait awhile before I use it.

Cheers

Link to comment
Share on other sites

Hi klunk,

I got it working with a little adjustment. If the player selects a valid Vendor, and you type

/p buy

the bots will all list items they can buy, if not, they will whisper 'Barf'.

  else if ((text == "buy") || (text == "buy ") || (text.size() > 4 && text.substr(0, 4) == "buy "))
   {
       const uint64 playerSelection = fromPlayer.GetSelection( );
       Object* const pNpc = ObjectAccessor::GetObjectByTypeMask(*m_bot, playerSelection, TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
       if (!pNpc)
       {
           SendWhisper ("Selected player is not an NPC I can talk to.", fromPlayer);
           return;
       } 
       Creature *creature = GetPlayer()->GetNPCIfCanInteractWith(playerSelection, UNIT_NPC_FLAG_VENDOR);
       // Changed from TYPEMASK_UNIT
       sLog.outDebug("[PlayerbotAI] pNpc TypeId %u", pNpc->GetTypeId()); // TypeID from Object.h
       sLog.outDebug("[PlayerbotAI] playerSelection is (GUID:%u)",uint32(GUID_LOPART(playerSelection))); 
       // 'guid' from 'creature' table. Then use 'id' to find 'entry' in 'creature_template' table

       if (text == "buy" || text =="buy ") {
           std::ostringstream itemsOut;
           if (!creature) {
               SendWhisper ("Barf.", fromPlayer);
               return;
           }
           const VendorItemData* items = creature->GetVendorItems ();
           if (items->Empty()) {
               SendWhisper("This vendor does not have items I can buy.", fromPlayer);
           }
           uint64 index = 0;
           for (index = 0; index < items->GetItemCount ();++index) {
               const VendorItem* item = items->GetItem(index);
               itemsOut << item->item << "|r";
           }
           ChatHandler ch(&fromPlayer);
           SendWhisper("Here are the items I can buy", fromPlayer);
           ch.SendSysMessage(itemsOut.str().c_str());
//          SendWhisper("Buying!!!", fromPlayer);
       }
       SendWhisper("I dont know how to do that yet!!!", fromPlayer);
   }

Hope this helps

I will try this tonight, thanks. It looks like you only change the type mask to indicate vendor and added some logging, is that right?

Obviously this is my approach to iterative development, change something and see what result it give, building up over a series of edits to a final solution, hence some unnecessary code in there. One question, did you experience my wired jumping back in the code issue with my original code sample or did it work fine for you?

Do you run this through gdb at all?

Link to comment
Share on other sites

Well Blueboy, I'm still not quite sure that it was totally a problem just in Valhalla because prior to MaNGOS 9200 area I was have a lot of trouble getting Valhalla to even merge to a clean repo then around 9214 it started to clear up, and as of last night everything started to go smother and smother to the point that this morning I did a usual pull on mangos and got 9218 all the way to 9225 with only a minor cleanup in SpellMNGR.cpp then it all compliled normal with the usual warnings about this or that command has been depreciated use bla bla instead...which I think is linked to the ability to compile on other platforms than just my Windows 7...lol.... I'm now checking things out but the other problem I'm having is with the DB's, under UDB only 2 to 3 of the mounts work at all but under YTDB almost all of the mounts work. This is an area that i'm not too sure of since I'm still learning a great deal about the DB's and how they are put together.

Link to comment
Share on other sites

I will try this tonight, thanks. It looks like you only change the type mask to indicate vendor and added some logging, is that right?

Obviously this is my approach to iterative development, change something and see what result it give, building up over a series of edits to a final solution, hence some unnecessary code in there. One question, did you experience my wired jumping back in the code issue with my original code sample or did it work fine for you?

Do you run this through gdb at all?

Hi klunk,

Yes, all I really changed was the flag mentioned. I realise that the block of code was in a prototype stage, no problems. I did experience the jump back effect on one occasion. It only seemed to occur while fromPlayer. was being used to address the GetNPCIfCanInteractWith function (I changed this to GetPlayer()->), although it didn't make much sense.

I did for the sake of testing, I added some additional code (on my server) to list the names and quantities of vendor items. If you would like this, let me know.

No, I don't use gdb, I prefer to add my own flags 'sLog.outDebug' to monitor variables & pointers, in debugging. Thats just my choice!

Cheers

Link to comment
Share on other sites

Well Blueboy, I'm still not quite sure that it was totally a problem just in Valhalla because prior to MaNGOS 9200 area I was have a lot of trouble getting Valhalla to even merge to a clean repo then around 9214 it started to clear up, and as of last night everything started to go smother and smother to the point that this morning I did a usual pull on mangos and got 9218 all the way to 9225 with only a minor cleanup in SpellMNGR.cpp then it all compliled normal with the usual warnings about this or that command has been depreciated use bla bla instead...which I think is linked to the ability to compile on other platforms than just my Windows 7...lol.... I'm now checking things out but the other problem I'm having is with the DB's, under UDB only 2 to 3 of the mounts work at all but under YTDB almost all of the mounts work. This is an area that i'm not too sure of since I'm still learning a great deal about the DB's and how they are put together.

Yeah, I am pleased that the code generally is behaving itself. I'm still waiting for an official DB, that supports 3.3.0 and clear all those nasty warnings, when the database loads. It shouldn't be long...

Cheers

Link to comment
Share on other sites

Hi klunk,

Yes, all I really changed was the flag mentioned. I realise that the block of code was in a prototype stage, no problems. I did experience the jump back effect on one occasion. It only seemed to occur while fromPlayer. was being used to address the GetNPCIfCanInteractWith function (I changed this to GetPlayer()->), although it didn't make much sense.

I did for the sake of testing, I added some additional code (on my server) to list the names and quantities of vendor items. If you would like this, let me know.

No, I don't use gdb, I prefer to add my own flags 'sLog.outDebug' to monitor variables & pointers, in debugging. Thats just my choice!

Cheers

Hi Blueboy

If you have code to translate the item guids to names and quantities I would appreciate that. I will be looking at that this evening, but if i can crib yours I can concentrate on the code to actually make the purchase :)

Thanks

Link to comment
Share on other sites

the problems with mangos and vehicle code constantly being a problem is the main reason i switched to evo-X-Core... vehicles is part of the core build as is ahbot, dual-spec, anticheat, and a bunch more... now that we have successfully merged evochat and the playerbots over to it we (bizkut and I) are going to upkeep both repos on my bahamut repo to keep it up to date there... of course we are giving full original port code credit to blueboy and a token nod to the original creators.

Link to comment
Share on other sites

Hi Blueboy

If you have code to translate the item guids to names and quantities I would appreciate that. I will be looking at that this evening, but if i can crib yours I can concentrate on the code to actually make the purchase :)

Thanks

Here is the code straight from my server,

    else if ((text == "buy") || (text == "buy ") || (text.size() > 4 && text.substr(0, 4) == "buy "))
   {
       const uint64 playerSelection = fromPlayer.GetSelection( );
       Object* const pNpc = ObjectAccessor::GetObjectByTypeMask(*m_bot, playerSelection, TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
       if (!pNpc)
       {
           SendWhisper ("Selected player is not an NPC I can talk to.", fromPlayer);
           return;
       } 
       Creature *creature = GetPlayer()->GetNPCIfCanInteractWith(playerSelection,UNIT_NPC_FLAG_VENDOR);

   // sLog.outDebug("[PlayerbotAI] pNpc TypeId %u", pNpc->GetTypeId());
   // sLog.outDebug("[PlayerbotAI] playerSelection is(GUID:%u)",uint32(GUID_LOPART(playerSelection)));

           std::ostringstream itemsOut;
           if (!creature) {
               SendWhisper ("Barf.", fromPlayer);
               return;
           }
           const VendorItemData* items = creature->GetVendorItems ();
           if (items->Empty()) {
               SendWhisper("This vendor does not have items I can buy.", fromPlayer);
           }
       for (uint64 index = 0; index < items->GetItemCount ();++index) {
               const VendorItem* vItem = items->GetItem(index);
               ItemPrototype const* pItemProto = ObjectMgr::GetItemPrototype(vItem->item);

               std::string itemName = pItemProto->Name1;
               ItemLocalization(itemName, pItemProto->ItemId);

               itemsOut << " |cffffffff|Hitem:" << pItemProto->ItemId
               << ":0:0:0:0:0:0:0" << "|h[" << itemName << "]|h|r";
               if (creature->GetVendorItemCurrentCount(vItem) > 1)
                   itemsOut << "x" << creature->GetVendorItemCurrentCount(vItem) << ' ';

           }
           ChatHandler ch(&fromPlayer);
           SendWhisper("Here are the items I can buy", fromPlayer);
           ch.SendSysMessage(itemsOut.str().c_str());
//          SendWhisper("Buying!!!", fromPlayer);
           SendWhisper("I dont know how to do that yet!!!", fromPlayer);
   }

Some vendors have more than one of an item for sale. A good example is 'Antonio Perelli' the traveling salesman who walks up and down the road just by the Eastvale Logging Camp, in Elwynn Forest. Try it.

Hope this helps

Link to comment
Share on other sites

Here is the code straight from my server,

    else if ((text == "buy") || (text == "buy ") || (text.size() > 4 && text.substr(0, 4) == "buy "))
   {
       const uint64 playerSelection = fromPlayer.GetSelection( );
       Object* const pNpc = ObjectAccessor::GetObjectByTypeMask(*m_bot, playerSelection, TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
       if (!pNpc)
       {
           SendWhisper ("Selected player is not an NPC I can talk to.", fromPlayer);
           return;
       } 
       Creature *creature = GetPlayer()->GetNPCIfCanInteractWith(playerSelection,UNIT_NPC_FLAG_VENDOR);

   // sLog.outDebug("[PlayerbotAI] pNpc TypeId %u", pNpc->GetTypeId());
   // sLog.outDebug("[PlayerbotAI] playerSelection is(GUID:%u)",uint32(GUID_LOPART(playerSelection)));

           std::ostringstream itemsOut;
           if (!creature) {
               SendWhisper ("Barf.", fromPlayer);
               return;
           }
           const VendorItemData* items = creature->GetVendorItems ();
           if (items->Empty()) {
               SendWhisper("This vendor does not have items I can buy.", fromPlayer);
           }
       for (uint64 index = 0; index < items->GetItemCount ();++index) {
               const VendorItem* vItem = items->GetItem(index);
               ItemPrototype const* pItemProto = ObjectMgr::GetItemPrototype(vItem->item);

               std::string itemName = pItemProto->Name1;
               ItemLocalization(itemName, pItemProto->ItemId);

               itemsOut << " |cffffffff|Hitem:" << pItemProto->ItemId
               << ":0:0:0:0:0:0:0" << "|h[" << itemName << "]|h|r";
               if (creature->GetVendorItemCurrentCount(vItem) > 1)
                   itemsOut << "x" << creature->GetVendorItemCurrentCount(vItem) << ' ';

           }
           ChatHandler ch(&fromPlayer);
           SendWhisper("Here are the items I can buy", fromPlayer);
           ch.SendSysMessage(itemsOut.str().c_str());
//          SendWhisper("Buying!!!", fromPlayer);
           SendWhisper("I dont know how to do that yet!!!", fromPlayer);
   }

Some vendors have more than one of an item for sale. A good example is 'Antonio Perelli' the traveling salesman who walks up and down the road just by the Eastvale Logging Camp, in Elwynn Forest. Try it.

Hope this helps

That is so good, thanks. It works a treat. Now to actually purchase the item.

Link to comment
Share on other sites

Me again :)

I am very close to completing the buy side, only problem I have is that the call to BuyItemFromVendor on m_bot is failing and I cant see why at the moment. Once I have buy working I will update my repo and make it available for people to test.

Link to comment
Share on other sites

Blueboy, I do wanna thank you for the hard work , I've just gotten done testing the monster I told you about and it's working as expected, I just whish I knew the command list better but in time that will happen. Next we need better DB's more Scripting and I wann'em now...but I guess I'll just have to wait for them....oh well...

PS...

Just for kick and giggles... I got the monster to run on a little Celeron 2.0 gighz, with 512megs of ram, 10 gig HD, and a WHOPPING 16megs of integrated Intel video chip...(an old HP Pavillion system) and it's handleing a HUGE Population of 50 people!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use