Author Topic: Forging?  (Read 3028 times)

Ok well this time I am trying to make a forge system for weapon's and Ore for my Mod. I have it basically working exept that when I type /forge silverore 1 it forges the ore but doesn't take away the copperore used to forge it.

Code: [Select]
//ItemForging

$itemPrices["SilverOre"] = "10 2 0 0";
$itemImage["SilverOre"] = nametoid("SilverOreItem");
$itemPrices["CopperOre"] = 5;
$itemImage["CopperOre"] = nametoid("CopperOreItem");
$itemPrices["GoldOre"] = 50;
$itemImage["GoldOre"] = nametoid("GoldOreItem");
$itemPrices["PineWood"] = 5;
$itemImage["PineWood"] = nametoid("PineWoodItem");
$itemPrices["OakWood"] = 10;
$itemImage["OakWood"] = nametoid("OakWoodItem");
$itemPrices["MapleWood"] = 20;
$itemImage["MapleWood"] = nametoid("MapleWoodItem");
$itemPrices["sword"] = 100;
$itemImage["sword"] = nametoid("swordItem");
$itemPrices["bow"] = 150;
$itemImage["bow"] = nametoid("bowItem");
$itemPrices["WarAxe"] = 200;
$itemImage["WarAxe"] = nametoid("WarAxeItem");
$itemPrices["ShortSword"] = 100;
$itemImage["ShortSword"] = nametoid("ShortSwordItem");
$itemPrices["Spear"] = 50;
$itemImage["Spear"] = nametoid("SpearItem");
$itemPrices["PioneerHG"] = 250;
$itemImage["PioneerHG"] = nametoid("PioneerHGItem");
$itemPrices["Longsword"] = 200;
$itemImage["Longsword"] = nametoid("LongswordItem");
$itemPrices["MCrossBow"] = 150;
$itemImage["MCrossBow"] = nametoid("MCrossBowItem");

function serverCmdForge(%client, %item, %amount_to_Forge)
{
if( %amount_to_Forge < 1 ) // They have to Forge at least 1
return;

%price_of_item = getWord(%price_of_item, 0);
if (%price_copper > %client.quantity["CopperOre"] || %price_silver > %client.quantity["SilverOre"] || %price_goldOre > %client.quantity["GoldOre"])
{
messageClient(%client,'','Not enough Material(s)!');
return;
}

%image = $itemImage[%item];

// Add the amount:
%client.quantity[%item] += %amount_to_Forge;

// The rest looks good. Find a free inventory slot, etc:
%k = 0;
%i = -1;
while( %k < 5 )
{
if( !%client.quantityplayer.tool[%k] )
{
%i = %k;
}
%k++;
}

if( %i == -1 )
{
messageClient(%client,'','Not enough inventory space!');
return;
}

%client.player.tool[%i] = %image;
messageClient(%client, 'MsgItemPickup', '', %i, %image);
%client.quantity["CopperOre"] -= %price_copper;
%client.quantity["SilverOre"] -= %price_silver;
%client.quantity["GoldOre"] -= %price_goldOre;
       
}

« Last Edit: June 08, 2008, 08:45:37 PM by exidyne »

Well wait how would I add more material's to the number process in this order PineWood OakWood MapleWood

The number code should go like this

1.Gold
2.Copperore
3.Silverore
4.Goldore
5.Pinewood
6.Oakwood
7.Maplewood

