Author Topic: Loot Script  (Read 23841 times)

0 Members and 1 Guest are viewing this topic.

Offline darklotusTopic starter

  • Newbie
  • *
  • Posts: 3
  • Activity:
    0%
  • Reputation Power: 1
  • darklotus has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Loot Script
« on: December 18, 2010, 02:16:45 AM »
0
Update of the sample loot script to work with latest uomachine.

Rather nice app, Its a pity work stopped as the latest client and latest razor fail to work with it.
Memory editing is my weakest point, so i havnt worked out how to fix the offsets yet.

Code: [Select]
using System;
using System.Threading;
using UOMachine;
using UOMachine.Macros;
using UOMachine.Data;
using UOMachine.Utility;
using UOMachine.Events;
using System.Collections.Generic;

namespace UOMScript
{
    public class Script : IScriptInterface
    {
        private bool myScriptRunning = true;
        private PlayerMobile myPlayer;
        private const int myClient = 0, myActionDelay = 650;
        private static string[] EUOLootTypes = { "POF", "ZLF", "RWF", "OZF", "LZF" };
        private int[] LootTypes = { 3821, 3903, 3617 } ;
        private Item LootBag;
        private DateTime myLastActionTime;
        private int myTargetCorpse;
        private int targetCorpse
        {
            get { return Thread.VolatileRead(ref myTargetCorpse); }
            set { myTargetCorpse = value; }
        }
        public void Start()
        {
            IncomingPackets.ContainerContentsEvent +=new IncomingPackets.dContainerContents(IncomingPackets_ContainerContentsEvent);
            IncomingPackets.MobileDeathEvent +=new IncomingPackets.dMobileDeath(IncomingPackets_MobileDeathEvent);
            
            UOMachine.Macros.Macro.GetPlayer(myClient,out myPlayer);
            //myPlayer.GetEquippedItem(Layer.Backpack, out LootBag);
            if (!Macro.GetItem(myClient, 1077150318, out LootBag)) { Stop(); }
            UOMachine.Macros.Macro.Speak(0, Speech.Say, LootBag.Name);
            while (myScriptRunning)
            {
                //TODO: Implement functionality
                Thread.Sleep(5);
            }
        }
        public static int[] EUOToInt(string[] val)
        {
            List<int> outs = new List<int>();
            foreach (string s in val)
            {
                uint temp = EUOToInt(s);
                outs.Add(Convert.ToInt32(temp));
            }
            return outs.ToArray();
        }
        public static uint EUOToInt(String val)
        //Code by BtbN
        {
            val = val.ToUpper(); // Important!
            uint num = 0;
            for (int p = val.Length - 1; p >= 0; p--)
                num = num * 26 + (((uint)val[p]) - 65);
            num = (num - 7) ^ 0x45;
            return num;
        }
void  IncomingPackets_ContainerContentsEvent(int client, ItemCollection container)
{
    
    Item corpse;
    UOMachine.Macros.Macro.GetItem(client, container.Serial, out corpse);
    
if (corpse.ID == 8198)
            {
                Item[] goldItems;
                if (container.FindItems(LootTypes, out goldItems))
                {
                    
                    foreach (Item i in goldItems)
                    {
                        DelayAction();
                        MacroEx.DragItem(client, i.Serial, i.Count);
                        DelayAction();
                        Thread.Sleep(500);
                        MacroEx.DropItem(client, i.Serial, LootBag.Serial);
                        //myDropItem(i.Serial, LootBag.Serial);
                        
                        UOMachine.Macros.Macro.Speak(0, Speech.Say, "Looted:" + i.ID.ToString());
                    }
                }
                targetCorpse = 0;
            }
}
public static void myDropItem(int serial, int containerSerial)
{
    byte[] packet;
        packet = new byte[14];
        packet[10] = (byte)(containerSerial >> 24);
        packet[11] = (byte)(containerSerial >> 16);
        packet[12] = (byte)(containerSerial >> 8);
        packet[13] = (byte)(containerSerial);
        packet[0] = 0x08;
        packet[1] = (byte)(serial >> 24);
        packet[2] = (byte)(serial >> 16);
        packet[3] = (byte)(serial >> 8);
        packet[4] = (byte)(serial);
        packet[5] = 0xFF;
        packet[6] = 0xFF;
        packet[7] = 0xFF;
        packet[8] = 0xFF;
        MacroEx.SendPacketToServer(0, packet);
        
    
}
void  IncomingPackets_MobileDeathEvent(int client, int mobileSerial, int corpseSerial)
{
   Item i;
      UOMachine.Macros.Macro.Speak(client, Speech.Say, "Container event");
            if(UOMachine.Macros.Macro.GetItem(client,corpseSerial,out i))
            {
                double distance = UOMath.Distance(myPlayer.X, myPlayer.Y, i.X, i.Y);
                UOMachine.Macros.Macro.Speak(client, Speech.Say, "Container Opened" + distance);
                if (distance <= 2)
                {
                    targetCorpse = corpseSerial;
                    DelayAction();
                    MacroEx.UseItem(client, corpseSerial);
                    
                }
            }
}
private void DelayAction()
{
    if (myLastActionTime == null)
    {
        myLastActionTime = DateTime.Now;
        return;
    }
    TimeSpan t = DateTime.Now - myLastActionTime;
    int waitTime = myActionDelay - (int)t.TotalMilliseconds;
    if (waitTime > 0) Thread.Sleep(waitTime);
    myLastActionTime = DateTime.Now;
}
        public void Stop()
        {
            myScriptRunning = false;
            IncomingPackets.ContainerContentsEvent -= IncomingPackets_ContainerContentsEvent;
            IncomingPackets.MobileDeathEvent -= IncomingPackets_MobileDeathEvent;
        }

    }
}
« Last Edit: December 18, 2010, 02:22:47 AM by darklotus »

Offline Masscre

  • Gran Master Jester !!
  • Scripthack
  • *
  • Posts: 4615
  • Activity:
    0%
  • Reputation Power: 55
  • Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!
  • Gender: Male
  • Air Guitar Commander !!
  • Respect: +144
  • Referrals: 1
    • View Profile
Re: Loot Script
« Reply #1 on: December 18, 2010, 06:35:12 AM »
0
Thank you for the post, but you might also want to hop over to the intro area and upgrade your status by introducing yourself and telling us a little about yourself.

Offline darklotusTopic starter

  • Newbie
  • *
  • Posts: 3
  • Activity:
    0%
  • Reputation Power: 1
  • darklotus has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Loot Script
« Reply #2 on: December 22, 2010, 03:28:13 AM »
0
I was a little hasty posting, turns out uomachine appears to have issues in multiple areas tracking items and such. Been trying to wrap my head around the source slowly to work out what the issue is.

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: Loot Script
« Reply #3 on: December 22, 2010, 08:06:14 AM »
0
I haven't heard from Xenoglyph for a while.  I actually emailed him a while ago, but never heard back..
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: