Mining a specific ore.

For questions relating to POL scripting (not necessarily related to WoD)

Moderators: Siobhan, Sebastian, Drocket

Mining a specific ore.

Postby dw3rby on Tue Jul 27, 2004 9:40 pm

I am trying to make a system, that when you use your shovel, and pick a location, it asks you what ore you want to mine. I have the gump written, but I have no idea how to make it mine the specific ore. Anyhelp is appreciated. Thanks ahead of time. I have attached the gump code:

Code: Select all
use uo;
use os;

include "include/attributes";

program ore_mining( who )

var gflayout := {
 
      "nodispose",   
      "page 0",   
      "resizepic 100 100 3600 180 300",
      "text 116 120 37 0",         //choose ore
      "page 1",
      "text 140 160 37 1",         //iron   
      "button 120 165 2103 2104 1 1 1",

      "text 140 180 37 2",         //bronze
      "button 120 185 2103 2104 1 1 2",
   
      "text 140 200 37 3",         //dull copper
      "button 120 205 2103 2104 1 1 3",

      "text 140 220 37 4",         //copper
      "button 120 225 2103 2104 1 1 4",

      "text 140 240 37 5",         //onyx
      "button 120 245 2103 2104 1 1 5",
      
      "text 140 260 37 6",         //pyrite
      "button 120 265 2103 2104 1 1 6",

      "text 140 280 37 7",         //malachite
      "button 120 285 2103 2104 1 1 7",

      "text 140 300 37 8",          //azurite
      "button 120 305 2103 2104 1 1 8",

      "text 140 320 37 9",         //blue steel
      "button 120 325 2103 2104 1 1 9",

      "text 140 340 37 10",         //ruby steel
      "button 120 345 2103 2104 1 1 10"


};

var gfdata :={
      "Choose Ore To Mine",
      "Iron",
      "Bronze",
      "Dull Copper",
      "Copper",
      "Onyx",
      "Pyrite",
      "Malachite",
      "Azurite",
      "Bluesteel",
      "Rubysteel"
};

SendDialogGump( who, gflayout, gfdata );

endprogram
dw3rby
Sr. Newbie
 
Posts: 20
Joined: Mon Dec 01, 2003 3:42 am

Postby dw3rby on Fri Jul 30, 2004 3:18 am

This compiles, but it doesnt bring up the gump until after I mine a little bit, and then it brings it up, you choose ore, and it says your backpack is full, then goes to the error message. Towards the bottom are my modifications, but I totally botched it up, because now mining doesnt user the regiontype or groups, so it is weird. ANY help is appreciated.

Code: Select all
use os;
use uo;
use util;
use cfgfile;

include "include/client";
include "include/objtype";
include "include/utility";
include "include/attributes";
include "include/spawn";
include "include/crafting";
include "../pkg/items/treasuremap/treasuremap";

Const UACTION_PICK := 0x0B;

Const REGION_WORLD         := 1;
Const REGION_DUNGEONS      := 2;

Const GROUP_CLAY         := 1;
Const GROUP_SAND         := 2;
Const GROUP_NORMAL_ORE      := 3;
Const GROUP_IRON         := 4;
Const GROUP_BRONZE         := 5;
Const GROUP_DULL_COPPER      := 6;
Const GROUP_COPPER         := 7;
Const GROUP_ONYX         := 8;
Const GROUP_PYRITE         := 9;
Const GROUP_MALACHITE      := 10;
Const GROUP_AZURITE         := 11;
Const GROUP_RUBYSTEEL      := 12;
Const GROUP_BLUESTEEL      := 13;

var mining_type := 0;
var region := 0;
var bad_event_chance := 0;
var craftingbag;