Code: [Select]
//ItemForging
$itemPrices["SilverOre"] = "10 2 0 0 0 0 0";
$itemImage["SilverOre"] = nametoid("SilverOreItem");
$itemPrices["CopperOre"] = "5 0 0 0 0 0 0";
$itemImage["CopperOre"] = nametoid("CopperOreItem");
$itemPrices["GoldOre"] = "50 0 5 0 0 0 0";
$itemImage["GoldOre"] = nametoid("GoldOreItem");
$itemPrices["PineWood"] = "5 0 0 0 0 0 0";
$itemImage["PineWood"] = nametoid("PineWoodItem");
$itemPrices["OakWood"] = "10 0 0 0 2 0 0";
$itemImage["OakWood"] = nametoid("OakWoodItem");
$itemPrices["MapleWood"] = "50 0 0 0 0 5 0";
$itemImage["MapleWood"] = nametoid("MapleWoodItem");
$itemPrices["sword"] = "100 0 10 0 0 0 0";
$itemImage["sword"] = nametoid("swordItem");
$itemPrices["bow"] = "50 0 0 0 0 5 0";
$itemImage["bow"] = nametoid("bowItem");
$itemPrices["WarAxe"] = "75 5 5 0 0 0 0";
$itemImage["WarAxe"] = nametoid("WarAxeItem");
$itemPrices["ShortSword"] = "45 5 2 0 0 0 0";
$itemImage["ShortSword"] = nametoid("ShortSwordItem");
$itemPrices["Spear"] = "50 0 0 0 5 0 0";
$itemImage["Spear"] = nametoid("SpearItem");
$itemPrices["PioneerHG"] = "90 5 5 0 3 0 0";
$itemImage["PioneerHG"] = nametoid("PioneerHGItem");
$itemPrices["Longsword"] = "105 5 8 0 0 0 0";
$itemImage["Longsword"] = nametoid("LongswordItem");
$itemPrices["MCrossBow"] = "150 5 5 1 5 0 0";
$itemImage["MCrossBow"] = nametoid("MCrossBowItem");

function serverCmdForge(%client, %item, %amount)
{
if( %amount < 1 ) // They have to Forge at least 1
return;

        %ore = "";
        switch$(%item)
        {
            case "CopperOre":
               // Buy in it cash?
               if( %client.gold < (%amount * $itemPrices["CopperOre"]) )
               {
                  messageClient(%client, '', 'Not enough money to buy the item!');
                  return;
               }
               else
               {
                  %client.gold -= (%amount * $itemPrices["CopperOre"]);
                  %client.quantity["CopperOre"] += %amount;
               }
               break;
            case "SilverOre":
               %ore = "CopperOre";
               break;
            case "GoldOre":
               %ore = "SilverOre";
               break;
            default:
               messageClient(%client, '', 'You cannot forge that item(%1).', %item);
               return;
        }

%price = firstWord($itemPrices[%item]);

         if( %amount > %client.quantity[%ore] )
{
messageClient(%client, '', 'Not enough material(s)!');
return;
}

%image = $itemImage[%item];

// Add the amount:
%client.quantity[%item] += %amount;
        %client.quantity[%ore] -= %amount;

// The rest looks good. Find a free inventory slot, etc:
%i = 4;
while( %i >= -1 )
{
if( !%client.player.tool[%i] )
{
break;
}
                else if( %client.player.tool[%i] $= %image )
                {
                   return;
                }
%i--;
}

if( %i == -1 )
{
messageClient(%client, '', 'Not enough inventory space!');
return;
}

%client.player.tool[%i] = %image;
messageClient(%client, 'MsgItemPickup', '', %i, %image);
}
« Last Edit: June 08, 2008, 07:43:22 PM by Eonz »

« Last Edit: June 08, 2008, 08:45:28 PM by exidyne »

Uhh now it take's one of the previous ore's and tran's form's it in to the next ore like say I got 4 copper ore I type /forge silverore 2 it gives me 2 silver ore but still got 2 copper left

You have to say exactly what you want it to do. I can't read your mind to figure out what code to make.

Well I want the code as followed in this case it would take 10 gold to buy OR 5 silver ore to forge a gold ore. 50 0 5 0 0 0 0

1.gold
2.Copperore
3.Silverore
4.Goldore
5.PineWood
6OakWood
7.MapleWood


If you're buying gold then, how does it know whether to pay 10gp or 5 silver ore?

He basically wants to allow you to combine different types of ores to make new items. I was helping him out with it earlier and now looking at it, I see what's wrong (or so I think).

Code: [Select]
%price_of_item = getWord(%price_of_item, 0);
- I meant put this in the buy function, not this one.

Replace that with this:
Code: [Select]
%price_of_item = $itemPrices[%item];
%price_copper = getWord(%price_of_item, 1);
%price_silver = getWord(%price_of_item, 2);
%price_goldOre = getWord(%price_of_item, 3);

