[Orion] Mining for newbies (Minoc mine)

If you make a Client-side script you can publish it here for other players to use
Post Reply
Meliofaro
Novice Scribe
Posts: 6
Joined: Fri Aug 16, 2019 12:43 pm

[Orion] Mining for newbies (Minoc mine)

Post by Meliofaro »

Hey, i made a small script for Orion Client ( https://github.com/Hotride/OrionUO ) that should help newbies to get some resources =). You just need some shovel(s) in your pack and be in Minoc mine. Script mines some ore, when near weight limit - smelts it on forge in cave, and returns to mining. That's all, no keys, no portable forges, no fire beetles :) This scripts helped me to get some ingots for Tinkering, hope you like it.

Code: Select all

var config = {
	"maxWeight"  		: (Player.MaxWeight()-10), //Max Weight to unload
	"pickaxe"    		: "0x0F39", //Pickaxe type(pickaxe, shovel etc)
	"ore"				: "0x19B9",
	"forge"      		: "0x0FB1",
	"forgeScanDistance" : 20,
	"toolQty"    		: 1,        //To keep in bag
	"tileOffset" 		: 2,     // Radius to dig (X+-2, Y+-2)
};

var minePoints = {
	1 : {"x" : 2559, "y" : 496, "z" : 0},
	2 : {"x" : 2563, "y" : 489, "z" : 0},
	3 : {"x" : 2566, "y" : 482, "z" : 0},
	4 : {"x" : 2572, "y" : 484, "z" : 0},
	5 : {"x" : 2577, "y" : 481, "z" : 0},
	6 : {"x" : 2575, "y" : 477, "z" : 0},
	7 : {"x" : 2571, "y" : 477, "z" : 0},
};

function start()
{	
	init();	
	while(!Player.Dead())
	{
		for(var i in minePoints)
		{		
			Orion.Print('[i] Point '+i);		
			Orion.WalkTo(minePoints[i]["x"],minePoints[i]["y"], minePoints[i]["z"],0);
			for (var x = -config['tileOffset']; x <= config['tileOffset']; x++)
			{
				for (var y = -config['tileOffset']; y <= config['tileOffset']; y++)
				{
					mine(x,y);
				}
			}
		}
	}
}

function mine(x,y)
{
	Orion.Print("[i] Mining at offset X+"+x+" Y+"+y);
	while(!Player.Dead())
	{
	    if(checkTool())
	    {
	    	if(Player.Weight() >= config['maxWeight'] )
	    		smelt(Player.X(),Player.Y(),Player.Z());

	    	if(Orion.ValidateTargetTileRelative('mine', x, y))
	    	{
	    		if(Orion.HaveTarget())
	    			Orion.CancelWaitTarget();
	    		
	    		Orion.UseType(config['pickaxe']);	
	    		Orion.WaitJournal('Where do you wish', Orion.Now(), Orion.Now()+2000, 'me|sys');
				Orion.TargetTileRelative('mine', x, y, Player.Z());	    			    		
	    		var result = Orion.WaitJournal('You put some|You loosen some|There is no metal|Try mining|is too far|no line of|seen', Orion.Now(), (Orion.Now() + 7000), 'me|sys');	    	
	    		if(result && result.FindTextID()==2)
	    		{
	    			Orion.Print("[i] Tile depleted");
	    			Orion.Wait(300);
	    			break;
	    		}	    		

	    	}else{
	    		break;
	    	}    	
	    }else{ //Not enough tools
	    	break;
	    }
	//Main Loop
	}
}
function smelt(x,y,z){
	Orion.Print("[i] Smelting");
	var forgeSerial = Orion.FindType(config['forge'],-1,'ground','', config['forgeScanDistance']);
	if(forgeSerial)
	{
		var forge = Orion.FindObject(forgeSerial);
		if(forge)
		{			
			if(Orion.WalkTo(forge.X(),forge.Y(),forge.Z(),1))
			{
				var ores = Orion.FindType(config['ore'],-1, 'backpack');
				if(ores && ores.length > 0)
				{
					ores.forEach(function(items){
						Orion.UseType(config['ore']);
						Orion.WaitJournal("Select the forge", Orion.Now(), Orion.Now()+1000, 'me|sys');
						Orion.TargetObject(forgeSerial);
						Orion.WaitJournal("You burn away|You smelt", Orion.Now(), Orion.Now()+1000, 'me|sys');
						Orion.Wait(500);
					});
					//Back to spot
					Orion.WalkTo(x,y,z,0);
				}
			}
		}
	}
}
function checkTool()
{   
	var tools = Orion.FindType(config['pickaxe'], -1, 'backpack');
	if(tools && tools.length >= config['toolQty'])
	{
		//Orion.Print("[i] There is "+tools.length+" tools left");
		return true;
	}else{
		Orion.Print("[e] Not enough tools");		
		Orion.PlayWav("Alarm");
		Orion.PauseScript();				
		return false;
	}
}

function init()
{	

	if(Player.WarMode())
		Player.WarMode(false)

	Orion.Print("Initialization...");
}
User avatar
+Colibri
Administrator
Posts: 3958
Joined: Sat Feb 25, 2006 4:08 pm
Location: static void Main

Re: [Orion] Mining for newbies (Minoc mine)

Post by +Colibri »

First time I'm hearing of this client, i did some searching and this image came up https://i.ytimg.com/vi/NpgM53X7FjM/maxresdefault.jpg - excelsior brit bank :)
Looks like a cool way to tinker and get under the hood of how the game works, cool!
+Colibri, Administrator of UO Excelsior Shard

Don't know what the purpose of your life is? Well then make something up! ;)
(Old Colibrian proverb)
Meliofaro
Novice Scribe
Posts: 6
Joined: Fri Aug 16, 2019 12:43 pm

Re: [Orion] Mining for newbies (Minoc mine)

Post by Meliofaro »

+Colibri wrote:First time I'm hearing of this client, i did some searching and this image came up https://i.ytimg.com/vi/NpgM53X7FjM/maxresdefault.jpg - excelsior brit bank :)
Looks like a cool way to tinker and get under the hood of how the game works, cool!
There is a short video - it shows more :) https://www.youtube.com/watch?v=SEIVj7x6nsg
davethemage
Grandmaster Scribe
Posts: 89
Joined: Sun Aug 09, 2020 2:13 pm

