ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Cerveza on December 15, 2011, 05:19:05 AM

Title: Working on a pixel scan sub
Post by: Cerveza on December 15, 2011, 05:19:05 AM
I want to execute a primary weapon move every 3 seconds so I don't get the penalty for doing them back to back.

I'll use pixel scanning to determine the condition of the icon...

Code: [Select]
gosub set_pixel 1 ArmorIgnore 35 0

sub set_pixel
  event macro %3 %4
  display ok Move mouse to your %2 Button.$You have 2 seconds
  wait 2s
  savePix #cursorX #cursorY %1
  wait 5
  display ok Pixel saved as # %1 $Do NOT move that icon!
return

That sets cmppix 1 to the active Armor Ignore icon.

What I want to do is keep checking that, amongst other things, and when it toggles to False (the icon is no longer red) set a 3 second timer. During this 3 second timer I don't want to recheck the icon at all. At the end of the 3 second timer I want to activate Armor Ignore again, which is easy enough. During that 3 second period the rest of the script must continue.

I'm thinking I'll need a "pixel checker" in the main loop with a timer attached.

Code: [Select]
set %timer_primary ( #sCnt2 + 60 )

gosub check_primary

sub check_primary
cmppix 1 f ; icon is NOT active
  {
  if %timer_primary > #sCnt2
    return
  event macro 35 0
  set %timer_primary ( #sCnt2 + 60 )
  wait 5
  }
return

I'm coffee lagged and can't determine if that is what I'm looking for? It seems like it.... Check the pixel, if it's NOT lit up that means I just armor ignored.

Anyways, need a fresh set of eyes on this, I'm not even sure I'm in the ballpark here.

Ultimate would be to include a different cmppix while waiting for the armor ignore ;) , like 3 lightning strikes - 1 armor ignore pattern.
Title: Re: Working on a pixel scan sub
Post by: Endless Night on December 15, 2011, 05:00:58 PM
off top of head code... not tested in the slightest.  Generic so you can define as many gumps to check as you want and check as many as needed.

Code: [Select]
gosub set_pixel 1 ArmorIgnore 35 0 3
gosub Set_pixel 2   name        macro timer ie 3sec

gosub Check_pixel 1
gosub Check_pixel 2
halt

sub set_pixel
  set %PixelName . %1 %2
  set %Pixelmacro1 . %1 %3
  set %Pixelmacro2 .  %1 %4
  set %PixelTime . %1 %5 * 1000
  event macro %3 %4
  set %PixelTimer . %1 #SYSTIME + %PixelTime . %1
  display ok Move mouse to your %2 Button.$You have 2 seconds
  wait 2s
  savePix #cursorX #cursorY %1
  set %PixelPosx  . %1 #cursorx
  set %PixelPosy .  %1 #cursorY
  set %PixelValue . %1  #pixcol
  wait 5
  display ok Pixel saved as # %1 $Do NOT move that icon!
return

sub check_pixel ; 1....
  if %PixelTimer . %1 > #SYSTIME
     {
    savePix #cursorX #cursorY
    if #pixcol <>  %PixelValue . %1  
       {
       event macro %Pixelmacro1 . %1  %Pixelmacro2 . %1
       set %PixelLastCall . %1  #SYSTIME + %PixelTime . %1  
       }
    if #pixcol =  %PixelValue . %1  
       set %PixelTimer . %1 %PixelLastCall . %1 ; done this way so dont have to wait to check was good checks on next loop.
     }
return
Title: Re: Working on a pixel scan sub
Post by: manwinc on December 15, 2011, 06:29:44 PM
These Subs Might Be Handy For You. Just wrote them tonight actually....

Gosub Move_PrimaryAbility (x) (y)

Pixel Scans the location to see if it can find proper Pixels for the Gump in the Location First, and if it Can't, pulls the Primary Gump and moves it to The Location. Works the Same for SecondaryAbility, MomentumStrike, And LightningStrike

I know it's Not "En" Pixel Scanning and Doesn't Compensate for all Resolutions, but seems to work okay.


Code: [Select]
;====================================
Sub Save_Pix2
Namespace Push
Namespace Local Save_Pix2
Set !SaveX %1
set !SaveY %2
Savepix !SaveX !SaveY 1
Namespace Pop
Return
;=====================================

Sub Move_PrimaryAbility
Namespace Push
Namespace Local Mwinc_Move_PrimaryAbility
set !LPC #LPC
set #LPC 9999
set !X %1
set !Y %2
set !X_Start !X + 25
set !X_End !X + 30
set !Y_Scan !Y + 27
set !Cipher
for !X_Scan !X_Start !X_End
{
Gosub Save_Pix2 !X_Scan !Y_Scan
Str Left #Pixcol 1
set !Cipher !Cipher , #Strres
}
if !Cipher = 431431 || !Cipher = 771862
{
set #Lpc !Lpc
NameSpace Pop
Return
}
Event macro 8 14
Gosub Cont_Timer 30 Contsize 406_249
Gosub Click_Offset 243 127 G
Gosub Cont_Timer 30 COntName AbilityIcon_Gump
if #ContName = AbilityIcon_Gump
{
Gosub Click_Offset 15 15 f
Contpos !X !Y
}
Event Macro 9 14
set #LPC !LPC
Namespace Pop
Return

;======================================

Sub Move_SecondaryAbility
Namespace Push
Namespace Local Mwinc_Move_PrimaryAbility
set !LPC #LPC
set #LPC 9999
set !X %1
set !Y %2
set !X_Start !X + 25
set !X_End !X + 30
set !Y_Scan !Y + 27
set !Cipher
for !X_Scan !X_Start !X_End
{
Gosub Save_Pix2 !X_Scan !Y_Scan
Str Left #Pixcol 1
set !Cipher !Cipher , #Strres
}
if !Cipher = 952948 || !Cipher = 411424
{
set #Lpc !Lpc
Namespace Pop
Return
}
Event macro 8 14
Gosub Cont_Timer 30 Contsize 406_249
Gosub Click_Offset 243 171 G
Gosub Cont_Timer 30 COntName AbilityIcon_Gump
if #ContName = AbilityIcon_Gump
{
Gosub Click_Offset 15 15 f
Contpos !X !Y
}
Event Macro 9 14
set #Lpc !LPC
Namespace Pop
Return
;====================================

Sub Move_LightningStrike
Namespace Push
Namespace Local Mwinc_Move_LightningStrike
set !Lpc #Lpc
set #Lpc 9999
set !X %1
set !Y %2
set !X_Start !X + 25
set !X_End !X + 30
set !Y_Scan !Y + 27
set !Cipher
for !X_Scan !X_Start !X_End
{
Gosub Save_Pix2 !X_Scan !Y_Scan
Str Left #Pixcol 1
set !Cipher !Cipher , #Strres
}
if !Cipher = 768888 || !Cipher = 334444
{
set #Lpc !Lpc
Namespace Pop
Return
}
Finditem QON C_ , #Backpackid
if #findcnt < 1
{
set #Lpc !Lpc
Namespace Pop
Return
}
Event macro 8 15
Gosub Cont_Timer 30 Contsize 406_249
if #Result = #True
{
set #Lpc !Lpc
Namespace Pop
Return
}
Gosub Click_Offset 335 18 x 3
Wait 10
Gosub Click_Offset 90 76 G
Gosub Cont_Timer 30 COntName SpellIcon_Gump
if #ContName = SpellIcon_Gump
{
Gosub Click_Offset 15 15 f
Contpos !X !Y
}
Event Macro 9 15
set #Lpc !Lpc
Namespace Pop
Return
;========================================
Sub Move_MomentumStrike
Namespace Push
Namespace Local Mwinc_Move_MomentumStrike
set !LPC #LPC
set #Lpc 9999
set !X %1
set !Y %2
set !X_Start !X + 25
set !X_End !X + 30
set !Y_Scan !Y + 27
set !Cipher
for !X_Scan !X_Start !X_End
{
Gosub Save_Pix2 !X_Scan !Y_Scan
Str Left #Pixcol 1
set !Cipher !Cipher , #Strres
}
if !Cipher = 776567 || !Cipher = 433333
{
Set #Lpc !Lpc
Namespace Pop
Return
}
Finditem QON C_ , #Backpackid
if #findcnt < 1
{
set #Lpc !Lpc
Namespace Pop
Return
}
Event macro 8 15
Gosub Cont_Timer 30 Contsize 406_249
if #Result = #True
{
set #Lpc !Lpc
Namespace Pop
Return
}
Gosub Click_Offset 335 18 x 3
Wait 10
Gosub Click_Offset 252 76 G
Gosub Cont_Timer 30 COntName SpellIcon_Gump
if #ContName = SpellIcon_Gump
{
Gosub Click_Offset 15 15 f
Contpos !X !Y
}
Event Macro 9 15
set #Lpc !Lpc
Namespace Pop
Return
;===================================
;========================================================
Sub Click_Offset
Namespace Push
Namespace Local Mwinc_ClickOffset
set !Clickx #contposx + %1
set !CLicky #contposy + %2
Click !Clickx !CLicky %3 %4
set %3 0
set %4 0
Namespace pop
Return
;========================================================
;==========================================================
Sub Cont_Timer
; Gosub Cont_Timer (Timer) ( Var ) ( Value )
Namespace Push
Namespace Local Mwinc_Cont_Timer
set !Lpc #Lpc
set #lpc 9999
set !Time_Limit #scnt2 + %1
set !Cont_Check # . %2
While !Cont_Check <> %3 && !Time_Limit > #scnt2
{
set !Cont_Check # . %2
wait 1
}
set #Lpc !LPC
if !Time_Limit <= #scnt2
{
Namespace Pop
Return #true
}
Namespace Pop
Return #False
;=========================================================

Title: Re: Working on a pixel scan sub
Post by: manwinc on December 15, 2011, 08:44:45 PM
ROFL, Stupid me, Forgot that there are more than just one Kind of Special... That was Dumb..... Time for lots of Pixel Scanning.
Title: Re: Working on a pixel scan sub
Post by: Cerveza on December 16, 2011, 02:49:15 AM
In LAME3.0 dxrom has it setup for Whirlwind primary and also Armor Ignore primary. His trick is to pixel scan the lower left corner of the icon. That spot doesn't change between the two different icons so it's a "safe place".

The true way would be what you gents have mentioned. A pixel scanner that would arrange the icons and scan do determine which icons are busy would be the very best case.

I was trying to get AI's every three seconds so I don't get spammed with "you need 24 mana to perform that action" messages all the darn time LOL. And eventually I'd love to have 2 or 3 lightning strikes then 1 armor ignore. Or even lightning strike until mana meets a criteria ( > 24 LOL ) then do an AI again.
Title: Re: Working on a pixel scan sub
Post by: manwinc on December 16, 2011, 07:45:28 AM
Hehe, What I wound up doing was arranging my Gumps so there was a little space in between them, then I would scan top portion, which would give a code like

0111111111111111111111111111111111111110

the Zeros Representing the Black saying that its at least in the Right spot for the X Position Requested. I guess I could do the Same for The Y Position, but I like for the Script to start up as quickly as Possible.
Title: Re: Working on a pixel scan sub
Post by: dxrom on December 16, 2011, 11:23:00 AM
I have an idea, but I'm still sorting out (mentally) how to explain it...

I'm gonna run to the store and get a case of beer, have a couple and by then I should have it worked out. I'll post it later tonight.
Title: Re: Working on a pixel scan sub
Post by: dxrom on December 16, 2011, 11:51:35 AM
In LAME3.0 dxrom has it setup for Whirlwind primary and also Armor Ignore primary. His trick is to pixel scan the lower left corner of the icon. That spot doesn't change between the two different icons so it's a "safe place".

The true way would be what you gents have mentioned. A pixel scanner that would arrange the icons and scan do determine which icons are busy would be the very best case.

I was trying to get AI's every three seconds so I don't get spammed with "you need 24 mana to perform that action" messages all the darn time LOL. And eventually I'd love to have 2 or 3 lightning strikes then 1 armor ignore. Or even lightning strike until mana meets a criteria ( > 24 LOL ) then do an AI again.

(http://img543.imageshack.us/img543/200/cornerse.png)

I guess a more technical term would be that they have 4 things in common.
Title: Re: Working on a pixel scan sub
Post by: Cerveza on December 16, 2011, 11:54:30 AM
I'd say they all have the lower right corner in common also. The closes one is the concussion blow, but even that has a clear spot in the lower right corner.
Title: Re: Working on a pixel scan sub
Post by: dxrom on December 16, 2011, 12:15:13 PM
Anywhere on that edge, really...
Title: Re: Working on a pixel scan sub
Post by: dxrom on December 17, 2011, 04:36:23 PM
Code: [Select]
gosub set_pixel 1 ArmorIgnore 35 0

sub set_pixel
  event macro %3 %4
  display ok Move mouse to your %2 Button.$You have 2 seconds
  wait 2s
  savePix #cursorX #cursorY %1
  wait 5
  set %primCnt 0
  display ok Pixel saved as # %1 $Do NOT move that icon!
return




// set %timer_primary ( #sCnt2 + 60 )

gosub check_primary
gosub check_lightningStrike

sub check_lightningStrike
cmppix 2 f
 {
 if %primCnt < 3
return
 event macro 15 149
 set %primCnt 0
 wait 5
 }
return

sub check_primary
cmppix 1 f ; icon is NOT active
  {
  if %primCnt < 3
    return
  event macro 35 0
//  set %timer_primary ( #sCnt2 + 60 )
  set %primCnt + 1
  wait 5
  }
return

I was thinking something like that. However THAT is completely untested and I can guarantee will not work as is (left out alot of stuff, like setting the pixel for LS). But the basic concept is that instead of using a timer, to make a primary counter, that assume you hit. Every three Primaries will switch over to a lightning strike.
Title: Re: Working on a pixel scan sub
Post by: Cerveza on December 19, 2011, 08:19:20 AM
Thinking here....

Code: [Select]
gosub check_pix

sub check_pix
cmppix 1 f ; icon not active
  {
  if %LSCount < 3
    {
    event macro 15 149
    set %LSCount ( %LSCount + 1 )
    return
    }
  }
event macro 35 0 ; armor ignore
set %LSCount 0
return

The missing part is knowing when the toggle for Armor Ignore ( cmppix 2 ) goes off to start the Lightning Strike cycle once more.
Title: Re: Working on a pixel scan sub
Post by: dxrom on December 19, 2011, 08:47:10 PM
I would make it so that after I utilize event macro 35 0 that it adds +1 to a counter... Once it reaches a certain point, (or mana is at a certain level) it switches to lightning strike, resetting the counter, or until mana is back.