Sorry I didn't catch this on live, I didn't know you removed these lines.
« Last Edit: June 08, 2008, 08:20:35 PM by Nitramtj »

If you're buying gold then, how does it know whether to pay 10gp or 5 silver ore?

Well what we were deciding on was prices would be like this "gold copper silver goldore" and that we would use getWord() to get the individual costs.

He basically wants to allow you to combine different types of ores to make new items.

Oh. Here:

Code: [Select]
//ItemForging
$itemPrices["SilverOre"] = "10 2 0 0 0 0 0";
$itemImage["SilverOre"] = nametoid("SilverOreItem");
$itemPrices["CopperOre"] = "5 0 0 0 0 0 0";
$itemImage["CopperOre"] = nametoid("CopperOreItem");
$itemPrices["GoldOre"] = "50 0 5 0 0 0 0";
$itemImage["GoldOre"] = nametoid("GoldOreItem");
$itemPrices["PineWood"] = "5 0 0 0 0 0 0";
$itemImage["PineWood"] = nametoid("PineWoodItem");
$itemPrices["OakWood"] = "10 0 0 0 2 0 0";
$itemImage["OakWood"] = nametoid("OakWoodItem");
$itemPrices["MapleWood"] = "50 0 0 0 0 5 0";
$itemImage["MapleWood"] = nametoid("MapleWoodItem");
$itemPrices["sword"] = "100 0 10 0 0 0 0";
$itemImage["sword"] = nametoid("swordItem");
$itemPrices["bow"] = "50 0 0 0 0 5 0";
$itemImage["bow"] = nametoid("bowItem");
$itemPrices["WarAxe"] = "75 5 5 0 0 0 0";
$itemImage["WarAxe"] = nametoid("WarAxeItem");
$itemPrices["ShortSword"] = "45 5 2 0 0 0 0";
$itemImage["ShortSword"] = nametoid("ShortSwordItem");
$itemPrices["Spear"] = "50 0 0 0 5 0 0";
$itemImage["Spear"] = nametoid("SpearItem");
$itemPrices["PioneerHG"] = "90 5 5 0 3 0 0";
$itemImage["PioneerHG"] = nametoid("PioneerHGItem");
$itemPrices["Longsword"] = "105 5 8 0 0 0 0";
$itemImage["Longsword"] = nametoid("LongswordItem");
$itemPrices["MCrossBow"] = "150 5 5 1 5 0 0";
$itemImage["MCrossBow"] = nametoid("MCrossBowItem");

function serverCmdForge(%client, %item, %amount)
{
   if( $itemPrices[%item] $= "" )
   {
      messageClient(%client, '', 'You cannot forge that item (%1).', %item);
      return;
   }

   if( %amount < 1 ) %amount = 1;

   %items[0] = "gold";
   %items[1] = "CopperOre";
   %items[2] = "SilverOre";
   %items[3] = "GoldOre";
   %items[4] = "PineWood";
   %items[5] = "OakWood";
   %items[6] = "MapleWood";

   for(%i = 1; %i < 7; %i++)
   {
      %price[%i] = getWord($itemPrices[%item], %i);
      if( %client.quantity[%items[%i]] < (%amount * %price[%i]) )
      {
          messageClient(%client, '', 'You do not have enough material(s)! You need %1 more %2.', ((%price[%i] * %amount)- %client.quantity[%items[%i]]), %items[%i]);
          return;
      }
   }

   %msg = "Forging costed you: ";
   for(%i = 1; %i < 7; %i++)
   {
      %amnt = (%amount * %price[%i]);
      if( %amnt != 0 )
         %msg = %msg @ %amnt SPC %items[%i] @ ", ";

      %client.quantity[%items[%i]] -= %amnt;
   }

   %client.quantity[%item] += %amount;

   %image = $itemImage[%item];

   %i = 4;
   while( %i >= -1 )
   {
      if( !%client.player.tool[%i]  || (%client.player.tool[%i].getId() == %image.getId()) )
      {
         break;
      }
      %i--;
   }

   if( %i == -1 )
   {
      messageClient(%client, '', 'Not enough inventory space!');
      return;
   }

   %msg = %msg @ " and you now have " @ %client.quantity[%item] SPC %item @ ".";
   %client.player.tool[%i] = %image;
   messageClient(%client, 'MsgItemPickup', '', %i, %image);
   messageClient(%client, '', %msg);
}
« Last Edit: June 08, 2008, 09:14:00 PM by exidyne »

