ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Fabolous1 on January 26, 2020, 02:17:58 PM

Title: How to check if Protection is already on?
Post by: Fabolous1 on January 26, 2020, 02:17:58 PM
Hey everybody,

I'm trying to cast Protection if I don't already have the buff. I copied the Protection script from TM's strip miner script and can't seem to get it to work.

Currently I'm doing

Code: [Select]
;==================
sub CastProtection
  event macro 8 2 ; open status
  gosub GumpWait status_gump status_gump
  contpos 0 680
  wait 20
  gosub scanbar
   event sysmessage #result
  if _protection_ notin #result
  {
    event sysMessage casting protection...
    event macro 15 14
    while a in #charstatus
      wait 1
    wait 5

  }
return

sub scanBar
  namespace push
  namespace local scanBar . #charid
  if %whawhawha = #false 2
    namespace clear
  set %whawhawha #true
  set !tempLpc #lpc
  set #lpc 10000
  if %1 <> n/a && %2 <> n/a && %1 > -10000000 && %1 < 49000000000 2
    set !percentOhx %1
  set !percentOhy %2
  else 2
    set !percentOhx n/a
  set !percentOhy n/a
  if !scanOffset = n/a
    gosub setVars %1 %2
  set !buttonX . 1 !blueButtonX . 1 + !blueContPosX . 1
  set !buttonY . 1 !blueButtonY . 1 + !blueContPosY . 1
  if #contname <> buffIcons_Gump || ( #contName = buffIcons_Gump && ( #contposx <> !blueContPosX . 1 || #contposy <> !blueContPosY . 1 ) ) 3
    savepix !buttonX . 1 !buttonY . 1 !savePixelNumber
  if ( #pixcol < !blueButtonPixCol . 1 - !scanOffset || #pixcol > !blueButtonPixcol . 1 + !scanOffset ) && #pixcol < !high
    gosub findBarVars
  set %icons . #charid _
  set !notFound 0
  for !scanIcons 1 !scanBarIconCount
  {
    set !x !scanX + ( ( !scanIcons - 1 ) * 31 )
    savepix !x !scanY !savePixelNumber
    ;event sysmessage #pixcol scan1
    if #pixcol = 0 || #pixcol > 16779215
      break
    if ! . #pixcol <> n/a && ! . #pixcol <> block && ! . #pixcol <> massCurse && ! . #pixcol <> Curse && ! . #pixcol <> Sleep && ! . #pixcol <> Consecrate && ! . #pixcol <> HeatOfBattle && ! . #pixcol <> SplinteringDebuff && ! . #pixcol <> Feeblemind && ! . #pixcol <> Tribulation && ! . #pixcol <> MedusaStone && ! . #pixcol <> FastSkillGain 4
      if _ , ! . #pixcol , _ in %icons . #charid
      continue
    set %icons . #charid %icons . #charid , ! . #pixcol , _
    continue
    gosub S1
    if !notFound >= 2
      break
  }
  set #result %icons . #charid
  set #lpc 10
  namespace pop
return #result

; %1 = Gumpname 1
; %2 = Gumpname 2
; #TRUE gump occured before timeout
sub gumpWait
  namespace push
  namespace local GW
  set !timedelay #SCNT
  while #SCNT <= !timedelay + 2
  {
    if #CONTNAME = %1 || #CONTNAME = %2 2
      namespace pop
    return #TRUE
  }
  namespace pop
return #FALSE

Thanks
Title: Re: How to check if Protection is already on?
Post by: Gaderian on January 26, 2020, 03:57:30 PM
It looks like you are lacking the rest of the scanbar routines.

A much easier way to implement this is to save JosephAJ/Endless Night's version and call it instead. You can find that here:http://www.scriptuo.com/index.php?topic=1508.msg11033#msg11033 (http://www.scriptuo.com/index.php?topic=1508.msg11033#msg11033)

It has coding examples to use it. You will get a new variable in scope for your script called %BuffBarIconNames. You will want to call the external file and then check the variable.

Code: easyuo
  1. ;==================
  2. sub CastProtection
  3.   event macro 8 2 ; open status
  4.   gosub GumpWait status_gump status_gump
  5.   contpos 0 680
  6.   wait 20
  7.   call Scanbuffbar
  8.   if _Protection_ notin %BuffBarIconNames
  9.     {
  10.     event sysMessage casting protection...
  11.     event macro 15 14
  12.     while a in #charstatus
  13.       wait 1
  14.     wait 5
  15.  
  16.   }
  17. return
  18.  
Title: Re: How to check if Protection is already on?
Post by: Fabolous1 on January 26, 2020, 06:30:50 PM
Awesome, it worked, ty!