ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: declo on February 22, 2017, 06:11:42 PM

Title: Looting Issue
Post by: declo on February 22, 2017, 06:11:42 PM
I am trying to to write a bird killer/leather looter script.

The kill sub is working but I can't get the loot to work.  The corpse opens, and then its hidden, but it does not drag the feathers off the corpse.

Any suggestions?

Quote
;========================================
;  Check Corpse
;========================================
sub chkcrpse
milky:
finditem YFM G_3
if #findkind = -1
   {
    return
   }
set %dead #findid
set #ltargetid #findid
set #ltargetkind 1
finditem %knife C_ , #backpackid
set #lobjectid #findid
event macro 17 0
target 1s        ;3s
event macro 22 0
wait 20


finditem %dead
set #lobjectid #findid
event macro 17 0
wait 1s


finditem VLK C_ , %dead
wait 1s
exevent drag #findid #findstack
wait 1s
exevent DropC %rbag
wait 1s
ignoreitem %dead
hideitem %dead
goto milky:


Title: Re: Looting Issue
Post by: TrailMyx on February 22, 2017, 06:19:23 PM
What you are seeing is what OSI calls "instanced" corpses.  What you need to do is find the corpse, wait a little bit, and then find the corpse again to get the "true" #FINDID. 

Code: easyuo
  1.   finditem YFM G_2
  2.   if #FINDKIND <> -1
  3.   {
  4.     wait 5
  5.     finditem YFM G_2
  6. ; do you looting thing with the resulting #FINDID
  7.   }
  8.  
Title: Re: Looting Issue
Post by: BobOzarius on February 22, 2017, 08:14:44 PM
Or wait for the container and use it's id. The corpse id and the container id can be different. Sometimes they are the same. Sometimes they are not. On OSI anyways. Probly due to instanced corpses. But I've seen it happen during solo pvm and when you'd think instanced corpses would be a problem with multiple people attacking the same monster. You're using the corpse id for the container id, which isn't always the same thing. Just assume that the corpse id is different from the corpse container id, and write your script to assume that also and your problems should go away.
Title: Re: Looting Issue
Post by: declo on February 23, 2017, 02:10:27 PM
Or wait for the container and use it's id. The corpse id and the container id can be different. Sometimes they are the same. Sometimes they are not. On OSI anyways. Probly due to instanced corpses. But I've seen it happen during solo pvm and when you'd think instanced corpses would be a problem with multiple people attacking the same monster. You're using the corpse id for the container id, which isn't always the same thing. Just assume that the corpse id is different from the corpse container id, and write your script to assume that also and your problems should go away.


Some something like this?

Quote
IF #CONTTYPE = YFM
   {
   set %corpse #contid
   }
Title: Re: Looting Issue
Post by: The Ghost on February 23, 2017, 02:31:25 PM
maybe this, this is not tested

Code: easyuo
  1.  
  2. finditem %corpseID G_2
  3. if #findkind = -1
  4.       Return
  5. set #lobjectid #findid
  6. event macro 17 0
  7. ignoreitem #findid
  8.  
  9. IF #CONTTYPE = YFM
  10.    set %corpse #contid
  11. FINDITEM %itemtype C_ , %corpse
  12. Event Drag #findid
  13. Exevent dropc #BACKPACKID
  14.  wait 30
  15.  
  16.  
Title: Re: Looting Issue
Post by: BobOzarius on February 23, 2017, 04:53:01 PM
You also probly need to account for the timing of instanced corpses, which this does not do. You'd have to loot it once at the beginning, and then again after a couple minutes when the other corpses become un-instanced. (Is that a word?)  Or if you're finding corpses nonstop, instead of looting it twice, find the corpse, set it to an instanced timer, then loot it just once when it combines the instances. But if you're competing with others, probly better to just loot it twice. So you get your items at least. That %contWait timer probly needs some tweaking also. It looks like it would work correctly, but I'm not sure. It seems to wait as long as it takes for a corpse to open, plus 100ms. But is that too long? After opening a corpse with event macro 17, you have to wait at least 1000ms on OSI to perform another action. That's something to consider. That's why I made the timer 1100. But what if the container opens in 500 ms, you'd have a spare 500 ms you'd have to wait before performing an action, so you'd have to account for that somewhere.

