Author Topic: SUB - Veryify new targeting system is active  (Read 7164 times)

0 Members and 1 Guest are viewing this topic.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +861
  • Referrals: 11
    • View Profile
SUB - Veryify new targeting system is active
« on: December 09, 2009, 08:12:21 AM »
0
A little sub to ensure the new targeting system is either on or off.

Called with:

gosub ToggleTargeting {on or off}

Code: [Select]
;==========================
; %1 = on or off
sub ToggleTargeting
gosub TM_AdvJournalSync TARGETING
if %1 = on
  {
    event macro 56
    gosub TM_AdvJournalScan TARGETING NULL The_New_Targetting_System_is_now_turned_On
    if #RESULT = #TRUE
      return
    event macro 56
    return
  }
if %1 = off
  {
    event macro 56
    gosub TM_AdvJournalScan TARGETING NULL The_New_Targetting_System_is_now_turned_Off
    if #RESULT = #TRUE
      return
    event macro 56
    return
  }
return ; fallout - should never be seen

;=================================================================
; Script Name: TrailMyx's Advanced Journal Scanner
; Author: TrailMyx
; Version: 1.1
; Shard OSI / FS: OSI / FS?
; Revision Date: 10/20/2007
; Purpose:
;   Use these subs to quickly find text in your #journal entries.  These subs
; use #jindex for flawless journal scanning and is much more reliable than using
; standard indexing of #journal and #SYSMSG.
;
;   Now it is possible to manage separate journals based on unrelated text.  It's now possible
; to monitor spellcasting, bandaging, stealing, or anything else without a TM_AdvJournalSync
; potentially removing text needed for another UO funciton.
;
;   New is the ability to either gosub or call these functions without the need to change the
; header!  When calling, a limit of 10 arguments is allowed, but more can be added by editing the
; call interface section.
;
;  Examples:
;     gosub TM_AdvJournalSync speech 100 ; sync "speech" journal space, set #LPC to 100 from default of 1000
;     gosub TM_AdvJournalScan speech VALID Find_this_text and_find_this_too ; will not advance copy of #jindex
;     gosub TM_AdvJournalScan heal VALID_ADVANCE you_heal_what that_patient_is_not ; advances pointer after scan
;     gosub TM_AdvJournalScan spellcast NONE fizzle ; no spam checking and doesn't advance #jindex copy automatically
;
;  Subs included:
;     TM_AdvJournalSync - Must call this in initialzation
;     TM_AdvJournalScan - see header for details....
;
;  Release history:
;    v1.0 - Initial release.
;    v1.1 - debug code added, fixed small possibility to miss an incoming journal entry
;
;  Requirements:
;    Nothing special
;
;  Credit:
;    If you use these subs, please leave credit for me somewhere in your script header.
;=================================================================
;------------------------  Call interface  -----------------------
;=================================================================
set !TM_FunctionCalled #FALSE
if %0 = 1
  gosub %1
if %0 = 2
  gosub %1 %2
if %0 = 3
  gosub %1 %2 %3
if %0 = 4
  gosub %1 %2 %3 %4
if %0 = 5
  gosub %1 %2 %3 %4 %5
if %0 = 6
  gosub %1 %2 %3 %4 %5 %6
if %0 = 7
  gosub %1 %2 %3 %4 %5 %6 %7
if %0 = 8
  gosub %1 %2 %3 %4 %5 %6 %7 %8
if %0 = 9
  gosub %1 %2 %3 %4 %5 %6 %7 %8 %9
if %0 = 10
  gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10
if %0 = 11
  gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11
if %0 > 11
{
  display ok Too many arguments for "call", edit file.
  stop
}

if !TM_FunctionCalled = #TRUE
  exit
if %0 = N/A
  display ok You may not run this script directly.
else
  display ok Function " , %1 , " not found.
stop
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; %1 - Journal Name
; %2 - #LPC setting (optional)
; Brings !_jindex up to the most recent #journal entry
sub TM_AdvJournalSync
  namespace push
  namespace local TM_AdvJS_ , %1
  set !_jindex #jindex + 1
  if %0 > 1
    set !lpc_set %2
  namespace pop
  set !TM_FunctionCalled #TRUE