I was trying to walk Eonz through the code (which I failed at) so I wasn't trying to add much extra to it. He had the idea of hard-coded materials to forge items with, such as a sword would be 5 silver ores, 1 copper ore and no other combination.

Basically yes, But not I got all of it to work and such but when you type /forge goldore 1 and you have 5 silver ore it gives the gold ore but doesnt take the silver ore

Code: [Select]
//ItemForging

$itemPrices["SilverOre"] = "10 2 0 0 0 0 0";
$itemImage["SilverOre"] = nametoid("SilverOreItem");
$itemPrices["CopperOre"] = "5 0 0 0 0 0 0";
$itemImage["CopperOre"] = nametoid("CopperOreItem");
$itemPrices["GoldOre"] = "50 0 5 0 0 0 0";
$itemImage["GoldOre"] = nametoid("GoldOreItem");
$itemPrices["PineWood"] = "5 0 0 0 0 0 0";
$itemImage["PineWood"] = nametoid("PineWoodItem");
$itemPrices["OakWood"] = "10 0 0 0 2 0 0";
$itemImage["OakWood"] = nametoid("OakWoodItem");
$itemPrices["MapleWood"] = "50 0 0 0 0 5 0";
$itemImage["MapleWood"] = nametoid("MapleWoodItem");
$itemPrices["sword"] = "100 0 10 0 0 0 0";
$itemImage["sword"] = nametoid("swordItem");
$itemPrices["bow"] = "50 0 0 0 0 5 0";
$itemImage["bow"] = nametoid("bowItem");
$itemPrices["WarAxe"] = "75 5 5 0 0 0 0";
$itemImage["WarAxe"] = nametoid("WarAxeItem");
$itemPrices["ShortSword"] = "45 5 2 0 0 0 0";
$itemImage["ShortSword"] = nametoid("ShortSwordItem");
$itemPrices["Spear"] = "50 0 0 0 5 0 0";
$itemImage["Spear"] = nametoid("SpearItem");
$itemPrices["PioneerHG"] = "90 5 5 0 3 0 0";
$itemImage["PioneerHG"] = nametoid("PioneerHGItem");
$itemPrices["Longsword"] = "105 5 8 0 0 0 0";
$itemImage["Longsword"] = nametoid("LongswordItem");
$itemPrices["MCrossBow"] = "150 5 5 1 5 0 0";
$itemImage["MCrossBow"] = nametoid("MCrossBowItem");

function serverCmdForge(%client, %item, %amount_to_Forge)
{
if( %amount_to_Forge < 1 ) // They have to Forge at least 1
return;

%price_of_item = %price_of_item;
%price_copper = getWord(%price_of_item, 1);
%price_silver = getWord(%price_of_item, 2);
%price_goldOre = getWord(%price_of_item, 3);
%price_PineWood = getWord(%price_of_item, 4);
%price_OakWood = getWord(%price_of_item, 5);
%price_MapleWood = getWord(%price_of_item, 6);

if (%price_copper > %client.quantity["CopperOre"] || %price_silver > %client.quantity["SilverOre"] || %price_goldOre > %client.quantity["GoldOre"])
{
messageClient(%client,'','Not enough Material(s)!');
return;
}

%image = $itemImage[%item];

// Add the amount:
%client.quantity[%item] += %amount_to_Forge;

// The rest looks good. Find a free inventory slot, etc:
%k = 0;
%i = -1;
while( %k < 5 )
{
if( !%client.quantityplayer.tool[%k] )
{
%i = %k;
}
%k++;
}

if( %i == -1 )
{
messageClient(%client,'','Not enough inventory space!');
return;
}

%client.player.tool[%i] = %image;
messageClient(%client, 'MsgItemPickup', '', %i, %image);
%client.quantity["CopperOre"] -= %price_copper;
%client.quantity["SilverOre"] -= %price_silver;
%client.quantity["GoldOre"] -= %price_goldOre;
       
}