program use_picktool (character, tool)

   SendSysmessage (character, "Select a place to mine, or a treasure map to dig up.");
   var mining_loc := TargetCoordinates (character);
   if (!mining_loc)
      SendSysMessage (character, "Canceled.");
      return;
   endif

   if (mining_loc.item.objtype == UOBJ_MAP1)
      TryToDigUpTreasureMap (character, mining_loc.item);
      return;
   endif

   var distt := coordist (character.x, character.y, mining_loc.x, mining_loc.y );

   if ( distt > 2 )
      SendSysmessage (character, "That is too far away");
      return;
   endif

   var info := GetMapInfo (mining_loc.x , mining_loc.y);

   if ( IsSwampTile (info.landtile) )
      mining_type := GROUP_CLAY;
      bad_event_chance := 1;
   elseif ( IsSandTile (info.landtile) )
      mining_type := GROUP_SAND;
      bad_event_chance := 1;
   elseif (IsMinableTile ( info.landtile , mining_loc.objtype ) )
      region := DetermineMiningRegion (mining_loc);
      mining_type := DetermingMiningGroupType (character, tool);
      if (!mining_type)
         return;
      endif
   else
      SendSysMessage (character, "You cannot mine on that.");
      return;
   endif

   craftingbag := FindCraftingBag (character);
   var sx := character.x;
   var sy := character.y;

   repeat
      case (mining_type)
         GROUP_CLAY:
            if (DigForClay (character, mining_loc, info))
               return;
            endif
         GROUP_SAND:
            if (DigForSand (character, mining_loc, info))
               return;
            endif
         default:
            if (DigForOre (character, mining_loc, info))
               return;
            endif
      endcase

      if ( RandomInt(100) <= CINT (bad_event_chance) )
         if ( DoRandomEvent (character, tool) )
            return;
         endif
      endif

   until (character.x != sx or character.y != sy or character.hidden);

endprogram



///////////////////
//  determines if the tile is one that you can mine ore on
///////////////////

function IsMinableTile ( theobj , othertype )

   if(theobj >= 0xe2 and theobj <= 0xe7)
      return 1;
   elseif (theobj >= 0x0f3 and theobj <= 0x0f7)
      return 1;
   elseif (theobj >= 0x104 and theobj <= 0x107)
      return 1;
   elseif (theobj >= 0x110 and theobj <= 0x113)
      return 1;
   elseif (theobj >= 0x122 and theobj <= 0x125)
      return 1;
   elseif (theobj >= 0x1d3 and theobj <= 0x1da)
      return 1;
   elseif (theobj >= 0x21f and theobj <= 0x230)
      return 1;
   elseif (theobj >= 0x232 and theobj <= 0x23B)
      return 1;
   elseif (theobj >= 0x6cd and theobj <= 0x6d1)
      return 1;
   elseif (theobj >= 0x6da and theobj <= 0x6dd)
      return 1;
   elseif (theobj >= 0x6eb and theobj <= 0x6fe)
      return 1;
   elseif (theobj >= 0x70d and theobj <= 0x714)
      return 1;
   elseif (theobj >= 0x71d and theobj <= 0x720)
      return 1;
   elseif (theobj >= 0x72b and theobj <= 0x732)
      return 1;
   elseif (theobj >= 0x73b and theobj <= 0x73e)
      return 1;
   elseif (theobj >= 0x749 and theobj <= 0x750)
      return 1;
   elseif (theobj >= 0x759 and theobj <= 0x75c)
      return 1;
   elseif (theobj >= 0x240 and theobj <= 0x250)
        return 1;
   elseif( (othertype >= 0x053b) and (othertype <= 0x0553) and (othertype != 0x0550 ) )
      return 1;
   elseif( (theobj == 0xDF) or (theobj == 0x75) or (theobj == 0xDE) )
      return 1;
   else
      return 0;
   endif

endfunction




///////////////////
//  determines if the tile being mined on is one that produces clay
///////////////////

function IsSwampTile (theobjtype)
   if (theobjtype >= 0x3d65 and theobjtype <= 0x3ef0)
      return 1;
   else
      return 0;
   endif
endfunction




///////////////////
//  determines if the tile being mined on is sand
///////////////////