Code: easyuo
  1. set %corpseContSize ; Set this to whatever size the container is for a corpse on your shard
  2. set %corpseLooted n/a
  3. finditem %corpses G_2
  4. if #findcnt > 0
  5. {
  6.   set #lobjectid #findid
  7.   set %contid #contid
  8.   event macro 17
  9.   set %contWait #sysTime + 1100
  10.   while #contsize <> %corpseContSize || #contid = %contid
  11.   {
  12.     if #contid <> %contid
  13.     {
  14.       wait 5
  15.       break
  16.     }
  17.   }
  18.   if %contWait < #sysTime  
  19.   {
  20.     set %corpseLooted #false
  21.     return  ; Return on container error
  22.   }
  23.   set %corpseContId #contid
  24.   finditem %itemTypes c_ , %corpseContId
  25.   {
  26.     if #findcnt > 0
  27.     {
  28.       ; Find and loot whatever you want here
  29.       set %corpseLooted #true
  30.     }
  31.   }
  32.   if %corpseLooted = #true
  33.     ignoreitem %contid
  34. }
Title: Re: Looting Issue
Post by: declo on February 23, 2017, 05:32:08 PM
TY Ghost & BobOz!
Title: Re: Looting Issue
Post by: declo on February 23, 2017, 05:44:19 PM
Ummm, how would I go about carving the corpse?  Would I open, carve, and open it again?
Title: Re: Looting Issue
Post by: valen2.0 on February 23, 2017, 05:46:30 PM
I may be wrong but, I think it would be more efficient if you carve the corpse first. because once you carve it will automatically close the corpse
Title: Re: Looting Issue
Post by: declo on February 23, 2017, 05:49:17 PM
Maybe between line 7 & 8? 
Title: Re: Looting Issue
Post by: valen2.0 on February 23, 2017, 05:53:17 PM
If you put it there I would make a sub to simply use a knife or the butchers cleaver and try it. I am not sure if it will work because it may reset your last object.
Title: Re: Looting Issue
Post by: declo on February 23, 2017, 05:56:48 PM
To setup gump size, is this correct?

Quote
set %corpseContSize 144_212

for OSI
#Contsizex: 144
#Contsizex: 212

Sorry, trying to learn
Title: Re: Looting Issue
Post by: valen2.0 on February 23, 2017, 05:59:55 PM
I am too, that's what I have in my notes for setting up #contSize = yournumber_yournumber
Title: Re: Looting Issue
Post by: declo on February 23, 2017, 06:20:13 PM
So I tried this:

