This is a little command script (i use it on :mining:command/gm ), that generates a number of random ore veins after selecting parameters from a gump - made with new gumps functions.
Basically it asks for total number of veins to create and max range from mobile who is using the command.
From then on, it performs a number of DiceRolls to generate the various ore veins in mining zones, each vein can be a different material but obviously rare materials are more difficult to spawn in vein, max quantity will be lower, and so on.
Here is the script:
Code: Select all
use uo;
use os;
use cfgfile;
use util;
/*
TODO:
Add a function that checks for :
- The existence of a previously created orevein in the same location
- The compatibility of the terrain tile with a minable one, to create ore veins
only in minable terrains.
*/
include ":datafile:datafile";
include ":gumps:gumps";
include ":gumps:gumps_ex";
include ":mining:report";
CONST CANCEL_BTN := 0xA00;
CONST UPDATE_BTN := 0xA01;
CONST VEIN := 0xEF01;
program create_RandomOreVein(who)
var gump := GFCreateGump();
GFResizePic(gump, 0, 0, GFGetCfgConst("Defaults", "BackGround"), 310, 210);
GFResizePic(gump, 15, 15, GFGetCfgConst("Defaults", "ForeGround"), 280, 180);
// Window title
GFTextLine(gump, 30, 20, 2100, "Random Ore Vein Creation");
// Data Entry
GFGumpPic(gump, 20, 50, 2444);
var amount := GFTextEntry(gump, 25, 50, 120, 20, 2100);
GFTextLine(gump, 135, 50, 2100, "Veins Amount");
GFGumpPic(gump, 20, 68, 2444);
var range := GFTextEntry(gump, 25, 68, 120, 20, 2100);
GFTextLine(gump, 135, 68, 2100, "Max Creation Range");
GFAddButton(gump, 25, 115, 2117, 2118, GF_CLOSE_BTN, UPDATE_BTN);
GFTextLine(gump, 45, 115, 2100, "Create Veins");
GFAddButton(gump, 25, 135, 2117, 2118, GF_CLOSE_BTN, CANCEL_BTN);
GFTextLine(gump, 45, 135, 2100, "Cancel");
var input := GFSendGump(who, gump);
if ( input[UPDATE_BTN] )
var dist := GFExtractData(input, range);
if ( !dist )
dist := 2;
endif
var amt := GFExtractData(input,amount);
SendSysMessage(who, "Generating Random Veins...");
GenerateRandomVein(who,dist,amt);
return 1;
else
SendSysMessage(who, "Cancelled");
return 0;
endif
endprogram
function GenerateRandomVein(who,range,amount)
MSP_ReportText("--- Generating Random Ore Veins ---", MSP_REPORT_SYSLOG);
// starting from a known location (the gm coords)
// we define a random function that places the exact amount of ore veins
// inside a well defined range of a grid
var i;
//var vein := 0xEF01;
amount := CInt(amount);
// Cycling into the max amount of ore veins to be spawned and generated
for (i := 1; i <= amount; i := i+1)
// A simple dice roll with a d2 dice, to determine if movement from who.x,y is negative or positive
var movementx := RandomDiceRoll("1d"+range);
var posnegx := RandomDiceRoll("1d2");
if ( posnegx == 1 )
movementx := (movementx * -1);
elseif ( posnegx == 2)
movementx := movementx;
endif
var movementy := RandomDiceRoll("1d"+range);
var posnegy := RandomDiceRoll("1d2");
if ( posnegy == 1 )
movementy := (movementy * -1);
elseif ( posnegy == 2)
movementy := movementy;
endif
// Ok, now we have the movement from original X and Y coords of the gm
// Let's Create the ore vein
var veinX := who.x+movementx;
var veinY := who.y+movementy;
var veinZ := GetWorldHeight(veinX,veinY,who.realm);
var orevein := CreateItemAtLocation(veinX, veinY, veinZ, VEIN);
if ( !orevein)
MSP_ReportText("--- Can't create ore vein at location "+veinX+","+veinY+","+veinZ+" ---", MSP_REPORT_SYSLOG);
else
MSP_ReportText("--- Creating "+orevein.desc+" at location "+veinX+","+veinY+","+veinZ+" ---", MSP_REPORT_SYSLOG);
endif
// Setting up parameters for Ore Vein
// Set up is made by a RandomDiceRoll of a "100" faces dice
// Number of dice faces determines the probability of getting a better material vein
var maxore := 0; // initialize the maxore variable
var matType := RandomDiceRoll("1d174");
SendSysMessage(who, "Random Dice: "+matType);
if ( matType <= 69 ) // Iron Ore
orevein.SetOreType("0x6300");
orevein.SetDifficulty(RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(20 + RandomDiceRoll("1d10"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 69 && matType <= 109 )
orevein.SetOreType("0x6301");
orevein.SetDifficulty(5+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(20 + RandomDiceRoll("1d8"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 109 && matType <= 134 )
orevein.SetOreType("0x6302");
orevein.SetDifficulty(10+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(20 + RandomDiceRoll("1d6"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 134 && matType <= 149 )
orevein.SetOreType("0x6303");
orevein.SetDifficulty(15+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(20 + RandomDiceRoll("1d4"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 149 && matType <= 159 )
orevein.SetOreType("0x6304");
orevein.SetDifficulty(20+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(20 + RandomDiceRoll("1d2"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 159 && matType <= 165 )
orevein.SetOreType("0x6305");
orevein.SetDifficulty(25+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(10 + RandomDiceRoll("1d10"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 165 && matType <= 169 )
orevein.SetOreType("0x6306");
orevein.SetDifficulty(30+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(10 + RandomDiceRoll("1d8"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 169 && matType <= 172 )
orevein.SetOreType("0x6307");
orevein.SetDifficulty(40+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(10 + RandomDiceRoll("1d4"));
orevein.SetRemainingOre(maxore);
elseif ( matType > 172 && matType <= 174 )
orevein.SetOreType("0x6308");
orevein.SetDifficulty(50+ RandomDiceRoll("1d10"));
orevein.SetYield("1");
maxore := orevein.SetMaxOre(10 + RandomDiceRoll("1d2"));
orevein.SetRemainingOre(maxore);
endif
endfor
endfunction