ScriptUO
		Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Alex Mars on April 30, 2012, 03:24:10 AM
		
			
			- 
				Hello guys,
I could use some help here. Basically I want pickup everything from a corpse from a monster I kill. I run my lil script, it opens corpse... and nothing. If I wait 2..3 mins, so the corpse goes public it loots the corpse clean as intended. What did I wrong?
start: 
finditem YFM G_2 
if #findid <> x 
   { 
   ignoreitem #findid 
   gosub body 
   } 
goto start: 
 
sub body 
;set %body #findid 
set #lobjectid #findid 
nextcpos 15 15 
event macro 17 
wait 15 
finditem * C_ , %body 
for %i 1 #findcnt 
{ 
finditem * %i C_ , %body 
event drag #findid 
if #findstack > 1 
   msg $ 
wait 10 
click 155 770 p 
ignoreitem #findid 
wait 15 
} 
return
Thanks in Advanche!
			 
			
			- 
				Howdy Alex -
Have you stepped through your logic using F7 etc to see where your logic is off? That can be extremely helpful.
My first question is your loop:
start: 
finditem YFM G_2 
if #findid <> x
   { 
   ignoreitem #findid 
   gosub body 
   } 
goto start:
So what you're saying here is:
1) To find a corpse within 2 tiles - fine
2) If you find one, and it's #findid isn't x - umm, well this does work although you may be better off using #findkind
3) Ignore what you just found - huh?
4) Now go to the body sub
Then, in the body sub, you're setting #lobjectid but you've commented out anything that sets your %body variable.
I'm thinking you might want to look at a few things, here is something similar (untested though, I'm at work). First, I got rid of the Goto - coder preference ;) you can still use if you'd like! Next, you find the item then immediately set a variable to that itemid. Away to the sub you go and when you return you ignore that variable and go back to looping.
While in the sub you can your backpackid so you don't need the yucky click command. I also set your lastobject to your actual %Body variable for consistency. Then, I replaced your events with exevent including the dropc replacing the click, just a little nicer this way - less likely to give you issues. Finally, I threw in a little loop that says "keep looking through this corpse (finditem) and drag any item or stack you find (exevent drag #findid #findstack) to my backpack (exevent dropc #backpackid) until there is nothing left (Until #findkind = -1). Then return to the findcorpse loop.
Check it out -
Repeat
   finditem YFM G_2 
   if #findkind <> -1
      { 
      set %Body #findid
      gosub Body
      ignoreitem %Body
      } 
Until #FALSE
 
sub Body 
   set #lobjectid %Body
   nextcpos 15 15 
   event macro 17 
   wait 15 
   repeat
      finditem * C_ , %Body
      exevent drag #findid #findstack
      wait 10 
      exevent dropc #backpackid
      wait 15
   Until #findkind = -1
return
Does this make sense?
Feel free to fire away!!
X
			 
			
			- 
				Only issue is that A Corpses "#Contid" and its #Findid Are sadly not one and the same. So, when you look for objects in the corpses id, you find nothing....... 
Typically its easier to simply Attempt to open the corpse, then just look for all Items you wish to loot in all containers, ignoring things in your backpack :P. There is plenty of code around to get the Proper ID For the "Container", but if you are going to go as far as to use that, you may as well just use the claw :P
Repeat
Finditem YFM G_2 
if #Findcnt > 0 
{
set %Corpse #findid
Gosub Loot
Ignoreitem #Findid 
}
Until Booyah
Sub Loot
set #Lobjectid %Corpse 
Event macro 17 0 
Wait 25
Finditem %Stuff C 
For #Findindex 1 #Findcnt 
{
if #Contid = #Backpackid 
Continue 
Gosub Mwinc_Drag_Drop #Findid #Findstack 
}
Return
Here is Something Handy for you, should help with the crashing of Exevent drag. This is custom cut and specifically for dragging objects from outside your backpack/paperdoll into your bag. 
Sub Mwinc_Drag_Drop 
Namespace Push 
Namespace Local Mwinc_Drag_Drop 
set !Weight #Weight
Exevent drag %1 %2 
Gosub Wait_Var 20 #Weight <> !Weight
if #Weight <> !Weight
Exevent dropc #Backpackid
wait 22
Namespace Pop 
Return
Sub Wait_Var
  Namespace Push
  Namespace Local Mwinc_Wait_Var
  set !LPC #Lpc 
  set #lpc 9999
  set !Time_Limit #scnt2 + %1
  set !Cont_Check # . %4
  Repeat
    set !Cont_Check # . %4
    wait 1
  Until %2 %3 !Cont_Check || !Time_Limit < #scnt2
  if !Time_Limit <= #scnt2
  {
    set #Lpc !LPC
    Namespace Pop
    Return #true
  }
  set #Lpc !LPC
  Namespace Pop
