ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Paulonius on May 20, 2010, 06:11:17 AM

Title: Dragging and Pathfinding
Post by: Paulonius on May 20, 2010, 06:11:17 AM

I know that attempting to move while dragging an item is a good way to crash the client.  Can anyone tell me what the recommended waits should be on either side of a pathfind that has a drop/drag on either side of it?
Title: Re: Dragging and Pathfinding
Post by: _C2_ on May 20, 2010, 08:20:32 AM
how about looking for the item in the bag it was intended to be dropped in before leaving the sub or an increase in #findstack or #findcnt.  That would be the most stable across all diff connection speeds.  Just a diff way of thinking about it.

Maybe even uses the #lliftid or whatever the command is for if something is on the drag cursor still...
exevent dropc %place
while #(item still on cursor command) = 1
  wait 0
Title: Re: Dragging and Pathfinding
Post by: Cerveza on May 20, 2010, 08:28:09 AM
Won't exactly work with that while.... what happens if it's still on your cursor? You just wait 0 forever (or till you get discon'd).

Some type of a repeat check would be best I'd think...
Title: Re: Dragging and Pathfinding
Post by: Scrripty on May 20, 2010, 09:00:44 AM
Yea but that's the general idea.  The best way I think I've found for me at least, is to use a secondary script for looting.  And integrate it into the main script, so it's constantly looking for bodies.  Then have checks for healing and such.  And if your main script is performing an action, have the looting pause until it's finished.  Then I put in checks to make sure there's nothing on the cursor like C2 said.  And make sure the script doesn't try to move while there's an unignored body on the ground, and while you're looting.  I finally have got around to doing a basic looter, and it's amazing how tightly you can integrate it into another script if you're carefull.  My xhealer will xheal 2 chars, and attack spawn, and my looter will loot 99 percent of everything I want off of bodies while the script is healing/attacking without error.  I've had one crash while moving in about 2 weeks of farming in level 3 like spawn conditions...  That aint bad.  And it moves/fights/loots faster than anybody could ever do it by hand.  Script one:  Check for spawn, move to bodies, loot, move on a rail.  Script 2, xheal/attack spawn.  I think it works shockingly well. :)  The way I keep the speed up is by doing double checks for loot on body.  If I try to loot something, and a bandaid interrupts the looting, I check again to see if the item is still on the corpse.  So I never miss a thing.  Then the script pauses, lets the heal finish, then finishes looting.  You only have to pause for a split second while xhealing, so you can basically loot while xhealing if you use a "read/write" sort of check.  Sort of like in the waypoint pathfinder.  If someone wants an example I can post one.  It's pretty interesting stuff. heh  Hard to get perfect and keep speed and errors right.
Title: Re: Dragging and Pathfinding
Post by: Paulonius on May 20, 2010, 09:10:32 AM
The script I am working on doesn't work in an environment as chaotic as a looter in a spawn.  I am just making sure that I keep an NPC vendor within reach whilst dropping things on him. My current code positions the toon and starts the process. It does a check between drops to confirm the NPC is still within two tiles, and pathfinds if the NPC moves outside that check.  I had no wait in between the previous drop, the check, and the pathfind, if they were to all hit, and I think that was causing my occassional crashes.  The cursor-check/item-drop snippet check you are suggesting is probably a good way to bullet-proof the routine -- but my instinct is that a wait 10 in there might be plenty stable. 

However, it sounds like it should be possible to write a code snippet that confirms that you don't have anything on the cursor, and drops it (in your pack?) if you do, that would eliminate the crash issue in pretty much every potential application.  Any of you experts care to hazard a slice at the sub that makes that check?   While I am asking, is there a way to check if there is a booger on my cursor?
 
Title: Re: Dragging and Pathfinding
Post by: Paulonius on May 20, 2010, 09:22:44 AM
Maybe something like this?:

Code: [Select]
Sub Item_Drag_Check
Finditem #LLiftedID C_ , %Source
If #FindCnt > 0
    Return #True
Finditem #LLiftedID C_ , %Target
If #FindCnt > 0
    Return #True
exevent dropc %Source
Wait 15
Return #False

I would want it dropped back in the source (#Backpack) in this instance, but it might be preferable to drop it somewhere else in another context.  Using this I would only be initiating a wait if it really needed one.  I can also see wanting to loop back into the checks in some scenarios.  Wouldn't be that helpful in mine since the trigger for going here is that I can't reach the target, and in any event successfully hitting the target consumes the thing I am dragging...

My "booger on my cursor" question was me wondering whether there is anything in EUO that gives an indication that the cursor is carrying something.  

I suppose even more generally useful would be the two checks with a #False/#True return.  If it comes back #False I try the dropc and wait -- #True I am good to go into the pathfind.

Code: [Select]
Sub Item_Drag_Check
Finditem #LLiftedID C_ , %Source
If #FindCnt > 0
    Return #True
Finditem #LLiftedID C_ , %Target
If #FindCnt > 0
    Return #True
Return #False
Title: Re: Dragging and Pathfinding
Post by: Scrripty on May 20, 2010, 11:11:51 AM
Is there a way to get a vendor to stop moving?  Say... saying vendor buy?  Not sure that works, but worth a try.  Then you could go "vendor buy" he'd turn around and listen, right click the menu, and drag/drop your stuff on him?  I don't know if that works, but worth a try to see if they stop moving when engaged in a transaction...
Title: Re: Dragging and Pathfinding
Post by: Paulonius on May 20, 2010, 12:08:35 PM
Nail their shoes to the floor maybe?

They do stop moving for the most part while you are performing transactions.  After 20 or so transactions, they tend to take a step now and again. 
Title: Re: Dragging and Pathfinding
Post by: manwinc on May 20, 2010, 02:23:31 PM
Just put a

Finditem %Vendor
if #findcnt > 0
{
While #finddist > 2
{
event pathfind #findx #findy #findz
wait 20
finditem %Vendor
}
}
Title: Re: Dragging and Pathfinding
Post by: Paulonius on May 20, 2010, 03:04:10 PM
That is almost precisely the code that is crashing -- I have a wait 30 where you have a wait 20.

I believe it crashes when it tries to drop on the NPC, the NPC moves outside the two tiles, and then the script tries to follow the NPC too quickly after the drop.  I am betting a wait 10 before the pathfind would eliminate most crashes, but thought I would talk it through with folks to see if anyone had a better solution.


Title: Re: Dragging and Pathfinding
Post by: Scrripty on May 20, 2010, 03:21:01 PM
No what you need is a repeat...until after the pathfind.  repeat.. until #charposx = #findx && #charposy = #findy.  Because the script continues to execute after the pathfind unless you force it to wait.  The while probly works but the repeat guarantees it works. :)
Title: Re: Dragging and Pathfinding
Post by: manwinc on May 20, 2010, 03:23:08 PM
Then you will need excessive waiting when dropping.

Exevent drag #findid
wait 20
exevent dropc %Bod_Book
wait 20
Title: Re: Dragging and Pathfinding
Post by: Paulonius on May 20, 2010, 04:20:12 PM
I think you guys are right. I looked at the code again and I don't have a conditional ending the pathfind, so the crash is almost certainly caused by the script still trying to pathfind while it goes to execute the next drop -- in which case the fix I was going to put in would accomplish nothing.

Thanks for the help gentlemen!
Title: Re: Dragging and Pathfinding
Post by: manwinc on May 20, 2010, 04:35:23 PM
NO problem!
Title: Re: Dragging and Pathfinding
Post by: baldielocks on June 18, 2010, 05:25:24 PM
If someone wants an example I can post one.  It's pretty interesting stuff. heh  Hard to get perfect and keep speed and errors right.

I would appreciate that, since that is close to my own project. Plus the item on cursor check. Oddly, you can cast heal with an object on cursor and last target, but not bandage. I think the cursor actually holds a ghost bandage while applying (but I AM a newb). I am suspending band-aid healing, but enabling cast healing during looting (once I get the conditions set better).