return
;-------------------------------------------------------------------------------
; %1 - Journal Name
; %2 - NONE, ADVANCE , ( _VALID ) - advances jindex pointer, anything else
; %3, %4, %5, etc strings to match
; returns #TRUE for match, #FALSE for no match
;  Will not advance !_jindex pointer to allow for scanning journal history for more than one search.
;  Also searches for : , #SPC in journal entry to be sure someone isn't spamming the text
;  About %2 arguments:
;    NONE: defaults to basic journal scan (no SPAM checking, no #jindex pointer copy advancing)
;    ADVANCE: no spam checking, advances #jindex copy
;    VALID: invokes SPAM filtering, no advance of #jindex copy
;    VALID_ADVANCE, VALIDADVANCE, ADVANCE_VALID, etc.: invokes SPAM filtering, advances of #jindex copy
sub TM_AdvJournalScan
  namespace push
  namespace local TM_AdvJS_ , %1
  set !args %2
  set !temp_lpc #LPC
  if !lpc_set = N/A
    set #LPC 1000
  else
    set #LPC !lpc_set
  set !num_args %0
  set !first_arg 3
  set !sampled_jindex #JINDEX
  if !_jindex = N/A
    set !_jindex !sampled_jindex
  if !charname = N/A
  {
    set !charname #CHARNAME
    AdvJournalScan_loop1:
      str pos !charname #SPC
      if #STRRES <> 0
      {
        set !val #STRRES - 1
        str left !charname !val
        set !left #STRRES
        set !val !val + 1
        str del !charname 1 !val
        set !charname !left , _ , #STRRES
        goto AdvJournalScan_loop1
      }
  }
  set !index !first_arg
  repeat
    set !temp_jindex !_jindex
    set !text % . !index
    while !temp_jindex <= !sampled_jindex
    {
      scanjournal !temp_jindex
      str pos #JOURNAL !charname 1
      set !namepos #STRRES
      str count #JOURNAL !charname
      set !namecnt #STRRES
      str pos #JOURNAL :_ 1
      set !smcpos #STRRES
      str pos #JOURNAL !text 1
      set !textpos #STRRES
      if !textpos < !smcpos && !smcpos <> 0 || !smcpos = 1 || :_ notin #JOURNAL || VALID notin !args
        set !pass #TRUE
      else
        set !pass #FALSE
      if ( !text in #journal && ( ( !namepos = 1 && !namecnt <= 1 ) || !pass ) )
      {
        set !temp_jindex !temp_jindex + 1
        if ADVANCE in !args
          set !_jindex !temp_jindex
        set #LPC !temp_lpc
        namespace pop
        set !TM_FunctionCalled #TRUE
        return #TRUE
      }
      set !temp_jindex !temp_jindex + 1
    }
    set !index !index + 1
  until !index - !first_arg > !num_args - !first_arg
  set %10 !sampled_jindex - !_jindex
  set %10 %1 , _ , %10 ; for debugging purposes
  set #LPC !temp_lpc
  namespace pop
  set !TM_FunctionCalled #TRUE
return #FALSE

[fixed a typo - TM]
« Last Edit: December 09, 2009, 08:30:01 AM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline Superslayer

  • Elite
  • *
  • *
  • Posts: 1006
  • Activity:
    0%
  • Reputation Power: 14
  • Superslayer barely matters.Superslayer barely matters.
  • Gender: Male
  • Well what do you drink? Not tea.
  • Respect: +100
  • Referrals: 0
    • View Profile
Re: SUB - Veryify new targeting system is active
« Reply #1 on: December 09, 2009, 08:21:39 AM »
0
Worked like a charm. Something I had tested out prior to this was using a repeat .. until loop.

Code: [Select]
repeat
event macro 56
until New_Targeting_System_ON in #sysmsg

Anything negative about this method?  Only thing I can think of is possibly spam, but then if I do like you have setup, I can add the spam filtering.

Edit: LOL, ya, I figured that should be removed !
« Last Edit: December 09, 2009, 08:24:29 AM by Superslayer »

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +861
  • Referrals: 11
    • View Profile
Re: SUB - Veryify new targeting system is active
« Reply #2 on: December 09, 2009, 08:29:16 AM »
0
TM's subs handle spam the best, I think all message scanning should use them.

It worked?! wow, cool. Most my YACSWAW stuff has issues. (YetAnotherCervezaScriptWrittenAtWork)
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: SUB - Veryify new targeting system is active
« Reply #3 on: December 09, 2009, 09:59:12 AM »
0
Although much respect for TMs subs.. sometiems its nice to have a peice of code that isnt dependant on anything so how about...

Below allows you to set it on or off and has inbult timeouts so if the client hangs or other the code doesnt get stuck.  Returns if it was succesfful in setting the desired on /off status
 
Code: [Select]
sub Ens_SetNewTargetSystem
  ; %1-On/off  %2-MaxAttampts %3-Waittime
  ; If nothing passed Default ON 6 20
  set !Status ON
  set !MaxAttempts 6
  set !MaxWaitTime 8
  If %0 > 0 && %1 <> N/A
     set !Status %1
  If %0 >= 2 && %2 <> N/A
    set !MaxAttempts %2
  If %0 >= 3 && %3 <> N/A
    set !MaxWaitTime %3
  set !StatusNo OFF
  If !status = OFF
     set !StatusNO ON
  set !YESString  New_Targeting_System_ , !Status
  set !NOString  New_Targeting_System_ , !StatusNo

  set !TargetOn #false
  repeat
    set !MaxAttempts !MaxAttempts - 1
    set !JOurnalOn #jindex + 1
    event macro 56
    set !Waittime !MaxWaitTime
    Repeat
      wait 1
      set !WaitTime !WaitTime - 1
      while #jindex >= !JournalOn
         {
         scanJournal !JOurnalOn
         IF !YESString = #journal
            set !Targeton #true
         IF !NOString = #journal
            set !Targeton #False
         set !JOurnalOn !JOurnalOn + 1
         }
    Until !WaitTime <= 0 || !TargetOn
  until !TargetOn  || !MaxAttempts <= 0
Return !TargetOn

This code can also be found in my code snippet library ..l
http://www.scriptuo.com/index.php?topic=2454.msg29703#msg29703
« Last Edit: December 09, 2009, 10:07:49 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Scrripty

  • Guest
Re: SUB - Veryify new targeting system is active
« Reply #4 on: December 09, 2009, 10:13:51 AM »
0
Although much respect for TMs subs.. sometiems its nice to have a peice of code that isnt dependant on anything so how about...

Below allows you to set it on or off and has inbult timeouts so if the client hangs or other the code doesnt get stuck.  Returns if it was succesfful in setting the desired on /off status
 
Code: [Select]
sub Ens_SetNewTargetSystem
  ; %1-On/off  %2-MaxAttampts %3-Waittime
  ; If nothing passed Default ON 6 20
  set !Status ON
  set !MaxAttempts 6
  set !MaxWaitTime 8
  If %0 > 0 && %1 <> N/A
     set !Status %1
  If %0 >= 2 && %2 <> N/A
    set !MaxAttempts %2
  If %0 >= 3 && %3 <> N/A
    set !MaxWaitTime %3
  set !StatusNo OFF
  If !status = OFF
     set !StatusNO ON
  set !YESString  New_Targeting_System_ , !Status
  set !NOString  New_Targeting_System_ , !StatusNo

  set !TargetOn #false
  repeat
    set !MaxAttempts !MaxAttempts - 1
    set !JOurnalOn #jindex + 1
    event macro 56
    set !Waittime !MaxWaitTime
    Repeat
      wait 1
      set !WaitTime !WaitTime - 1
      while #jindex >= !JournalOn
         {
         scanJournal !JOurnalOn
         IF !YESString = #journal
            set !Targeton #true
         IF !NOString = #journal
            set !Targeton #False
         set !JOurnalOn !JOurnalOn + 1
         }
    Until !WaitTime <= 0 || !TargetOn
  until !TargetOn  || !MaxAttempts <= 0
Return !TargetOn

This code can also be found in my code snippet library ..l
http://www.scriptuo.com/index.php?topic=2454.msg29703#msg29703

I'm going to attempt to write a win at UO script, then have EN look at it and redo it in 3 lines for me.  :)

Tags: