ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: The Ghost on August 31, 2013, 03:54:34 PM

Title: FindItem timer
Post by: The Ghost on August 31, 2013, 03:54:34 PM
Good day
  I'm trying fixing a snippet of mine  Do i need to add a wait in between those finditem  or this is how is should be. 
Code: [Select]
if if #weight >= %mxwt
   return #true
FindItem %item C_ , #backpackid
if #FINDCNT > 0
   gosub moveitem
FindItem %item C_ , %itembox
if #FINDCNT > 0
   gosub makeitem
Title: Re: FindItem timer
Post by: TrailMyx on August 31, 2013, 06:05:19 PM
Nope, no wait necessary.
Title: Re: FindItem timer
Post by: The Ghost on August 31, 2013, 06:33:39 PM
Thx TM
 here a new one.  Can I make this faster.

Code: [Select]
sub move item
finditem %item C_ , #backpackid
exEvent Drag #findID %stack
exevent dropc %itembox
wait 20
if #FindCnt > 0
   gosub moveitem
return #true
Title: Re: FindItem timer
Post by: manwinc on August 31, 2013, 10:30:16 PM
Code: [Select]
sub move item ;<--- Sub Names can't Contain Spaces.This would be "Sub Move"
finditem %item C_ , #backpackid
exEvent Drag #findID %stack
exevent dropc %itembox
wait 20
if #FindCnt > 0
   gosub moveitem ;<-- Would go nowhere. 
return #true

Its also fairly risky to do a gosub to a sub, inside a sub. Was just picking TM's brain on this one. You can wind up with an infinite Loop, and Variable Crossover. A better method would probably be a "For" Loop so you can have a fail safe.

Code: [Select]
Sub MoveItem
For %Attempt 1 5 ; Limit of 5 Tries
{
Finditem %Item C_ , #backpackid
if #FIndcnt > 0
{
Exevent Drag %Item #Findstack
Exevent dropc %itembox
wait 20
}
if #Findcnt = 0
Break ; Breaks from the For Loop, just ends it a little quicker
}
Return
Then at the End of the For Loop, you could do 1 final check, and if the item still hasn't moved, do a "Reset" Close the backpack and reopen it. Normally its either a glitched Item, or You Con lossed or some thing along those lines.
Title: Re: FindItem timer
Post by: The Ghost on September 01, 2013, 07:58:20 AM
Thx Manwinc,  Thx for the exemple.
      Just notice that I copy an old sub :(  This is the one I'm using now.   
Code: [Select]
sub MoveItem
finditem %Item C_ , #backpackid
for #FINDINDEX 1 #FINDCNT
{
exEvent Drag #findID   ;  %stack
exevent dropc %itembox
wait 20
}
return #true

Right now the item are moving every 2 sec and wondering if we can make them move faster.   
Can add the namespace push help me gain some speed.
Code: [Select]
sub MoveItem
  namespace push
  namespace local MI
finditem %Item C_ , #backpackid
for #FINDINDEX 1 #FINDCNT
{
exEvent Drag #findID   ;  %stack
exevent dropc %itembox
wait 20
}
namespace pop
return #true
Title: Re: FindItem timer
Post by: manwinc on September 01, 2013, 09:23:10 AM



Namespace Push Just puts Your Last namespace into a "Save", so when you do Namespace POP, it reloads the Namespace.

Code: [Select]
Namespace Local MW_Test
Display Your Namespace is #NSNAME
Namespace Push ; <- Saves the Previous NameSpace
Namespace Local MW_Next
Display Your Namespace is #NSNAME
Namespace Pop ;<- Reloads MW_Test
Halt

Namespaces Are for "Subs" that you want to be able to use without Interfering with the % Variables of your Script and to Communicate Between Scripts running under the same thread.

Code: [Select]
sub MoveItem
  namespace push
  namespace local MI
finditem %Item C_ , #backpackid
for #FINDINDEX 1 #FINDCNT
{
exEvent Drag #findID   ;  %stack
exevent dropc %itembox
wait 20
}
namespace pop
return #true

If you do a for #Findindex 1 #Findcnt, its always important to make sure that an item actually exists.

Code: [Select]
Finditem %Item C_ , #Backpackid
if #Findcnt > 0
{
For #Findindex 1 #FIndcnt
{
Exevent Drag #Findid ; Stack
Exevent Dropc %ItemBox
wait 20
}
}

If you wanted to make this into a Sub you could use in any situation, this is one way to set it up.

Code: [Select]
Sub MoveItem
Namespace Push
Namespace Local Ghost_MoveItem ;<- Unique name, This is handy because you can tell when your script is where by #Nsname
set !Itemid %1
set !Amount %2
set !ItemBox %3 ; ! Variables Are Unique to the NameSpace
Finditem !Itemid C_ , #backpackid
if #Findcnt > 0
{
Exevent drag !ItemID !Amount
Exevent Dropc !ItemBox
Wait 20
}
NameSpace Pop
Return

When you wanted to use that Sub you would do

Gosub MoveItem (ID) (Amount) (Drop Bag ID)
Title: Re: FindItem timer
Post by: Grandewd on September 16, 2013, 11:17:20 AM

@manwinc ^^^^^^

Great, simple example of namespace usage.... Thx  ;)