Jump to content
MakeWebGames

Need help With trading points for items


bennybwoi

Recommended Posts

ok basically ive been tryin to make it so that you can trade in crystals for items (on my game its points) i made the table and item and everythign but then i got to the function part which looks lik this:

}
function crystals()
{
global $db,$ir,$c,$userid,$h;
if($ir['points'] > 11)
{
print "You have just traded 12 points for 20 crystals!
[size="1"]> [/size][url='pointstrader.php']Back[/url]";
$points = 12;
$sql = sprintf("UPDATE users SET points = points - %u WHERE userid = ". $userid .";",$points);
mysql_query($sql);
$crystals = 20;
$sql = sprintf("UPDATE users SET crystals = crystals + %u WHERE userid = ". $userid .";",$crystals);
mysql_query($sql);
}
else
{
print "You havnt got enough points to trade!
[size="1"]> [/size][url='pointstrader.php']Back[/url]";
}
}

 

so basically i need someone to show me how to change the code to credit an item instead of crystals

if it helps the item id is 10.

any help will b of great help to me :).

Link to comment
Share on other sites

function crystals() {
global $db,$ir,$userid;
$itemname = 'ITEMNAMEHERE'; // change this to the name of the item
$itemid = 10; // item id
$points = 12; // amount of points needed
 if($ir['points'] >= $points) {
  echo '
You have just traded '.$points.' points for '.$itemname.'


[size="1"]> [/size][url="pointstrader.php"]Back[/url]
  ';
$sql = sprintf("UPDATE `users` SET `points` = `points` - %u WHERE `userid` = ". $userid .";",$points); // gathers the information for submission
$db->query($sql); // submits the query to the database
item_add($userid, $itemid, 1); // This function is defined in global_func.php
 } else {
  echo '
You havnt got enough points to trade.


[size="1"]> [/size][url="pointstrader.php"]Back[/url]
  ';
 }
}

I got abit bored thought i'd give you a hand, Please remember when using global to only really pull what you actually want it's just easier.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...