Official ScriptUO EasyUO Scripts > Script Debug

Trick or treat starter

(1/9) > >>

baldielocks:
HI! I'm baby stepping my way through making a robust trick or treater. First, I want to ensure I can reliably target, trick or treat, detect a teleport, and recall back to the spot. The script will "eventually" be a recall based script with bank/trash support. BUT I am having issues getting it to detect the teleport. This is what I have for one static NPC. The targetting and trick or treat and timing are spot on so far.


--- Code: ---Display ok Target your recall rune or book
set #targcurs 1
  while #targcurs = 1
    wait 0
  set %rune #ltargetid
wait 5
;----------
 Display ok Target your First Animal.
     set #targcurs 1
  while #targcurs = 1
    wait 0
  set %heal1 #ltargetid
wait 5
;-----------
mainloop:
gosub TM_AdvJournalSync TRICK 100
gosub trickortreat1
wait 60s
return
;----------
Sub trickortreat1
set #ltargetid %heal1
set #ltargetkind 1
msg $trick or treat
 if  #targcurs = 0
{
 repeat
}
target
Event macro 22 0
gosub trickcheck
return
;-----------
Sub trickcheck
gosub TM_AdvJournalScan TRICK VALID_Advance teleports
 If #result = #true
          {
          msg $trick detected
           }
  return
;=================================================================
; Script Name: TrailMyx's Advanced Journal Scanner
; Author: TrailMyx     gosub TM_AdvJournalScan heal VALID_ADVANCE
; Version: 1.2
; 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_AdvJournalGetTrigger - retrieve the triggering string (#FALSE for no trigger)
;     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
;-------------------------------------------------------------------------------
sub TM_AdvJournalGetTrigger
  namespace push
  namespace local TM_AdvJS_ , %1
  set #RESULT !trigger
  namespace pop
  set !TM_FunctionCalled #TRUE
return #RESULT
;-------------------------------------------------------------------------------
; %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 !trigger !text
        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
  set TM_AdvJournalGetTrigger #FALSE
  namespace pop
  set !TM_FunctionCalled #TRUE
return #FALSE
;-------------------------------------------------------------------------------


--- End code ---

Crisis:
Someone had a good script using a personal attendant before they fixed that. I am sure that you can get an idea from that. I don't remember whose script it was but am thinking it was probably The Ghost.

Gaderian:
My 2 cents:

Repeat is the first part of a repeat...until construct. If you want to build your own timeout using a wait loop on the target cursor, consider changing:


--- Code: easyuo ---Sub trickortreat1set #ltargetid %heal1set #ltargetkind 1msg $trick or treat if  #targcurs = 0{ repeat}targetEvent macro 22 0gosub trickcheckreturn

--- Code: easyuo ---Sub trickortreat1set #ltargetid %heal1set #ltargetkind 1msg $trick or treatrepeat wait 1until #targcurs <> 0targetEvent macro 22 0gosub trickcheckreturn
But honestly, if you are expecting it will bring up the target cursor 100% of the time, then simply use the 'target' command with a timeout by doing this:

--- Code: easyuo ---Sub trickortreat1set #ltargetid %heal1set #ltargetkind 1msg $trick or treattarget 4s; Here you would have #targcurs <> 0 or you would have reached the 4 second timeout provided; So you could now test if #targcurs <> 0 and bail with an appropriate error result if for some ; reason it did not come up with a target cursor...Event macro 22 0gosub trickcheckreturn
The command 'msg' is appropriate when you want your character to say something to the public/npc's. If you want to give yourself feedback, consider using "event sysmessage". I am looking at the use of 'msg' in the sub trickcheck specifically.

I have a slightly different version of the AdvJournal Routines - not sure the difference in function. Here is the version of the routines Oracle and I have been using this year for hundreds of hours in a project we did together. I know this code works as expected, so maybe there is some logic difference that you are experiencing.


--- Code: easyuo ---;-------------------------------------------------------------------------------; %1 - Journal Name; %2 - #LPC setting (optional); Brings !_jindex up to the most recent #journal entrysub 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 #TRUEreturn;-------------------------------------------------------------------------------; %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 copysub 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  if !_jindex = N/A    set !_jindex #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 <= #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 #LPC !temp_lpc  namespace pop  set !TM_FunctionCalled #TRUEreturn #FALSE;------------------------------------------------------------------------------- 
That is what jumps out at me...

Maybe it will help push your project along.

Gaderian

The Ghost:
Why event bored with the recall back to where you were.  At best you have 5 npc,  most are 3 -4.    Not sure it wort the effort  ATm .  If you get teleported,  you will recall back when  you can't find any NPC.    Once you  have a solid working build,  now you can to improve it
 
Don't over complicated the script.   Start with the basic.   

1) scan for NPC and ToT,
2)  recall to new location
3) Weight recall to bank and track


C2    Happy Halloween
 http://www.scriptuo.com/index.php?topic=3151.0

baldielocks:
Good suggestions Ghost. Those steps are in my plan. But FIRST, I have to get it to recognize that I teleported away. Either way, getting the hang of the journal scan is actually my priority here.

Navigation

[0] Message Index

[#] Next page

Go to full version