Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

ContextMenu without SetContextMenuHook

Ask for help
Post Reply
Oct
Posts: 3
Joined: 13.01.2017 9:10

ContextMenu without SetContextMenuHook

Post by Oct »

On my shard we have a NPC that has a random ContextMenu (random Entries, random Positions).
I get the "bad" context-Menu in 50% of the time. Clicking "Crime and Punishment" will send my char to Jail.
  • Good:

    Code: Select all

    ContexMenu! MenuID $0002AF30 EntriesNumber: 04
    Entry0: Tag $0000 Flags: 0000 Text: Open Paperdoll
    Entry1: Tag $0001 Flags: 0000 Text: Quest Conversation
    Entry2: Tag $0002 Flags: 0000 Text: Buy
    Entry3: Tag $0003 Flags: 0000 Text: Sell
  • Good:

    Code: Select all

    ContexMenu! MenuID $0002AF30 EntriesNumber: 04
    Entry0: Tag $0000 Flags: 0000 Text: Open Paperdoll
    Entry1: Tag $0001 Flags: 0000 Text: Buy
    Entry2: Tag $0002 Flags: 0000 Text: Quest Conversation
    Entry3: Tag $0003 Flags: 0000 Text: Sell
  • Bad:

    Code: Select all

    ContexMenu! MenuID $0002AF30 EntriesNumber: 04
    Entry0: Tag $0000 Flags: 0000 Text: Open Paperdoll
    Entry1: Tag $0001 Flags: 0000 Text: Crime and Punishment
    Entry2: Tag $0002 Flags: 0000 Text: Buy
    Entry3: Tag $0003 Flags: 0000 Text: Sell
  • Bad:

    Code: Select all

    ContexMenu! MenuID $0002AF30 EntriesNumber: 04
    Entry0: Tag $0000 Flags: 0000 Text: Crime and Punishment
    Entry1: Tag $0001 Flags: 0000 Text: Open Paperdoll
    Entry2: Tag $0002 Flags: 0000 Text: Buy
    Entry3: Tag $0003 Flags: 0000 Text: Sell
How do I click "Quest Conversation" without re-opening the ContextMenu?
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: ContextMenu without SetContextMenuHook

Post by drabadan »

Oct wrote:On my shard we have a NPC that has a random ContextMenu (random Entries, random Positions).
I get the "bad" context-Menu in 50% of the time. Clicking "Crime and Punishment" will send my char to Jail.
How do I click "Quest Conversation" without re-opening the ContextMenu?
Hi! You should dynamically handle that, so the algorithm should be like:

Code: Select all

ClearContextMenu;
RequestContextMenu(VendorID : Cardinal);
GetContextMenu(var list : TStringList);

for i := 0 to list.Count-1 do
  if Pos('HERE WRITE WHAT YOU WANT, like Buy', list[i]) then
    begin
      SetContextMenuHook(VendorID : Cardinal; i);
      Break; 
    end;
i wrote the algotihm not the exact so code, so you should edit it before with all your values.
Oct
Posts: 3
Joined: 13.01.2017 9:10

Re: ContextMenu without SetContextMenuHook

Post by Oct »

Code: Select all

ClearContextMenu;
RequestContextMenu(VendorID : Cardinal);
GetContextMenu(var list : TStringList);

for i := 0 to list.Count-1 do
  if Pos('Quest Conversation', list[i]) then
    begin
      SetContextMenuHook(VendorID : Cardinal; i);
      Break;
    end;
"SetContextMenuHook" requests a new Context-Menu. The Entries in this (new) ContextMenu aren't the same as in the one before.
As You can see in my examples, this would sometimes let me activate "Crime and Punishment" by chance.

That's because all the above-mentioned ContextMenues where generated by 1 Vendor.
drabadan
Expert
Expert
Posts: 730
Joined: 13.12.2012 17:35
Contact:

Re: ContextMenu without SetContextMenuHook

Post by drabadan »

Oct wrote:

Code: Select all

ClearContextMenu;
RequestContextMenu(VendorID : Cardinal);
GetContextMenu(var list : TStringList);

for i := 0 to list.Count-1 do
  if Pos('Quest Conversation', list[i]) then
    begin
      SetContextMenuHook(VendorID : Cardinal; i);
      Break;
    end;
"SetContextMenuHook" requests a new Context-Menu. The Entries in this (new) ContextMenu aren't the same as in the one before.
As You can see in my examples, this would sometimes let me activate "Crime and Punishment" by chance.

That's because all the above-mentioned ContextMenues where generated by 1 Vendor.
if so - developer should add a command that not makes hook but sends context menu answer solo.
User avatar
Vizit0r
Developer
Developer
Posts: 3958
Joined: 24.03.2005 17:05
Contact:

Re: ContextMenu without SetContextMenuHook

Post by Vizit0r »

Oct wrote:"SetContextMenuHook" requests a new Context-Menu.
negative, it's hook for future incoming menu, and for pending menu as well.
"Пишите код так, как будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете". (с) Макконнелл, "Совершенный код".
Oct
Posts: 3
Joined: 13.01.2017 9:10

Re: ContextMenu without SetContextMenuHook

Post by Oct »

I found my error:
SetContextMenuHook(ID, EntryNumber) has to be SetContextMenuHook(ID, EntryNumber + 1)

To activate Entry0 you have to do SetContextMenuHook(ID, 1)...
A simple index offset :oops:
Post Reply