Yes, It work's fine except that when I type /forge goldore 1 it takes 1 silver ore not 5

Now it say's Not Enough Gold!?

Code: [Select]
//ItemForging
$itemPrices["SilverOre"] = "10 2 0 0 0 0 0";
$itemImage["SilverOre"] = nametoid("SilverOreItem");
$itemPrices["CopperOre"] = "5 0 0 0 0 0 0";
$itemImage["CopperOre"] = nametoid("CopperOreItem");
$itemPrices["GoldOre"] = "50 0 5 0 0 0 0";
$itemImage["GoldOre"] = nametoid("GoldOreItem");
$itemPrices["PineWood"] = "5 0 0 0 0 0 0";
$itemImage["PineWood"] = nametoid("PineWoodItem");
$itemPrices["OakWood"] = "10 0 0 0 2 0 0";
$itemImage["OakWood"] = nametoid("OakWoodItem");
$itemPrices["MapleWood"] = "50 0 0 0 0 5 0";
$itemImage["MapleWood"] = nametoid("MapleWoodItem");
$itemPrices["sword"] = "100 0 10 0 0 0 0";
$itemImage["sword"] = nametoid("swordItem");
$itemPrices["bow"] = "50 0 0 0 0 5 0";
$itemImage["bow"] = nametoid("bowItem");
$itemPrices["WarAxe"] = "75 5 5 0 0 0 0";
$itemImage["WarAxe"] = nametoid("WarAxeItem");
$itemPrices["ShortSword"] = "45 5 2 0 0 0 0";
$itemImage["ShortSword"] = nametoid("ShortSwordItem");
$itemPrices["Spear"] = "50 0 0 0 5 0 0";
$itemImage["Spear"] = nametoid("SpearItem");
$itemPrices["PioneerHG"] = "90 5 5 0 3 0 0";
$itemImage["PioneerHG"] = nametoid("PioneerHGItem");
$itemPrices["Longsword"] = "105 5 8 0 0 0 0";
$itemImage["Longsword"] = nametoid("LongswordItem");
$itemPrices["MCrossBow"] = "150 5 5 1 5 0 0";
$itemImage["MCrossBow"] = nametoid("MCrossBowItem");

function serverCmdForge(%client, %item, %amount)
{
   if( %amount < 1 ) // They have to Forge at least 1
      return;

   if( $itemPrices[%item] $= "" )
   {
      messageClient(%client, '', 'You cannot forge that item (%1).', %item);
      return;
   }

   %client.quantity["gold"] = %client.gold;

   %items[0] = "gold";
   %items[1] = "CopperOre";
   %items[2] = "SilverOre";
   %items[3] = "GoldOre";
   %items[4] = "PineWood";
   %items[5] = "OakWood";
   %items[6] = "MapleWood";

   for(%i = 0; %i < 7; %i++)
   {
      %price[%i] = getWord($itemPrices[%item], %i);
      if( %client.quantity[%items[%i]] < (%amount * %price[%i]) )
      {
          messageClient(%client, '', 'You do not have enough %1!', %items[%i]);
          return;
      }
   }

   %msg = "Forging costed you: ";
   for(%i = 0; %i < 7; %i++)
   {
      %amnt = (%amount * %price[%i]);
      if( %amnt != 0 )
         %msg = %msg @ %amnt SPC %items[%i] @ ", ";

      %client.quantity[%items[%i]] -= %amnt;
   }

   %client.quantity[%item] += %amount;

   %image = $itemImage[%item];

   %i = 4;
   while( %i >= -1 )
   {
      if( !%client.player.tool[%i]  || (%client.player.tool[%i].getId() == %image.getId()) )
      {
         break;
      }
      %i--;
   }

   if( %i == -1 )
   {
      messageClient(%client, '', 'Not enough inventory space!');
      return;
   }

   %client.player.tool[%i] = %image;
   messageClient(%client, 'MsgItemPickup', '', %i, %image);
   %client.gold = %client.quantity["gold"];
   messageClient(%client, '', %msg);
}
« Last Edit: June 08, 2008, 08:42:20 PM by Eonz »