function IsSandTile (theobj)

   if (theobj >= 0x0016 and theobj <=  0x004b)
      return 1;
   elseif (theobj >= 0x011e and theobj <= 0x012d)
      return 1;
   elseif (theobj >= 0x0192 and theobj <= 0x01ab)
      return 1;
   elseif (theobj >= 0x01b9 and theobj <= 0x01d1)
      return 1;
   elseif (theobj >= 0x0282 and theobj <= 0x0291)
      return 1;
   elseif (theobj >= 0x03b7 and theobj <= 0x03ca)
      return 1;
   elseif (theobj >= 0x064b and theobj <= 0x0672)
      return 1;
   else
      return 0;
   endif

endfunction




///////////////////
//  tries to dig for sand at the chosen location
///////////////////

function DigForSand (character, use_on, info)
   var tdiff := GetHarvestDifficulty ( "sand", use_on.x , use_on.y , info.landtile );
   if( !tdiff )
      SendSysMessage (character, "There is no sand here to mine.");
      return 1;
   endif

   for i := 1 to 3
      PerformAction (character, UACTION_PICK);
      sleepms (1600);
      PlaySoundEffect (character, 0x126);
   endfor

   if ( CheckSkill (character, SKILLID_MINING, tdiff, 0 ) )
      var check_amt := HarvestResource ( "sand", use_on.x, use_on.y, 2, 2);
      if (!check_amt)
         SendSysMessage (character, "There is no sand here to mine.");
         return 1;
      endif
      
      var amount := RandomInt (5) + CINT (GetAttribute (character, ATTRIBUTEID_MINING)/20) + 1;
      var thesand := CreateItemInContainer (craftingbag, UOBJ_SAND, amount);
      if (!thesand)
         PrintTextAbovePrivate (character, "*Your backpack is full!*", character);
         return 1;
      else
         thesand.movable := 1;
         PrintTextAbovePrivate (character, "*" + thesand.desc + "*", character);
      endif
   endif

   return 0;

endfunction




///////////////////
//  tries to dig for clay at the location specified
///////////////////

function DigForClay (character, use_on, info)

   var tdiff := GetHarvestDifficulty ( "clay", use_on.x , use_on.y , info.landtile );
   if( !tdiff )
      SendSysMessage (character, "There is no clay here to mine.");
      return 1;
   endif

   for i := 1 to 3
      PerformAction (character, UACTION_PICK);
      sleepms (1600);
      PlaySoundEffect (character, 0x126);
   endfor
   sleep(1);

   if ( CheckSkill (character, SKILLID_MINING, tdiff, 0 ) )
      var check_amt := HarvestResource ( "clay", use_on.x, use_on.y, 2, 2);
      if (!check_amt)
         SendSysMessage (character, "There is no clay here to mine.");
         return 1;
      endif

      var amount := RandomInt (5) + CInt (GetATTRIBUTE (character, ATTRIBUTEID_MINING)/20) + 1;
      var theclay := CreateItemInContainer (craftingbag, UOBJ_CLAY, amount);
      if (!theclay)
         PrintTextAbovePrivate (character, "*Your backpack is full!*", character);
         return 1;
      else
         theclay.movable := 1;
         PrintTextAbovePrivate (character, "*" + theclay.desc + "*", character);
      endif
   endif

   return 0;

endfunction




///////////////////
//  attempts to dig for ore in the area specified
///////////////////


function DigForOre (character, use_on, info)
   
   var mining_difficulty := GetHarvestDifficulty ( "ore", use_on.x , use_on.y , info.landtile );
   if( !mining_difficulty )
      SendSysMessage (character, "There is no ore here to mine.");
      return 1;
   endif

   for i := 1 to 5
      performaction (character, UACTION_PICK);
      sleepms (1500);
      PlaySoundEffect (character, 0x126);
   endfor
   sleep(1);

   //if they fail to get anything
   if (!CheckSkill (character, SKILLID_MINING, -1, 0 ) )
      return 0;
   endif

   var character_skill := GetAttribute (character, ATTRIBUTEID_MINING);
   var ore_amount := RandomInt (5) + CInt ( (character_skill + 5)/20) + 1;
   var ore_type := DetermineOreType (character, mining_type);

   var created_ore := CreateItemInContainer (craftingbag, ore_type, ore_amount);
   HarvestResource ( "ore", use_on.x, use_on.y, 1, ore_amount );
   if (!created_ore)
      PrintTextAbovePrivate (character, "*Your backpack is full*", character);
      return 1;
   else
      created_ore.movable := 1;
      PrintTextAbovePrivate (character, "*" + created_ore.desc + "*", character);
   endif