Re: [Orion] Mining for newbies (Minoc mine)

Post by davethemage »

Looks similar to the lumberjacking one. I've done some slight modifications to take into account my BOH (which i just dump my raw ore into)
I won't bother to post the x/y coordinates as I have mapped out a lot of different mines in doing my modifications. (get them from the original code.)

Code: Select all

function start()
{   
   init();   
   while(!Player.Dead())
   {
      for(var i in minePoints)
      {      
         Orion.Print('[i] Point '+i);      
         Orion.WalkTo(minePoints[i]["x"],minePoints[i]["y"], minePoints[i]["z"],0);
         for (var x = -config['tileOffset']; x <= config['tileOffset']; x++)
         {
            for (var y = -config['tileOffset']; y <= config['tileOffset']; y++)
            {
              MoveOre(); //my str allows me to hold a full set of mining (400+ ore) hence no need to stop mining to move.  Just make sure that all ore has been moved before you start to mine again. 
               mine(x,y);
            }
         }
      }
   }
}

function mine(x,y)
{
   //Orion.Print("[i] Mining at offset X+"+x+" Y+"+y);
   while(!Player.Dead())
   {
       if(checkTool())
       {
          if(Orion.ValidateTargetTileRelative('mine', x, y))
          {
             if(Orion.HaveTarget())
                Orion.CancelWaitTarget();
             
             Orion.UseType(config['pickaxe']);   
             Orion.WaitJournal('Where do you wish', Orion.Now(), Orion.Now()+2000, 'me|sys');
            Orion.TargetTileRelative('mine', x, y, Player.Z());                          
             var result = Orion.WaitJournal('You put some|You loosen some|There is no metal|Try mining|is too far|no line of| cannot be seen| mine that', Orion.Now(), (Orion.Now() + 7000), 'me|sys');          
              if(result && (result.FindTextID()==6 || result.FindTextID()==7))
             {
             break;
             }
             if(result && result.FindTextID()==2)
             {
               // Orion.Print("[i] Tile depleted");
                Orion.Wait(300);
                break;
             }             

          }else{
             break;
          }       
       }else{ //Not enough tools
          break;
       }
   //Main Loop
   }
}
function MoveOre()
{
  var findItems0 = Orion.FindType('0x19B9', '0xFFFF', 'backpack', 'item');

	for(items in findItems0)
	{
		Orion.DragItem(findItems0[items], 0);
		Orion.Wait('300');
		Orion.DropDraggedItem('0x41C448BA');  // set this to your BOH, or pet or wherever you need. 
		Orion.Wait('500');
	}
}