Return #False
Here is a sample for how to use it once you have found the item you want to move. 
Gosub Mwinc_Drag_Drop #Findid #Findstack  
			 
			
			- 
				
Only issue is that A Corpses "#Contid" and its #Findid Are sadly not one and the same. So, when you look for objects in the corpses id, you find nothing....... 
Good catch there MW, my example wouldn't quite have cut it.
Between the stuff I posted and the stuff MW posted, Alex, you should be good to go!!
X
			 
			
			- 
				Yeah, looting corpses is definitely not at the top of my "Fun Things I like to Script" list.
			
 
			
			- 
				If you peel the CLAw open a bit, there's a subroutine that computes what the #CONTID should be from the corpse ID.  It's pretty bullet-proofed after many iterations with Kham and his testing.  Should be easy to stub into any looting script to mitigate the pain.
In fact, here's the routine:
sub OpenContainer
  namespace push
  namespace local OC
  set %container_delay 20
  set !body %1
  set !temp_cnt #SCNT + 12
  set !container_timeout 5
  
  repeat
    namespace copy TM_HEAL from global TM_healer
    if !TM_HEAL = #TRUE
      wait 20
    if #SCNT > !temp_cnt
    {
      namespace pop
      return #TRUE
    }
  until !TM_HEAL <> #TRUE && #LLIFTEDKIND = 0 && #TargCurs <> 1 && A notin #CHARSTATUS
  
  gosub TM_AdvJournalSync DRAG
  
  set #LOBJECTID !body
  set !temp_contid #CONTID
  set !temp2_cnt #SCNT + 5
  event macro 17 0
  repeat
  until #CONTID <> !temp_contid || #SCNT > !temp2_cnt
  set !temp_cnt #SCNT + !container_timeout
  set !open_retry_cnt #SCNT + 2
  repeat
    set !sample_contid #CONTID
    gosub TM_AdvJournalScan DRAG VALID you_must_wait
    if #RESULT = #TRUE || #SCNT > !open_retry_cnt
    {
      gosub TM_AdvJournalSync DRAG
      wait 20
      set #LOBJECTID !body
      set !temp_contid #CONTID
      set !temp2_cnt #SCNT + 5
      event macro 17 0
      repeat
      until #CONTID <> !temp_contid || #SCNT > !temp2_cnt
      set !temp_cnt #SCNT + !container_timeout
      set !open_retry_cnt #SCNT + 2
      continue
    }
    gosub TM_AdvJournalScan DRAG VALID you_did_not_earn that_is_too_far that_is_out_of_sight reach
    if #RESULT = #TRUE
    {
      gosub TM_AdvJournalSync DRAG
      namespace pop
      return #TRUE ; impossible to open this container - forget it
    }
    str del !sample_contid 1 4
  until ( ( ( #STRRES in !body ) || ( #SCNT > !temp_cnt ) ) && !temp_cnt <> #CHARID )
  
  if #SCNT > !temp_cnt
  {
    namespace pop
    return #FALSE ; not a fatal error, can try and open again
  }
  
  wait %container_delay
  set %ignored_containers %ignored_containers , _ , !sample_contid
  set #RESULT !sample_contid
  namespace pop
return #RESULT
The returned value is the #CONTID of the corpse (or whatever container).  Can also return #TRUE or #FALSE.  #TRUE means the container is impossible to open and should be ignored.  #FALSE means the container can probably be opened i.e. It's out of range.
Finally, the subroutine maintains a running list of containers that were successfully opened.  %ignored_containers contains all containers that were opened so you can ignore them.
note you need my journal handling subs for this to work as intended.
			 
			
			- 
				Ahh, thank you all for your clear explanations! I'm always a bit hmm.. reluctant? using other scripts. More fun trying it for myself, even if i reinvent the wheel. Looking at "claw" and that sub 12timesover wrote, those are nifty! Much to learn here, just from stepping through, thanks again.
Alex