Selling?

Author Topic: Selling?  (Read 994 times)

Ok so im trying to make a system for my rpg that if I have say 10 ore I can type /sell ore 10 and Ill gain 50 gold Ore = 5 gold. But when I try use this and I have 10 ore and type /sell ore 10 it say's Not enough Ore, Ore:10

Code: [Select]
//Sell

$itemprices["Ore"]=5;

function serverCmdSell(%client,%item,%ammount){
$amount = $client.ore[%item];
if(%amount==0||%Amount>%client.Gold){
messageClient(%client,'','Not enough Ore!Ore: %1',%client.Ore);
return;
}
%client.Gold+=%amount;
}

First of all, I suggest indenting your code to make it easier for both you and us to read:
Code: [Select]
//Sell

$itemPrices["Ore"]=5;

function serverCmdSell(%client, %item, %ammount)
{
   $amount = $client.ore[%item];

   if(%amount == 0 || %Amount > %client.Gold)
   {
      messageClient(%client, '', 'Not enough Ore! Ore: %1', %client.Ore);
      return;
   }

   %client.Gold += %amount;
}

This makes it easier to see your 3 easy to make mistakes:
1. You made a typo in the 3rd argument (%ammount).
2. You said $amount instead of %amount. It's not a global variable.
3. You said $client.ore[%item] instead of %client.ore[%item]. Same problem.


Another problem (a logistical one this time) is that you forgot to factor in the price of the item when you added %amount to the client's gold. It should look more like this:
Code: [Select]
...
   %client.Gold += (%amount * $itemPrices[%item]);

Also, in %amount > %client.Gold... you're saying, "if the amount of items the player wants to sell is greater than the amount of gold the player has, then...". Does this makes sense? You should instead say %amount > %client.quantity[%item]. This means you have to keep track of the quantitiy of each item a client has.
« Last Edit: May 27, 2008, 09:02:31 PM by exidyne »

Didn't see edit sorry

So, here's an idea of what it should look like:
Code: [Select]
$itemPrices["Ore"] = 5;

function serverCmdSell(%client, %item, %amount)
// This shouldn't have anything to do specifically with ore! You can sell stuff other than ore.

{
   $amount = $client.ore[%item]; // I don't know what this does

   if( %amount < 1 ) return; // You have to sell at least 1 item

   if( %amount > %client.quantity[%item] ) // If they're trying to sell more than they have:
   {
      messageClient(%client, '', 'Not enough %1! %1: %2', %item, %client.quantity[%item]);
      return;
   }

   // Add to their gold the amount * price of item:
   %client.Gold += (%amount * $itemPrices[%item]);
}
« Last Edit: May 27, 2008, 09:07:18 PM by exidyne »

Ok well with this it say's that I dont have enough ore but when I type /checkore I have 10. Btw get on MSN 
Code: [Select]
$itemPrices["Ore"] = 5;

function serverCmdSell(%client, %item, %amount)

{
   $amount = $client.Ore[%item]; // I don't know what this does

   if( %amount < 1 ) return; // You have to sell at least 1 item

   if( %amount > %client.quantity[%item] ) // If they're trying to sell more than they have:
   {
      messageClient(%client, '', 'Not enough %1! %1: %2', %item, %client.quantity[%item]);
      return;
   }

   // Add to their gold the amount * price of item:
   %client.Gold += (%amount * $itemPrices[%item]);
}
« Last Edit: May 27, 2008, 09:17:03 PM by Kunit_Yo »

Well, you're gunna need to show what /checkore does. It should do something like this:
Code: [Select]
function serverCmdCheckOre(%client)
{
   messageClient(%client, '', 'You have %1 ore.', %client.quantity["Ore"]);
}

You have to find some way of keeping track of how much ore a player has and storing that amount (in %client.quantity["Ore"]).
To debug, try doing: ClientGroup.getObject(0).quantity["Ore"] = 10; to give yourself 10 ore.

The most likely thing is that he doesnt use %client.quantity["item"] for the ore variable.