function checkTool()
{   
   var tools = Orion.FindType(config['pickaxe'], -1, 'backpack');
   if(tools && tools.length >= config['toolQty'])
   {
      //Orion.Print("[i] There is "+tools.length+" tools left");
      return true;
   }else{
      Orion.Print("[e] Not enough tools");      
      Orion.PlayWav("Alarm");
      Orion.PauseScript();            
      return false;
   }
}

function init()
{   

   if(Player.WarMode())
      Player.WarMode(false)

   Orion.Print("Initialization...");
}
IGN: Edwin Roach
Owlish
Passer by
Posts: 2
Joined: Thu Dec 29, 2022 5:12 pm

Re: [Orion] Mining for newbies (Minoc mine)

Post by Owlish »

Hello guys! I'm pretty sorry, a lot of stuff has happened to me since the initial message. I've lost my email, my forum account, and my ingame account. But I'm thrilled that you enjoy my simple script! So, I've decided to improve it a bit, there is a bug in Orion with TargetTIleRelative in the Malas region, so, have fun!

Code: Select all

const _mining = {
	"verbose": true,
	//Max Weight to unload
	"maxWeight": (Player.MaxWeight() - 20),
	//Pickaxe type(pickaxe, shovel etc)
	"forgeScanDistance": 120,
	// Radius to dig (X+-2, Y+-2)
	"tileOffset": 2,
	"forges": {
		"locations": [
			// Add ur own forge locations!
			{ "x": 3 "y": 2, "z": 1 },
		]
	},
	"types": {
		"tinkerTool": 0x1EB8,
		"pickaxe": 0x0F39,
		"ore": 0x19B9,
		"ingot": 0x1BF2,
		"forges": [0x0FB1, 0x19A2, 0x1996],
	},
	"craftTools": {
		"enabled": true,
		"minimumTools": 4,
		"gumpButtons": {
			"tinkerTool": 23,
			"pickaxe": 72
		}
	},
	"unload": {
		"enabled": true,
		"unloadWeightLimit": Player.MaxWeight() - 100,
		"bankLocation": {
			"x": 1066,
			"y": 1458,
			"z": -83
		}
	},
	"skipTileMessages": [
		"too far",
		"seen",
		"no metal",
		"can't target"
	]
};

var minePoints = {
	1: { "x": 1, "y": 2 "z": 3 },
	// Add your own mine!
};

function craft(tool, button) {
	print("craft", "Craft button " + button + " with tool " + tool, true);
	Orion.UseType(tool);
	Orion.WaitGump(Orion.CreateGumpHook(button));
	if (Orion.WaitForGump(2000)) {
		Orion.WaitGump(Orion.CreateGumpHook("cancel"));
		Orion.Wait(2000);
	}
}

function craftTools() {
	["tinkerTool", "pickaxe"].forEach(function (tool) {
		while (Orion.Count(_mining["types"][tool]) < _mining["craftTools"]["minimumTools"]) {
			craft(_mining["types"]["tinkerTool"], _mining["craftTools"]["gumpButtons"][tool]);
			Orion.Wait(2000);
		}
	});
}