endfunction




///////////////////
//  determines the which region of the world that the character is mining in
///////////////////

function DetermineMiningRegion (use_on)
   var x := use_on.x;
   var y := use_on.y;

   if (x > 5120 and x < 6138 and y > 0 and y < 2298)
      return REGION_DUNGEONS;
   else
      return REGION_WORLD;
   endif

endfunction




///////////////////
//  figures out what mining table to use
///////////////////

function DetermingMiningGroupType (character, tool)

   case (tool.objtype)
      0x07091:      //iron shovel
         bad_event_chance := 1;
         return GROUP_IRON;
      0x07092:      //bronze shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 40)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         bad_event_chance := 7;
         return GROUP_BRONZE;
      0x07093:      //dull copper shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 50)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         bad_event_chance := 7;
         return GROUP_DULL_COPPER;
      0x07094:      //copper shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 60)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         bad_event_chance := 7;
         return GROUP_COPPER;
      0x07095:      //onyx shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 70)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         bad_event_chance := 8;
         return GROUP_ONYX;
      0x07096:      //pyrite shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 80)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         bad_event_chance := 8;
         return GROUP_PYRITE;
      0x07097:      //malachite shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 90)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         bad_event_chance := 9;
         return GROUP_MALACHITE;
      0x07098:      //azurite shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 90)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif

         if (region != REGION_WORLD)
            SendSysMessage (character, "You can't use this shovel here.");
            return 0;
         endif
         bad_event_chance := 10;
         return GROUP_AZURITE;
      0x07099:      //rubysteel shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 90)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         if (region != REGION_DUNGEONS)
            SendSysMessage (character, "You can't use this shovel here.");
            return 0;
         endif
         bad_event_chance := 10;
         return GROUP_RUBYSTEEL;
      0x0709a:      //bluesteel shovel
         if (GetAttribute (character, ATTRIBUTEID_MINING) < 90)
            SendSysMessage (character, "Your skill isn't high enough to use this item.");
            return 0;
         endif
         if (region != REGION_DUNGEONS)
            SendSysMessage (character, "You can't use this shovel here.");
            return 0;
         endif
         bad_event_chance := 10;
         return GROUP_BLUESTEEL;
      default:
         if (region == REGION_DUNGEONS)
            bad_event_chance := 5;
         else
            bad_event_chance := 3;
         endif
         return GROUP_NORMAL_ORE;
   endcase

endfunction

///////////////////////////////////////
//Gumpness of the mining system - ore
///////////////////////////////////////

function DetermineOreType( character, mining_type, )





var gflayout := {

      "nodispose",   
      "page 0",   
      "resizepic 100 100 2620 180 280",
      "text 116 120 37 0",         //choose ore
      "page 1",

      "text 140 160 37 1",         //iron   
      "button 120 165 2103 2104 1 1 1",

      "text 140 180 37 2",         //bronze
      "button 120 185 2103 2104 1 1 2",
   
      "text 140 200 37 3",         //dull copper
      "button 120 205 2103 2104 1 1 3",

      "text 140 220 37 4",         //copper
      "button 120 225 2103 2104 1 1 4",

      "text 140 240 37 5",         //onyx
      "button 120 245 2103 2104 1 1 5",
      
      "text 140 260 37 6",         //pyrite
      "button 120 265 2103 2104 1 1 6",

      "text 140 280 37 7",         //malachite
      "button 120 285 2103 2104 1 1 7",

      "text 140 300 37 8",          //azurite
      "button 120 305 2103 2104 1 1 8",

      "text 140 320 37 9",         //blue steel
      "button 120 325 2103 2104 1 1 9",

      "text 140 340 37 10",         //ruby steel
      "button 120 345 2103 2104 1 1 10",

                        //pickaxe decorative 1
      "tilepic 170 135 3717",

                        //pickaxe decorative 2
      "tilepic 170 135 3718"


};


