npetrovski / l2js-client

JavaScript client for Lineage 2
MIT License
105 stars 34 forks source link

Event NpcHtmlMessage? #18

Closed ghost closed 3 years ago

ghost commented 3 years ago

I did a test here and everything seems to work, following the example until I managed to talk to the NPC and buy the item.

As I need the NpcHtmlMessage package (by the name of the menu I find the action (regex)) I did an event. but he always falls for this event because after buying the item, because the NPC sends the NpcHtmlMessage again. then as it receives the event again it stays in the loop (buying)

.on("LoggedIn").on("NpcInfo").on("NpcHtmlMessage").on("BuyList").

NpcHtmlMessage it returns the html of the npc, very useful, because then I can pass only the name of the menu, and it finds the value I need for the next package.

w3nder commented 3 years ago

NpcInfo only sends you when you enter the server, or when the GM summons an NPC.

Some NPCs also need to wait for the html, otherwise you are kick game when sending the RequestBuyItem before the server sends the html of the NPC

[08/12/2020 22:29:22] DEBUG GameClient Receive [ 'NpcHtmlMessage' ]
[08/12/2020 22:29:22] DEBUG GameClient Sending  [ 'RequestBypassToServer' ]
[08/12/2020 22:29:22] DEBUG GameClient Receive [ 'BuyList' ]
[08/12/2020 22:29:22] DEBUG GameClient Sending  [ 'RequestBuyItem' ]
[08/12/2020 22:29:23] DEBUG GameClient Receive [ 'NpcHtmlMessage' ] // Really, the game sends you the NpcHtmlMessage and as you use the event it will get there again.

With the HTML ID of to prevent it from sending the event again, only in the test here, I can't use the NPC again if for example the SSS ends.

My time is short, I will study a little here and try to help you.

w3nder commented 3 years ago

.on("LoggedIn").on("NpcInfo").on("NpcHtmlMessage").on("BuyList").

l2.on("LoggedIn", () => {l2.CreaturesList.getEntryById(idNpc)} you don't need the npcinfo event for this.

npetrovski commented 3 years ago

Hi @GameZk ,

Yeah, for the moment there is no a separate event for NpcHtmlMessage. You can capture this event by using

.on("PacketReceived", "NpcHtmlMessage", (e) => {
    var packet = e.data.packet; // NpcHtmlMessage packet
});

but the Html is not a public property and you cannot use it right away.

I will add a separate NpcHtmlMessage event over the next version. Stay tuned.

@W3nder Not sure what you suggested last will always work - it depends on the server. CreaturesList array gets filled upon receiving CharInfo, NpcInfo and UserInfo. Apparently in this case @GameZk is looking for an NPC, hence I would suggest you capture the NpcInfo packet in order to trigger your custom logic. aka.:

l2.on("PacketReceived", "NpcInfo", (e) => {
    var npc = l2.CreaturesList.getEntryById(idNpc);
    if (npc) {
       l2.hit(npc); // target
       l2.hit(npc); // talk
      // do some other actions here
    }
});

.on("PacketReceived", "NpcHtmlMessage", (e) => {
    var packet = e.data.packet; // NpcHtmlMessage packet
});
ghost commented 3 years ago

@W3nder

.on("LoggedIn").on("NpcInfo").on("NpcHtmlMessage").on("BuyList").

l2.on("LoggedIn", () => {l2.CreaturesList.getEntryById(idNpc)} you don't need the npcinfo event for this.

Thanks for your help. I had already done it that way, I think the event would be better ..

@npetrovski

Yeah, for the moment there is no a separate event for NpcHtmlMessage. You can capture this event by using

I got it, so I'm going to wait, with today's commit I was able to understand it better.

npetrovski commented 3 years ago

@GameZk Actually no need to wait - I pushed that change along with a new npm version 9 hours before your comment. Just make sure you have updated your project.

ghost commented 3 years ago

@GameZk Actually no need to wait - I pushed that change along with a new npm version 9 hours before your comment. Just make sure you have updated your project.

Oh yes :) I looked at the commits over here, coming home I'm going to test it, it wasn't much different than what I had already done at home.

I had already managed to buy the item from the NPC I think I shouldn't use NpcHtmlMessage because the way I did it, I think it was wrong. why at the end of the purchase the server sends the NpcHtmlMessage again and how do I use this event to get the html and parser to get the value menu_select?ask=-1&reply=6 is to send I did it like this l2.bypassToServer (actionRegex);

Here I buy .on("BuyList", (e: EBuyList) => {l2.buyItem(e.data.listID, 1, 2417, 1);} //This code of mine I had made before its commit.

I'll see if I can get this html from the NPC outside the event. then maybe I can use it without falling into the loop

w3nder commented 3 years ago

@GameZk

I made a condition that starts as false, after making the 2 hits on the NPC

    l2.hit(npc); // target
    l2.hit(npc); // talk
    condition  = true

I set the condition as true and in the NpcHtmlMessage event I change it to false after sending the command.

I can buy once

if(condition ) {
const value = button (e.data.html, "Light Armor"); // get the bypass by the name of the menu
l2.bypassToServer (value);
condition = false
}

It will enter the npcHtmlMessage event again, so the bot will not buy the item again each time you receive an event.

I think this event should be separated or receive the html together when talking to the npc