toddw123 / RotMG_Clientless

Compatible with version X16.0.0
MIT License
11 stars 4 forks source link

Trading with bot #43

Closed ashley-dv closed 7 years ago

ashley-dv commented 7 years ago

How do you accept a trade using this bot? I don't need to select anything in the bot's inventory. Every attempt with AcceptTrade packet has resulted in either cancelling the trade instead of accepting or just plain crashing the bot.

Sorry for noob question.

toddw123 commented 7 years ago

Do you know the correct trade protocol? Your accept packet has the correct boolean array's in it?

ashley-dv commented 7 years ago

Trades are accepted as soon as they are requested

As soon as the other player accepts the trade, I want the bot to accept the trade as well. I'm not sure how to go about this, though.

void Client::onTradeAccepted(Packet p) { // This is stuff that doesn't work, at least I tried std::vector MyOffers; MyOffers[1] = false; // End of stuff that is useless... I think? TradeChanged changed; AcceptTrade accept; PlayerText ptext; DebugHelper::print("S -> C: Trade has been accepted"); accept.yourOffer = changed.offer; accept.myOffer = MyOffers; packetio.sendPacket(ptext.write()); packetio.sendPacket(accept.write()); } [Sorry for cancerous formatting.] I think I'm mainly going wrong with accept.myOffer. I'm pretty sure accept.yourOffer is correct. Unless I'm mistaken on that too, if so, I will die

How am I to go about accepting the offer?

toddw123 commented 7 years ago

Yeah your packet data is wrong. Go check some of the k-relay traderbots on mpgh to see how the accept packet is formatted.

I also cant figure out why you created a PlayerText packet and send it, you didnt even fill in any text for it...

ashley-dv commented 7 years ago

The PlayerText thing is to PM me when a trade is completed, I removed the line containing the text because it contained my IGN.

Still can't figure out how to do this. I basically copied this code from PixelZerg's bot. PlayerText ptext; std::vector gettosel; std::list indexestosel; { int lefttofind = 8; for (int i = 4; i < 12; i++) { if (inventory[i] == 0 && lefttofind > 0) { lefttofind--; indexestosel.push_back(i); } } if (lefttofind = 0) { Sleep(1000); } } std::vector lad; for (int i = 4; i != 12; i++) { lad[i] = true; } gettosel = lad; TradeChanged changed; AcceptTrade accept;

DebugHelper::print("S -> C: Trade has been accepted");
ptext.text = "/tell [censored] Trade attempted";
accept.yourOffer = changed.offer;
accept.myOffer = gettosel;
packetio.sendPacket(ptext.write());
packetio.sendPacket(accept.write());

[This is my current onTradeAccepted. And formatting, again.] I am simply too dumb to understand how to do this. This current code gives me the error 'Expression: vector iterator not dereferencable.' And again, I'm trying to not select anything in the trade, although I can't even get code to work when trying to select something.

toddw123 commented 7 years ago

Yeah i have no idea what you are trying to do there in creating the vector. A vector is like an array, except you dont have a preset size, so you cant just jump to the 4th element of nothing.

I honestly have 0 idea what you are doing in your code you just posted, it would help if you formatted it so i can read it easier, but it also doesnt make much sense.

If you arent trading anything from your bot, myOffer has to be 12 "false" elements. You can do something as simple as: for(int i = 0; i < 12; i++) accept.myOffer.push_back(false);

And thats all you need for the myOffer bit.

Assuming the changed.offer value is valid, that should work, but if not just create the yourOffer vector of 12 bools using "false" for not trading the item and "true" for trading the item.

ashley-dv commented 7 years ago

Sure enough, what you did worked. While TradeChanged has the data for the offer and what is selected (I think, at least), it's only sent in the packet.

changed.offer is just the same as accept.yourOffer. It needs to be manually assigned. Of course, I am an idiot, as displayed, so I'll either never find a way to work around manually assigning accept.yourOffer or it'll take a very long time.

toddw123 commented 7 years ago

so I'll either never find a way to work around manually assigning accept.yourOffer or it'll take a very long time.

Using the value from the change trade packet will work. But you cant reference it unless you store that value somewhere in the class. Probably the easiest way to do it would be to go to the Client header file and add something like, TradeChanged lastTradeChange; and then in the handler for TradeChanged just store the packet value this->lastTradeChange = (TradeChanged)p;. Then finally, in your accept handler you can set the yourOffer to accept.yourOffer = this->lastTradeChange.offer;

Doing something like that would work.

Unless you are just saying that you dont know how to assign the acccept.yourOffer without doing something like accept.yourOffer = change.offer;...which that is impossible. You will always have to set the values in the packet since they are all blank when you create it.

toddw123 commented 7 years ago

Closing this issue as it appears to be solved. You can open another issue if you need more assistance.