var gfdata :={
      "Choose Ore To Mine",
      "Iron",
      "Bronze",
      "Dull Copper",
      "Copper",
      "Onyx",
      "Pyrite",
      "Malachite",
      "Azurite",
      "Bluesteel",
      "Rubysteel"
};

SendDialogGump( character, gflayout, gfdata );

var gump_return := SendDialogGump( character, gflayout, gfdata );

     
     
  if (gump_return == 1)
   return UOBJ_IRON_ORE;
elseif (gump_return == 2 and CheckSkill (character, SKILLID_MINING, 40, 0 ))
   return UOBJ_BRONZE_ORE;
elseif (gump_return == 3 and CheckSkill (character, SKILLID_MINING, 60, 0 ))
   return UOBJ_DULLCOPPER_ORE;
elseif (gump_return == 4 and CheckSkill (character, SKILLID_MINING, 60, 0 ))
   return UOBJ_COPPER_ORE;
elseif (gump_return == 5 and CheckSkill (character, SKILLID_MINING, 70, 0 ))
   return UOBJ_ONYX_ORE;
elseif (gump_return == 6 and CheckSkill (character, SKILLID_MINING, 80, 0 ))
   return UOBJ_PYRITE_ORE;
elseif (gump_return == 6 and CheckSkill (character, SKILLID_MINING, 90, 0 ))
   return UOBJ_MALACHITE_ORE;
elseif (gump_return == 7 and CheckSkill (character, SKILLID_MINING, 90, 0 ))
   return UOBJ_AZURITE_ORE;
elseif (gump_return == 8 and CheckSkill (character, SKILLID_MINING, 95, 0 ))
   return UOBJ_BLUESTEEL_ORE;
elseif (gump_return == 9 and CheckSkill (character, SKILLID_MINING, 95, 0 ))
   return UOBJ_RUBYSTEEL_ORE;
else
   SendSysMessage (character, "Error with script, please try again");
endif




endfunction


///////////////////
//  randomly does something, such as break a tool
///////////////////

