Scripting Resources & Utilities > UO Machine Corner

Loot Script

(1/1)

darklotus:
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: ---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;
        }

    }
}

--- End code ---

Masscre:
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.

darklotus:
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.

TrailMyx:
I haven't heard from Xenoglyph for a while.  I actually emailed him a while ago, but never heard back..

Navigation

[0] Message Index

Go to full version