Author Topic: Context menu handler subs  (Read 1251 times)

0 Members and 1 Guest are viewing this topic.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12912
  • Activity:
    0.6%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1328
  • Referrals: 32
    • View Profile
    • ScriptUO
Context menu handler subs
« on: June 11, 2008, 10:57:41 PM »
0
Here's a set of subs I put together that will search the text of the context popup menu (exevent popup) and select the proper item.  I have searched the land to find most of the context menu entries, but I probably have forgotten a few, so if you find one, let me know and I'll add it to the master list.  This is independent of any OCR program out there, so you won't have any code dependencies.

Note:
You have to run SetupContextValues at the beginning of your scripts execution to setup all the %CONTEXT_XXX.. values.

Also, since this uses pixcol you must keep the screen clear of clutter, otherwise the script will claim it can't find the requested context line.

Here's a bit of test code:
Code: easyuo
  1. gosub SetupContextValues
  2. set #TARGCURS 1
  3. repeat
  4. until #TARGCURS = 0
  5. gosub HandleContextMenu NULL #LTARGETID %CONTEXT_Buy ; "Vender buy!"
  6.  

Also, this has been setup so you may call it as a separate subroutine:
Code: easyuo
  1. set %context_subs c:\context_subs.txt
  2.  
  3. call %context_subs SetupContextValues
  4. call %context_subs HandleContextMenu #CHARID %CONTEXT_Open_Paperdoll
  5.  

Here's the code you'll need to include in your script:

If you add it directly, then you don't need the "gosub %1" and "exit".  Those are there to allow these subs to be "call"ed.
Code: easyuo
  1. gosub %1
  2. exit
  3. ;-------------------------------------------------------------------------------
  4. sub SetupContextValues
  5. ; For #CHARID -------------------------------------------
  6.   set %CONTEXT_Open_Paperdoll 3156756
  7.   set %CONTEXT_Open_Backpack 3428334
  8.   set %CONTEXT_View_Quest_Log 3126406
  9.   set %CONTEXT_Quest_Conversation 3730488
  10.   set %CONTEXT_Cancel_Quest 1535584
  11.   set %CONTEXT_Toggle_Insurance 6427264
  12.   set %CONTEXT_Auto_Renew_Insurance 10565554
  13.   set %CONTEXT_Cancel_Renewing 8578676
  14.   set %CONTEXT_Toggle_Monster_Title_Display 6959492
  15.   set %CONTEXT_Toggle_Quest_Item 3603586
  16.   set %CONTEXT_Leave_House 2202616
  17.   set %CONTEXT_Totals 744812 ; alexandria
  18. ; -------------------------------------------------------
  19. ; Various commands:
  20.   set %CONTEXT_Buy 200250
  21.   set %CONTEXT_Sell 260988
  22.   set %CONTEXT_Open_Bankbox 2793788
  23.   set %CONTEXT_Talk 208296
  24.   set %CONTEXT_Stable_Pet 1059800
  25.   set %CONTEXT_Claim_All_Pets 3073470
  26.   set %CONTEXT_Ask_Destination 4153934
  27.   set %CONTEXT_Accept_Escort 2171844
  28.   set %CONTEXT_Command_Kill 3025036
  29.   set %CONTEXT_Command_Follow 2998872
  30.   set %CONTEXT_Command_Guard 3695576
  31.   set %CONTEXT_Command_Stop 3084560
  32.   set %CONTEXT_Command_Stay 3438018
  33.   set %CONTEXT_Add_Friend 1757318
  34.   set %CONTEXT_Remove_Friend 2870250
  35.   set %CONTEXT_Transfer 593758
  36.   set %CONTEXT_Release 753348
  37.   set %CONTEXT_Tame 2967380
  38.   set %CONTEXT_Hire 271802
  39.   set %CONTEXT_Lock_Karma 1628904
  40.   set %CONTEXT_Tithe_Gold 1504152
  41.   set %CONTEXT_Resurrect 1040922
  42.   set %CONTEXT_Add_To_Spellbook 4435612
  43.  
  44. ; -------------------------------------------------------
  45. ; Training commands:
  46.   set %CONTEXT_Train_Alchemy 2851050
  47.   set %CONTEXT_Train_Anatomy 2802984
  48.   set %CONTEXT_Train_Animal_Taming 4605822
  49.   set %CONTEXT_Train_Animal_Lore 3779370
  50.   set %CONTEXT_Train_Archery 2127964
  51.   set %CONTEXT_Train_Arms_Lore 2746638
  52.   set %CONTEXT_Train_Blacksmithy 5406112
  53.   set %CONTEXT_Train_Bowcraft_Fletching 9229098
  54.   set %CONTEXT_Train_Camping 3103050
  55.   set %CONTEXT_Train_Carpentry 3895634
  56.   set %CONTEXT_Train_Cartography 4174618
  57.   set %CONTEXT_Train_Chivalry 3031212
  58.   set %CONTEXT_Train_Cooking 2505550
  59.   set %CONTEXT_Train_Discordance 4510014
  60.   set %CONTEXT_Train_Evaluating_Intelligence 10255594
  61.   set %CONTEXT_Train_Fencing 2057938
  62.   set %CONTEXT_Train_Fishing 2129530
  63.   set %CONTEXT_Train_Focus 1736784
  64.   set %CONTEXT_Train_Forensic_Evaluation 9881992
  65.   set %CONTEXT_Train_Healing 2330106
  66.   set %CONTEXT_Train_Inscription 2652544
  67.   set %CONTEXT_Train_Item_Identification 10238832
  68.   set %CONTEXT_Train_Lockpicking 3681790
  69.   set %CONTEXT_Train_Lumberjacking 6315420
  70.   set %CONTEXT_Train_Mace_Fighting 5961428
  71.   set %CONTEXT_Train_Magery 2466304
  72.   set %CONTEXT_Train_Meditation 3901812
  73.   set %CONTEXT_Train_Mining 2019092
  74.   set %CONTEXT_Train_Musicianship 4167920
  75.   set %CONTEXT_Train_Necromancy 4205298
  76.   set %CONTEXT_Train_Parry 3108898
  77.   set %CONTEXT_Train_Peacemaking 4680400
  78.   set %CONTEXT_Train_Provocation 3850930
  79.   set %CONTEXT_Train_Resisting_Spells 6022522
  80.   set %CONTEXT_Train_Spirit_Speak 4945928
  81.   set %CONTEXT_Train_Swordsmanship 5601890
  82.   set %CONTEXT_Train_Tactics 1806400
  83.   set %CONTEXT_Train_Tailoring 2867278
  84.   set %CONTEXT_Train_Taste_Evaluation 6613220
  85.   set %CONTEXT_Train_Tinkering 2863750
  86.   set %CONTEXT_Train_Tracking 2572028
  87.   set %CONTEXT_Train_Veterinary 2777822
  88.   set %CONTEXT_Train_Wrestling 2967380
  89. return
  90. ;-------------------------------------------------------------------------------
  91. ; %1 = HandleContextMenu
  92. ; %2 = #FINDID to manipulate
  93. ; %3 = menu selection
  94. ; returns #TRUE if entry not found, otherwise #FALSE for no error
  95. ; stores computed values in !test1, !test2, !test3, etc for each menu selection.
  96. sub HandleContextMenu
  97.   namespace push
  98.   namespace local HCM
  99.   set !findid %2
  100.   set !menu_selection %3
  101.   set !x_offset 12
  102.   set !y_offset 12
  103.   set !select_height 18
  104.   set !y_gump_excess 24
  105.  
  106.   exevent popup !findid
  107.   gosub GumpWait NULL normal_gump normal_gump
  108.   set #CONTPOSX 25
  109.   set #CONTPOSY 25
  110.   wait 10
  111.   str pos #CONTSIZE _
  112.   str del #CONTSIZE 1 #STRRES
  113.  
  114.   set !gump_y #STRRES
  115.   set !number_of_selections ( ( !gump_y - !y_gump_excess ) / !select_height )
  116.   for !line_number 1 !number_of_selections
  117.   {
  118.     set !clickxposition1 #CONTPOSX + !x_offset
  119.     set !clickyposition1 #CONTPOSY + !y_offset + ( !select_height * ( !line_number - 1 ) )
  120.     set !clickxposition2 !clickxposition1 + 150
  121.     set !clickyposition2 !clickyposition1 + !select_height - 1
  122.     gosub NewSampleArea NULL !clickxposition1 !clickyposition1 !clickxposition2 !clickyposition2
  123.     set !test . !line_number #RESULT  ; stores values in !test1, !test2, .. !test . n.  Put in debug mode to gather these sampled values
  124. ;    pause  ; include this pause to view sampled values.
  125.     if #RESULT = !menu_selection
  126.     {
  127.       click !clickxposition1 !clickyposition1 mc
  128.       namespace pop
  129.       return #FALSE ; no error, selection found
  130.     }
  131.   }
  132. ;  pause
  133.   namespace clear
  134.   namespace pop
  135. return #TRUE
  136. ;-------------------------------------------------------------------------------
  137. ; %1 = NewSampleArea
  138. ; %2 = x1coord
  139. ; %3 = y1coord
  140. ; %4 = x2coord
  141. ; %5 = y2coord
  142. ; %6 = return stamp
  143. sub NewSampleArea
  144.   namespace push
  145.   namespace local NSA2
  146.   set !temp_LPC #LPC
  147.   set #LPC 10000
  148.   set !stamp 0
  149.   set !x %2
  150.   set !blank_cnt 0
  151.   while !x <= %4
  152.   {
  153.     set !y %3
  154.     while !y <= %5
  155.     {
  156.       savepix !x !y 1
  157.       if #PIXCOL = 16777215
  158.       {
  159.         set !stamp ( !stamp + ( !x - %2 + 1 ) * 2048 + ( !y - %3 + 1 ) * 128 )
  160.         set !blank_cnt 0
  161.       }
  162.       else
  163.       {
  164.         set !stamp ( !stamp + ( !x - %2 ) * ( !y - %3 ) )
  165.       }
  166.       set !y !y + 2
  167.     }
  168.     set !blank_cnt !blank_cnt + 1
  169.     if !blank_cnt >= 10
  170.       goto NewSampleArea_skip1
  171.     set !x !x + 5 ; changing this will impact present sampled values!!
  172.   }
  173. NewSampleArea_skip1:
  174.   set #LPC !temp_LPC
  175.   set #RESULT !stamp
  176.   namespace pop
  177. return #RESULT
  178. ;-------------------------------------------------------------------------------
  179. ; %1 = GumpWait
  180. ; %2 = Gumpname 1
  181. ; %3 = Gumpname 2
  182. sub GumpWait
  183.   wait 10
  184.   set %timedelay #SCNT
  185.   GumpWait_loop1:
  186.     if #CONTNAME = %2 || #CONTNAME = %3
  187.       return
  188.     if #SCNT > %timedelay + 7
  189.       return
  190.     goto GumpWait_loop1
  191. return

This should work on both OSI and RunUO
« Last Edit: May 05, 2017, 05:07:26 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!