Code: easyuo
  1. set %corpseContSize 144_212; Set this to whatever size the container is for a corpse on your shard
  2. set %corpseLooted n/a
  3. set %itemTypes VLK
  4. set %corpses YFM
  5.  
  6. finditem %corpses G_2
  7. if #findcnt > 0
  8. {
  9.   set #lobjectid #findid
  10.   set %contid #contid
  11.   event macro 17
  12.   set %contWait #sysTime + 1100
  13.   while #contsize <> %corpseContSize || #contid = %contid
  14.   {
  15.     if #contid <> %contid
  16.     {
  17.       wait 5
  18.       break
  19.     }
  20.   }
  21.   if %contWait < #sysTime
  22.   {
  23.     set %corpseLooted #false
  24.     return  ; Return on container error
  25.  

but it is stuck in the loop

Code: easyuo
  1.   set %contWait #sysTime + 1100
  2.   while #contsize <> %corpseContSize || #contid = %contid
  3.   {
  4.     if #contid <> %contid
  5.     {
  6.       wait 5
  7.       break
  8.     }
  9.   }
  10.   if %contWait < #sysTime
  11.   {
  12.     set %corpseLooted #false
  13.     return  ; Return on container error
  14. [/quote]
  15.  
  16.  
Title: Re: Looting Issue
Post by: valen2.0 on February 23, 2017, 06:44:19 PM
Where exactly is it getting stuck? did you step through it?
Title: Re: Looting Issue
Post by: godfetish on February 23, 2017, 07:17:42 PM
If #contid = %contid the while loop is an infinite loop. Maybe that is where you are getting stuck?
Title: Re: Looting Issue
Post by: BobOzarius on February 23, 2017, 08:10:12 PM
I set a timer for it to break out, but forgot to add the time to actually break out of the while loop if it triggers.  ;)  It's there. You'll see it. Just above the while. if %contWait < #sysTime break needs to be INSIDE the while loop.  Oops.  ;)
Title: Re: Looting Issue
Post by: The Ghost on February 24, 2017, 02:56:12 AM
Here one of my sub when I use to gather leather.

Code: easyuo
  1. ; ----------------------------------------------------
  2. ;                gatherLeather
  3. ;-------------------------------------------------------
  4. sub TG_gatherLeather
  5. set %itemtype YFM
  6.  
  7.  
  8. finditem %itemtype G_9
  9. repeat
  10. event pathfind #findx #findy #charposz
  11. wait 2s
  12. if #findkind = -1
  13. {
  14. return
  15. }
  16.  
  17. finditem KFR_HFR C_ , #backpackid   : harvest Blade , Butcher Knife
  18. if #findkind = 1
  19. set #lobjectid HFR
  20. set #lobjectid #findID
  21. event macro 17
  22. wait 10
  23. finditem %itemtype G_2
  24. set #ltargetid #findid
  25. set #ltargetkind 1
  26. event macro 22
  27. ignoreitem #findid
  28. wait 1s
  29. {
  30.  gosub unloadbase
  31. }
  32. return
  33.  
  34. ; -----------------------------------------------------
  35.  
  36.  
Title: Re: Looting Issue
Post by: BobOzarius on February 24, 2017, 05:22:33 AM
     It's bad practice to have a repeat without an until. Also, your wait timers don't allow for any error at all. So your character would be walking all over the place. To every corpse. What if the corpse was 9 tiles away? Is 2 seconds enough time while walking? Maybe. What if you lag? Having that wait 10 after the event macro 17 isn't very efficient either. It's a better idea to set a wait timer, over what it would normally take for a corpse to open, and detect if the #contid has changed. Because no 2 corpse container ids will be alike. Then on error, you can break out of that loop while you wait. What if the corpse doesn't open for some reason? Then you wait that 10, and continue through the code like an error never occurred. Which it did... That's not a good idea. You should look at mine for a better idea of how to do it. I actually put in a return for a corpse cont error so it will not continue to execute code if the container doesn't open. That also will fix missing corpses, because it won't ignore that corpse if it errors and it will reloot that corpse again. It's just more logical.

     Plus #findkind is oldschool.  ;)  #findcnt is better.  That's a very basic wait to handle cutting corpses. Now that I wrote all that, I'll write corpse cutting into mine to show you. Another issue you have, is you are doing a finditem every loop for tools, when that isn't needed. It's fine, just slows things down needlessly, when you start writing larger scripts that will matter. And this code should now account for all timings from actions performed in the script itself, so outside of this code, no timing should be needed to use it. It's all taken care of in the looting code itself. You could probly just do a gosub loot and put that code into that, with the variables at the top of the script and it would work fine.

Code: easyuo
  1. set %cutCorpse #true
  2. set %knife ; Set this to any knives or corpse cutting tool
  3. if %cutCorpse = #true
  4. {
  5.   finditem %knife c_ , #backpacked
  6.   if #findcnt > 0
  7.     set %knifeTool #findid
  8.   else
  9.     display ok Tool not found! Get a tool!
  10. }
  11. set %targetTimer #sysTime
  12. set %corpseContSize 144_212; Set this to whatever size the container is for a corpse on your shard
  13. set %corpseLooted n/a
  14. set %itemTypes VLK
  15. set %corpses YFM
  16.  
  17. repeat
  18. finditem %corpses G_2
  19. if #findcnt > 0
  20. {
  21.   set %corpse #findid
  22.   set %contid #contid
  23.   if %cutCorpse = #true
  24.   {
  25.     set #lobjectid %knifeTool
  26.     if #targCurs = 1
  27.     {
  28.       set #targCurs 0
  29.       wait 5
  30.     }
  31.     event macro 17
  32.     set #ltargetkind 1
  33.     set %targetTimer #sysTime + 1000
  34.     while %targetTimer > #sysTime && #targCurs = 0
  35.     {
  36.     }
  37.     if #targCurs = 1
  38.     {
  39.       event macro 22
  40.       while %targetTimer > #sysTime
  41.       {
  42.       }
  43.     }
  44.   }
  45.   while %targetTimer > #sysTime
  46.   {
  47.   }
  48.   event macro 17
  49.   set %contWait #sysTime + 1100
  50.   while #contsize <> %corpseContSize || #contid = %contid
  51.   {
  52.     if #contid <> %contid
  53.     {
  54.       wait 5
  55.       break
  56.     }
  57.   }
  58.   if %contWait < #sysTime
  59.   {
  60.     set %corpseLooted #false
  61.     while %contWait > #sysTime
  62.     {
  63.     }
  64.     return  ; Return on container error
  65.   }
  66.   set %corpseContId #contid
  67.   finditem %itemTypes c_ , %corpseContId
  68.   {
  69.     if #findcnt > 0
  70.     {
  71.       ; Find and loot whatever you want here
  72.       set %corpseLooted #true
  73.     }
  74.   }
  75.   if %corpseLooted = #true
  76.     ignoreitem %contid
  77.   while %contWait > #systime
  78.   {
  79.   }
  80. }
  81. until #false
Title: Re: Looting Issue
Post by: declo on February 28, 2017, 02:28:01 PM
The purpose for using finditem each time is that on a certain shard "SP" daggers or knifes wear out after so many uses.  So be using in each loop, if the previous item is destroyed, it uses a new item to continue one.

Just an FYI