ContextMenu on POL97 (Working!!)

Post your Custom Scripts or Packages.

Moderator: POL Developer

Post Reply
User avatar
Hannibal29
New User
Posts: 6
Joined: Mon Nov 24, 2008 7:08 am
Location: Gravataí - RS - Brazil

ContextMenu on POL97 (Working!!)

Post by Hannibal29 »

Hi guys, this is my first post on the PolServer community.
Sorry by my bad english, i am brazilian and i still learning the english language.
I will post the steps to make contextmenus works on your POL97 shard.

Image

Step 1 - servspecopt.cfg

Code: Select all

UOFeatureEnable=0x28
Step 2 - uopackets.cfg

Code: Select all

Packet 0xBF
{
  Length           variable
  SubCommandOffset 4
  SubCommandLength 1
}  

SubPacket 0xBF     
{
  SubCommandID     0x13
  ReceiveFunction  handlePopups:HandlePopupRequest
}

SubPacket 0xBF
{                     
  SubCommandID     0x15
  ReceiveFunction  handlePopups:HandlePopupResponse
}
Step 3 - handlePopups.src

Code: Select all

use uo;
use polsys;        
                                                
program Install()
  Print("INSTALLING: PopupMenus system handler..");
  return 1;
endprogram
                        
exported function HandlePopupRequest(Who, byref Packet)
  var WhatSerial := Packet.GetInt32(5);
  var WhatObject := SystemFindObjectBySerial(WhatSerial, SYSFIND_SEARCH_OFFLINE_MOBILES);
  // Define the target for the context menu
  if(WhatObject == Who)
    ShowMenuSelf(Who, Packet, WhatSerial);  
  endif
  return 0;                 
endfunction                   

exported function HandlePopupResponse(Who, byref Packet)
  var WhatSerial   := Packet.GetInt32(5);
  var WhatObject   := SystemFindObjectBySerial(WhatSerial, SYSFIND_SEARCH_OFFLINE_MOBILES);
  var ResultPrefix := Packet.GetInt8(9);
  var ResultSuffix := Packet.GetInt8(10);
  case(ResultPrefix)                              
    0x00: ReceiveMenuSelf(Who, WhatObject, ResultSuffix);
  endcase
  return 0;
endfunction

function ShowMenuSelf(Who, byref Packet, AboveObject)
  var Menu := CreateNewMenu();
  MenuAddItem(Menu, 0x0001, 6123); 
  SendContextMenu(Who, Menu, AboveObject, Packet);
endfunction 

function ReceiveMenuSelf(Who, Object, Result)
  case(Result)             
    0x01: OpenPaperdoll(Who, Who);
  endcase          
endfunction

function CreateNewMenu()  
  return array;     
endfunction      

function MenuAddItem(byref Menu, Result, Text, Flags := 0x20, Color := 0xFFFF)
  Menu.append({Result, Text, Flags, Color}); 
endfunction  

function SendContextMenu(Who, byref Menu, AboveObject, byref Packet)
  if(!Len(Menu))
    return;                
  endif
  Packet.SetSize(12 + (Len(Menu) * 8));
  Packet.SetInt16(03, 0x14);
  Packet.SetInt8(05, 0x00);
  Packet.SetInt8(06, 0x01);
  Packet.SetInt32(07, AboveObject); 
  Packet.SetInt8(11, Len(Menu));
  var Index := 12;
  foreach Item in Menu                                    
    Packet.SetInt16(Index, Item[1]);
    Index := Index + 2;             
    Packet.SetInt16(Index, Item[2]);
    Index := Index + 2;               
    Packet.SetInt16(Index, Item[3]);
    Index := Index + 2;             
    Packet.SetInt16(Index, Item[4]);
    Index := Index + 2;             
  endforeach
  Packet.SendPacket(Who);
endfunction
This is my first work with packets :)
I spend many hours to make this pkg works!!
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: ContextMenu on POL97 (Working!!)

Post by *Edwards »

Welcome :)
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: ContextMenu on POL97 (Working!!)

Post by Austin »

Awesome!
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: ContextMenu on POL97 (Working!!)

Post by Yukiko »

Very nice!
And we are truly happy you've joined the POL Community.
Luth
Former Developer
Posts: 200
Joined: Mon Jan 30, 2006 8:10 am

Re: ContextMenu on POL97 (Working!!)

Post by Luth »

Great work. I was able to integrate this into my game pretty easily. Much obliged! :D

I've attached my implementation of the ContextMenu system here. The CMR numbers are indexes into cliloc.enu at offset 3000000 + CMR. So CMR 6122 will display cliloc index 6122, or "Open".
Attachments
contextMenus.zip
(1.72 KiB) Downloaded 394 times
User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Re: ContextMenu on POL97 (Working!!)

Post by OldnGrey »

Hmm.
When I use this I get the menus appearing over the top of the name of the npc.
The screencap in the first post in this topic shows the name in yellow NEXT to the popupmenus.
On mine they are printed over the top of each other.

The curious thing is that if I click on the npc a second time they appear next to each other as they should.

Turning off the megacliloc makes no difference.

Client 5.0.9.1, core 097.3, UOFeatureEnable=0x1a8
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: ContextMenu on POL97 (Working!!)

Post by Yukiko »

Reviving an old thread here.
I get a server crash at character log-in with this package enabled. I'll have to build a debug version of the Core and submit the mini-dump file I guess to get more help.
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: ContextMenu on POL97 (Working!!)

Post by Yukiko »

Well, I think I fixed my problem. I had put uopacket.cfg in the config folder for the contextmenu phg and was getting the crash. I moved it out of the config folder into contextmenu proper and didn't get a crash...yet. So I guess uopacket.cfg is like pkg.cfg. It needs to be in the main folder for the package. Good to know.
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: ContextMenu on POL97 (Working!!)

Post by Yukiko »

Nope. Not fixed. I had disabled the pkg temporarily and forgot about it. Still getting crash on character login.
Post Reply