function DoRandomEvent (me, tool)

   var it;
   if ( mining_type == GROUP_SAND or mining_type == GROUP_CLAY or mining_type == GROUP_NORMAL_ORE )
      case (RandomInt (8))
         0:
         1:
         2:
            it := SpawnNPCInArea ("slime", me.x, me.y);
            if (it)
               SendSysmessage(me, "A slime oozes over to see what you're doing");
               return 1;
            endif
            return 0;
         3:
            if ( CheckSkill(me, SKILLID_MINING, 90,0) and RandomInt (2) )
               var maptype := 0x6003;
               if ( randomint(5) == 1 )
                  maptype := 0x6004;
               endif
               CreateIteminContainer (craftingbag, maptype, 1);
               SendSysMessage (me, "You discover a tattered old map!");
               return 0;
            endif
         4:
         5:
              if ( CheckSkill(me, SKILLID_MINING, 70,0) )
               CreateIteminContainer (craftingbag, 0x0F25, 1);
               sendsysmessage (me, "You find a chunk of fossilized sap!");
               return 0;
            endif
         6:
            if ( randomint(4) == 1 )
               sendsysmessage(me, "Oh no your tool breaks!");
               DestroyItem (tool);
               return 1;
            endif
         7:
            if (mining_type == GROUP_SAND)
               it := SpawnNPCInArea ("sandelemental", me.x, me.y);
               if (it)
                  SendSysmessage(me, "Oh no!  A sand elemental!");
                  return 1;
               endif
               return 0;
            else
               it := SpawnNPCInArea ("earthelemental", me.x, me.y);
               if (it)
                  SendSysmessage(me, "Oh no!  An earth elemental!");
                  return 1;
               endif
               return 0;
            endif
         default:
            return 0;
      endcase
   elseif (mining_type == GROUP_BLUESTEEL or mining_type == GROUP_RUBYSTEEL or mining_type == GROUP_AZURITE)
      case (RandomInt (12))
         0:
         1:
            it := SpawnNPCInArea ("slime", me.x, me.y);
            if (it)
               SendSysmessage(me, "A slime oozes over to see what you're doing");
               return 1;
            endif
            return 0;
         2:
            if ( CheckSkill(me, SKILLID_MINING, 90,0) and RandomInt (2) )
               var maptype := 0x6005;
               if ( randomint(5) == 1 )
                  maptype := 0x6006;
               endif
               CreateIteminContainer (craftingbag, maptype, 1);
               SendSysMessage (me, "You discover a tattered old map!");
               return 0;
            endif
         3:
            CreateItemInContainer (craftingbag, UOBJ_GEM_RUBY, 1);
            SendSysMessage (me, "You find a ruby!");
         4:
            CreateItemInContainer (craftingbag, UOBJ_GEM_EMERALD, 1);
            SendSysMessage (me, "You find an emerald!");
         5:
            if (RandomInt (2) )
               CreateItemInContainer (craftingbag, UOBJ_GEM_DIAMOND, 1);
               SendSysMessage (me, "You find a diamond!");
            endif
         6:
            sendsysmessage(me, "Oh no your tool breaks!");
            DestroyItem (tool);
            return 1;
         7:
         8:
            it := SpawnNPCInArea ("giantslime", me.x, me.y);
            if (it)
               SendSysmessage(me, "A slime oozes over to see what you're doing.");
               return 1;
            endif
            return 0;
         9:
         10:
            it := SpawnNPCInArea ("graniteelemental", me.x, me.y);
            if (it)
               SendSysmessage(me, "Oh no!  An earth elemental!");
               return 1;
            endif
            return 0;
         11:
            for i := 1 to 4
               SpawnNPCInArea ("earthelemental", me.x, me.y);
            endfor
         default:
            return 0;
      endcase
   else
      case (RandomInt (10))
         0:
         1:
         2:
            it := SpawnNPCInArea ("slime", me.x, me.y);
            if (it)
               SendSysmessage(me, "A slime oozes over to see what you're doing");
               return 1;
            endif
            return 0;
         3:
            if ( CheckSkill(me, SKILLID_MINING, 90,0) and RandomInt (2) )
               var maptype := 0x6004;
               if ( randomint(5) == 1 )
                  maptype := 0x6005;
               endif
               CreateIteminContainer (craftingbag, maptype, 1);
               SendSysMessage (me, "You discover a tattered old map!");
               return 0;
            endif
         4:
            CreateIteminContainer (craftingbag, UOBJ_GEM_SAPPHIRE, 1);
            sendsysmessage (me, "You find a sapphire!");
            return 0;
         5:
            CreateIteminContainer (craftingbag, UOBJ_GEM_STAR_SAPPHIRE, 1);
            sendsysmessage (me, "You find a star sapphire!");
            return 0;
         6:
            sendsysmessage(me, "Oh no your tool breaks!");
            DestroyItem (tool);
            return 1;
         7:
         8:
            it := SpawnNPCInArea ("earthelemental", me.x, me.y);
            if (it)
               SendSysmessage(me, "Oh no!  An earth elemental!");
               return 1;
            else
               return 0;
            endif
         9:
            if ( randomint(2) )
               it := SpawnNPCInArea ("graniteelemental", me.x, me.y);
               if (it)
                  SendSysmessage(me, "Oh no!  An earth elemental!");
                  return 1;
               else
                  return 0;
               endif
            endif
         default:
            return 0;
      endcase

   endif

   return 0;

endfunction
dw3rby
Sr. Newbie
 
Posts: 20
Joined: Mon Dec 01, 2003 3:42 am


Return to Scripting Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron