Jump to content
MakeWebGames

Recommended Posts

Posted

hi, im wondering can anyone make this for me and can you give me a link to a page who has already made this mod. i have searched but had no luck...

its a crystals market where you can buy a quanity of crystals on the market like say...

a player had 1512 crystals on the market

you can have the option of buying between 1-1512 crystals.

and say you buy 12 crystals from that player who put the crystals up.

there will then be 1500 crystals left on the market.

hopefully you understand what i mean lol.

thanks, Nicholas.

Posted

Code posted, thanks to Djkanna for finding it for me xD

 

<?php
//Crystal Market, free for Dev Forum
//Copyright (c), 2009 Magictallguy
//Not for resale
//If you don't understand it, leave it alone
include(DIRNAME(__FILE__) . '/globals.php');
echo "<h3>Crystal Market</h3>";
$_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : false;
$_GET['act2'] = isset($_GET['act2']) && is_string($_GET['act2']) ? strtolower(trim($_GET['act2'])) : false;
$_GET['ID'] = isset($_GET['ID']) && is_numeric($_GET['ID']) ? abs(@intval($_GET['ID'])) : false;
switch($_GET['action'])
{
case 'add': add_listing(); break;
case 'remove': remove_listing(); break;
case 'buy': buy_crystals(); break;

default: index(); break;
}

function index()
{
global $db, $userid;
echo "Viewing all listings
";
echo "[url='cmarket.php?action=add']Add a listing[/url]
";
echo "<table class='table' width='100%'>";

echo "<tr>";
echo "<th>Player</th>";
echo "<th>Crystals</th>";
echo "<th>Price</th>";
echo "<th>Link</th>";
echo "</tr>";

$query = $db->query(
"SELECT c.*, u.username " .
"FROM crystalmarket c " .
"LEFT JOIN users u ON (u.userid = c.cmADDER) " .
"ORDER BY c.cmQTY ASC, c.cmPRICE ASC");
if(!$db->num_rows($query))
{
echo "<tr>";
echo "<td colspan='4' style='text-align:center;'>There are no listings</td>";
echo "</tr>";
}

while($row = $db->fetch_row($query))
{
$total = $row['cmQTY'] * $row['cmPRICE'];
$link = ($row['cmADDER'] == $userid)
? sprintf("[url='cmarket.php?action=remove&ID=%u']Remove[/url]", $row['cmID'])
: sprintf("[url='cmarket.php?action=buy&ID=%u']Buy[/url]", $row['cmID']);
echo "<tr style='text-align:center;'>";
echo sprintf("<td>[url='viewuser.php?u=%u']%s[/url] [%s]</td>", $row['cmADDER'], stripslashes(htmlspecialchars($row['username'])), number_format($row['cmADDER']));
echo sprintf("<td style='text-align:right;'>%s</td>", number_format($row['cmQTY']));
echo sprintf("<td style='text-align:right;'>Total: \$%s
<span style='font-size:10px;'>(Each: \$%s)</span></td>", number_format($total), number_format($row['cmPRICE']));
echo sprintf("<td>%s</td>", $link);
echo "</tr>";
}
echo "</table>";
}

function buy_crystals()
{
global $ir, $db, $userid, $h;
if(!$_GET['ID'])
{
echo "Listing ID not specified.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
if(!$ir['money'])
{
echo "You have no money.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
$select = sprintf("SELECT * FROM crystalmarket WHERE (cmID = %u)", $_GET['ID']);
$query = $db->query($select);
if(!$db->num_rows($query))
{
echo "This listing does not exist.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
$row = $db->fetch_row($query);
if($row['cmADDER'] == $userid)
{
echo "You can't buy your own listing.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
$total = $row['cmQTY'] * $row['cmPRICE'];
$icanbuy = floor($ir['money'] / $row['cmPRICE']);
$cost = $icanbuy * $row['cmPRICE'];
$name = $db->fetch_single($db->query(sprintf("SELECT username FROM users WHERE (userid = %u)", $row['cmADDER'])));
if($total > $ir['money']) { $_GET['act2'] = 'buysome'; }
if(!$icanbuy)
{
echo "You don't have enough money.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
switch($_GET['act2'])
{
default:

$update1 = sprintf("UPDATE users SET money = money - %s, crystals = crystals + %u WHERE (userid = %u)", $total, $row['cmQTY'], $userid);
$update2 = sprintf("UPDATE users SET money = money + %s WHERE (userid = %u)", $total, $row['cmADDER']);
$delete = sprintf("DELETE FROM crystalmarket WHERE (cmID = %u)", $_GET['ID']);
$db->query($update1);
$db->query($update2);
$db->query($delete);

$event = sprintf("[url='viewuser.php?u=%u']%s[/url] bought your %s crystal%s for \$%s from the crystal market", $userid, $ir['username'], number_format($row['cmQTY']), ($row['cmQTY'] == 1) ? '' : 's', number_format($total));
event_add($row['cmADDER'], $event);

echo sprintf("You bought the %s crystal%s from %s for \$%s.
[url='cmarket.php']Back[/url]", number_format($row['cmQTY']), ($row['cmQTY'] == 1) ? '' : 's', stripslashes(htmlspecialchars($name)), number_format($total));
break;

case 'buysome':
if($ir['money'] < $row['cmPRICE'])
{
echo "You don't have enough money.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
if(!isset($_POST['buy']))
{
echo "You don't have enough money to buy all of the crystals listed.
";
echo sprintf("But you do have enough to buy %s crystal%s, costing you \$%s.
", number_format($icanbuy), ($icanbuy == 1) ? '' : 's', number_format($cost));
echo "Would you like to buy that amount instead?
";
echo sprintf("<form action='cmarket.php?action=buy&ID=%u&act2=buysome' method='post'>", $_GET['ID']);
echo "<input type='submit' name='buy' value='Yes' /> <input type='button' value='No' onclick='location.href=\"cmarket.php\"' />";
echo "</form>";
}
else
{
$update1 = sprintf("UPDATE users SET money = money - %s, crystals = crystals + %u WHERE (userid = %u)", $cost, $icanbuy, $userid);
$update2 = sprintf("UPDATE users SET money = money + %s WHERE (userid = %u)", $cost, $row['cmADDER']);
$update3 = sprintf("UPDATE crystalmarket SET cmQTY = cmQTY - %u WHERE (cmID = %u)", $icanbuy, $_GET['ID']);
$db->query($update1);
$db->query($update2);
$db->query($update3);

$event = sprintf("[url='viewuser.php?u=%u']%s[/url] bought %s of your %s crystal%s for \$%s from the crystal market", $userid, $ir['username'], number_format($icanbuy), number_format($row['cmQTY']), ($row['cmQTY'] == 1) ? '' : 's', number_format($cost));
event_add($row['cmADDER'], $event);

echo sprintf("You have bought %s crystal%s from %s for \$%s.
[url='cmarket.php']Back[/url]", number_format($icanbuy), ($icanbuy == 1) ? '' : 's', stripslashes(htmlspecialchars($name)), number_format($cost));
}
break;
}
}

function remove_listing()
{
global $db, $userid, $h;
if(!$_GET['ID'])
{
echo "Listing ID not specified.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
$select = sprintf("SELECT * FROM crystalmarket WHERE ((cmID = %u) AND (cmADDER = %u))", $_GET['ID'], $userid);
$query = $db->query($select);
if(!$db->num_rows($query))
{
echo "Either this listing does not exist, or you don't own it.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}

$row = $db->fetch_row($query);
$update = sprintf("UPDATE users SET crystals = crystals + %u WHERE (userid = %u)", $row['cmQTY'], $userid);
$delete = sprintf("DELETE FROM crystalmarket WHERE (cmID = %u)", $_GET['ID']);
$db->query($update);
$db->query($delete);

echo "Your crystals have been returned to you";
}

function add_listing()
{
global $db, $userid, $h, $ir;
echo "<h4>Adding a listing to the Crystal Market</h4>";
if(!$ir['crystals'])
{
echo "You don't have any crystals.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}

if(!isset($_POST['crystals']) || empty($_POST['price']))
{
echo "<form action='cmarket.php?action=add' method='post'>";
echo "<table class='table' width='50%' style='text-align:center;'>";

echo "<tr>";
echo "<th>Amount</th>";
echo "<td><input type='text' name='crystals' /></td>";
echo "</tr>";

echo "<tr>";
echo "<th>Price</th>";
echo "<td><input type='text' name='price' /></td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'><input type='submit' value='Submit' /></td>";
echo "</tr>";

echo "</table>";
echo "</form>";
}
else
{
if($_POST['crystals'] > $ir['crystals'])
{
echo "You don't have enough crystals.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}
$_POST['price'] = abs(@intval($_POST['price']));
if(!$_POST['price'])
{
echo "You didn't enter a valid price.
[url='cmarket.php']Back[/url]";
$h->endpage();
exit;
}

$update = sprintf("UPDATE users SET crystals = crystals - %u WHERE (userid = %u)", $_POST['crystals'], $userid);
$insert = sprintf("INSERT INTO crystalmarket VALUES ('', %u, %u, %u)", $_POST['crystals'], $userid, $_POST['price']);
$db->query($update);
$db->query($insert);

echo "Your listing has been added to the market.
[url='cmarket.php']Back[/url]";
}
}
$h->endpage();
?>

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...