// #helpers/global.oajs
function ifFeatureFlagEnabled(flag, func) {
	if (_mining[flag]["enabled"]) {
		func();
	} else {
		Orion.Print("FeatureFlag for the function " + flag + " is disabled, skipping ection")
	}
}


function nearestForge() {
	print("nearestForge", "Looking for the nearest forge... ", true);
	var forges = {};
	_mining["forges"]["locations"].forEach(function (location) {
		var distance = Orion.GetDistance(location["x"], location["y"]);

		forges[distance] = location;

		print("nearestForge",
			"Range: " + distance + " Location: " +
			" X: " + location["x"] +
			" Y: " + location["y"] +
			" Z: " + location["z"], true);
	});

	const ranges = Object.keys(forges);
	const min = Math.min.apply(Math, ranges);
	print("nearestForge", "Ranges: " + Object.keys(forges), true);
	print("nearestForge", "Minimum : " + min, true);
	print("nearestForge",
		"Location: " +
		" X: " + forges[min]["x"] +
		" Y: " + forges[min]["y"] +
		" Z: " + forges[min]["z"], true);

	return forges[min];
}

// #helpers/global.oajs
function print(func, msg, debug) {
	var debug = debug === undefined ? false : true;
	if (_mining["verbose"] && debug) {
		Orion.Print(0x0006, "[DEBUG] [" + func + "] " + msg, true)
		return;
	}

	if (!debug) {
		Orion.Print(0x0035, "[" + func + "] " + msg);
	}


}

// #helpers/global.oajs
function ensureContainerOpened(serial, bank) {
	var isBank = bank === undefined ? false : true;
	var cnt = 0;
	print("ensureContainerOpened", "IsBank? " + isBank, true);
	while (cnt < 5) {
		cnt++;
		print("ensureContainerOpened", "Try #" + cnt, true);

		if (isBank) {
			Orion.Say("bank");
		} else {
			Orion.UseObject(serial);
		}

		Orion.Wait(1000);
		if (Orion.GetSerial("lastcontainer") == serial) {
			print("ensureContainerOpened", "Container " + serial + " opened", true);
			return true;
		}
		print("ensureContainerOpened", "Failed to open container " + serial, true);
	}

	return false;
}

function unload() {
	print("unload", "Unloading...", true)
	if (!ensureContainerOpened(Orion.ObjAtLayer("Backpack", Player.Serial()).Serial())) {
		return false;
	}

	if (!ensureContainerOpened(Player.BankSerial(), true)) {
		return false;
	}

	var ingots = Orion.FindType(_mining["types"]["ingot"]);
	ingots.forEach(function (ingot) {
		Orion.MoveItem(ingot, -1, Player.BankSerial());
		Orion.Wait(2000);
	});

	print("unload", "Unloaded", true)
}

function start() {
	init();
	while (!Player.Dead()) {
		for (var i in minePoints) {
			print("start", "[i] Point " + i);
			Orion.WalkTo(minePoints[i]["x"], minePoints[i]["y"], minePoints[i]["z"], 0);

			for (var x = -_mining["tileOffset"]; x <= _mining["tileOffset"]; x++) {
				for (var y = -_mining["tileOffset"]; y <= _mining["tileOffset"]; y++) {
					var tiles = Orion.GetTiles("cave", Player.X() + x, Player.Y() + y);
					tiles.forEach(function (tile) {
						mine(tile.Graphic(), tile.X(), tile.Y(), tile.Z());
					})
				}
			}
		}
	}
}

// #helpers/data.oajs
function substInList(string, list) {
	var result = false;
	// print("substInList", "Check if '" + string + "' matches to " + list, true);
	list.forEach(function (element) {
		if (Orion.Contains(string, element)) {
			print("substInList", "Matched " + element + " to " + string, true);
			result = true;
		}
	});

	return result;
}

