ScriptUO
Official ScriptUO EasyUO Scripts => Script Debug => Topic started 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.
if if #weight >= %mxwt
return #true
FindItem %item C_ , #backpackid
if #FINDCNT > 0
gosub moveitem
FindItem %item C_ , %itembox
if #FINDCNT > 0
gosub makeitem
-
Nope, no wait necessary.
-
Thx TM
here a new one. Can I make this faster.
sub move item
finditem %item C_ , #backpackid
exEvent Drag #findID %stack
exevent dropc %itembox
wait 20
if #FindCnt > 0
gosub moveitem
return #true
-
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.
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.
-
Thx Manwinc, Thx for the exemple.
Just notice that I copy an old sub :( This is the one I'm using now.
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.
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
-
Namespace Push Just puts Your Last namespace into a "Save", so when you do Namespace POP, it reloads the Namespace.
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.
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.
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.
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)
-
@manwinc ^^^^^^
Great, simple example of namespace usage.... Thx ;)