Author Topic: Problem with looting script  (Read 5179 times)

0 Members and 1 Guest are viewing this topic.

Offline Alex MarsTopic starter

  • Newbie
  • *
  • Posts: 5
  • Activity:
    0%
  • Reputation Power: 0
  • Alex Mars has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Problem with looting script
« on: April 30, 2012, 03:24:10 AM »
0
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?

Code: [Select]
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!

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Problem with looting script
« Reply #1 on: April 30, 2012, 09:30:31 AM »
0
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:

Code: [Select]
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 -

Code: [Select]
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
« Last Edit: April 30, 2012, 09:34:27 AM by 12TimesOver »
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Problem with looting script
« Reply #2 on: May 01, 2012, 12:47:47 AM »
0
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

Code: [Select]
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.

Code: [Select]
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.

Code: [Select]
Gosub Mwinc_Drag_Drop #Findid #Findstack
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Problem with looting script
« Reply #3 on: May 01, 2012, 06:25:45 AM »
0
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
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Problem with looting script
« Reply #4 on: May 01, 2012, 10:11:47 AM »
0
Yeah, looting corpses is definitely not at the top of my "Fun Things I like to Script" list.
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Problem with looting script
« Reply #5 on: May 01, 2012, 10:19:36 AM »
0
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:

Code: [Select]
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.
« Last Edit: May 01, 2012, 10:22:59 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Alex MarsTopic starter

  • Newbie
  • *
  • Posts: 5
  • Activity:
    0%
  • Reputation Power: 0
  • Alex Mars has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Problem with looting script
« Reply #6 on: May 01, 2012, 12:46:42 PM »
0
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

Tags: Looting