function mine(graphic, x, y, z) {
	while (!Player.Dead()) {
		print("m", "123")
		if (!checkTool()) {
			print("mine", "Not enough tools, pausing the script.");
			Orion.PauseScript();
		}

		print("m", "Tool ok")

		if (Player.Weight() >= _mining["maxWeight"]) {
			print("mine -> weight", "W: " + Player.Weight() + " Smelt: " + _mining["maxWeight"] + " Unload: " + _mining["unload"]["unloadWeightLimit"], true);
			const forgeLocation = nearestForge();
			Orion.WalkTo(forgeLocation["x"], forgeLocation["y"], forgeLocation["z"], 1);
			smelt(Player.X(), Player.Y(), Player.Z());
			ifFeatureFlagEnabled("craftTools", craftTools);
			ifFeatureFlagEnabled("unload", function () {
				if (Player.Weight() >= _mining["unload"]["unloadWeightLimit"]) {
					if (!Orion.WalkTo(
						_mining["unload"]["bankLocation"]["x"],
						_mining["unload"]["bankLocation"]["y"],
						_mining["unload"]["bankLocation"]["z"])) {
						print("mine -> unload", "Failed to reach the bank, pausing the script")
						Orion.PauseScript();
					}
					unload()
					if (!Orion.WalkTo(x, y, z)) {
						pprint("mine -> unload", "Failed to reach the spot, pausing the script")
						Orion.PauseScript();
					}
				}
			});
		}
		Orion.WalkTo(x, y, z, 0);
		if (Orion.ValidateTargetTile(graphic, x, y, z)) {
			if (Orion.HaveTarget())
				Orion.CancelWaitTarget();

			Orion.UseType(_mining["types"]["pickaxe"]);
			Orion.WaitJournal("Where do you wish", Orion.Now(), Orion.Now() + 2000, "me|sys");
			Orion.TargetTile(graphic, x, y, z);
			var result = Orion.WaitJournal("You put some|You loosen some|There is no metal|Try mining|is too far|no line of|seen", Orion.Now(), (Orion.Now() + 7000), "me|sys");
			// TODO: Refactor this
			if (result && substInList(result.Text(), _mining["skipTileMessages"])) {
				print("mine", "[i] Tile depleted", true);
				Orion.Wait(300);
				break;
			}
		} else {
			print("mine", "Tile is not valid", true);
			break;
		}
	}
}
function smelt(x, y, z) {
	print("smelt", "[i] Smelting");
	var forgeSerial = Orion.FindType(_mining["types"]["forges"].join("|"), -1, "ground", "", _mining["forgeScanDistance"]);
	if (forgeSerial.length > 0) {
		var forge = Orion.FindObject(forgeSerial[0]);
		if (forge) {
			if (Orion.WalkTo(forge.X(), forge.Y(), forge.Z(), 1)) {
				while (Orion.FindType(_mining["types"]["ore"], -1, "backpack").length > 0) {
					var ores = Orion.FindType(_mining["types"]["ore"], -1, "backpack");
					ores.forEach(function (ore) {
						Orion.UseObject(ore);
						Orion.WaitJournal("Select the forge", Orion.Now(), Orion.Now() + 1000, "me|sys");
						Orion.TargetObject(forgeSerial);
						Orion.WaitJournal("You burn away|You smelt", Orion.Now(), Orion.Now() + 1000, "me|sys");
						Orion.Wait(500);
					});
				}
				//Back to spot
				Orion.WalkTo(x, y, z, 0);
			}
		}
	} else {
		print("smelt", "Failed to find a forge, pausing the script.");
		Orion.PauseScript();
	}
}
function checkTool() {
	var tools = Orion.FindType(_mining["types"]["pickaxe"], -1, "backpack");
	if (tools && tools.length >= 0) {
		return true;
	}

	print("checkTool", "[e] Not enough tools");
	return false;

}

function init() {

	if (Player.WarMode())
		Player.WarMode(false)

	print("init", "Initialization...");
	print("init", "[Unloading] Enabled: " + _mining["unload"]["enabled"])
	print("init", "[CraftTools] Enabled: " + _mining["craftTools"]["enabled"])
}
Post Reply