Re: [mccode] Stats Market
<?php
include "globals.php";
print "<h3>Stats Market</h3>";
$_GET['ID'] = abs(@intval($_GET['ID']));
switch($_GET['action'])
{
case "buy":
stats_buy();
break;
case "remove":
stats_remove();
break;
case "add":
stats_add();
break;
default:
statsmarket_index();
break;
}
function statsmarket_index()
{
global $db,$ir,$c,$userid,$h;
print "[url='statsmarket.php?action=add']> Add A Listing[/url]
Viewing all listings...
<table width=75% cellspacing=1 class='table'> <tr style='background:gray'> <th>Adder</th> <th>Stat</th> <th>Qty</th> <th>Price each</th> <th>Price total</th> <th>Links</th> </tr>";
$q=$db->query("SELECT sm.*, u.* FROM statsmarket sm LEFT JOIN users u ON u.userid=sm.smADDER ORDER BY smPRICE/smQTY ASC");
while($r=$db->fetch_row($q))
{
if($r['smADDER'] == $userid) { $link = "[url='statsmarket.php?action=remove&ID={$r[']Remove[/url]"; } else { $link = "[url='statsmarket.php?action=buy&ID={$r[']Buy[/url]"; }
$each= (float) $r['smPRICE'] / $r['smQTY'];
print "\n<tr> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]</td> <td>{$r['smSTATS']}</td> <td>{$r['smQTY']}</td> <td> \$" . number_format($each)."</td> <td>\$".number_format($r['smPRICE'])."</td> <td>[$link]</td> </tr>";
}
print "</table>";
}
function stats_remove()
{
global $db,$ir,$c,$userid,$h;
$f = mysql_query("SELECT * FROM statsmarket WHERE smID='{$_GET['ID']}'") or die(mysql_error());
$a = mysql_fetch_assoc($f);
$q=$db->query("SELECT us.*,sm.* FROM statsmarket sm LEFT JOIN userstats us ON sm.smQTY=us.{$a['smSTATS']} WHERE sm.smID='{$_GET['ID']}' AND sm.smADDER='{$ir['userid']}'");
if(!$db->num_rows($q))
{
print "Error, either this listing doesn't exist, or you are not the owner.
[url='statsmarket.php']> Back[/url]";
$h->endpage();
exit;
}
$r=$db->fetch_row($q);
//FIXED
$db->query("UPDATE userstats SET {$r['smSTATS']}={$r['smSTATS']}+{$r['smQTY']} WHERE userid='{$ir['userid']}'") or die(mysql_error());
$db->query("DELETE FROM statsmarket WHERE smID={$_GET['ID']}");
print "Stats removed from market!
[url='statsmarket.php']> Back[/url]";
}
function stats_buy()
{
global $db,$ir,$c,$userid,$h;
$q=$db->query("SELECT * FROM statsmarket st WHERE smID={$_GET['ID']}");
if(!$db->num_rows($q))
{
print "Error, either this listing doesn't exist, or it has already been bought.
[url='statsmarket.php']> Back[/url]";
$h->endpage();
exit;
}
$r=$db->fetch_row($q);
if($r['smPRICE'] > $ir['money'])
{
print "Error, you do not have the funds to buy these stats.
[url='statsmarket.php']> Back[/url]";
$h->endpage();
exit;
}
$db->query("UPDATE userstats SET {$r['smSTATS']}={$r['smSTATS']}+{$r['smQTY']} WHERE userid=$userid");
$db->query("DELETE FROM statsmarket WHERE smID={$_GET['ID']}");
$db->query("UPDATE `users` SET `money` = `money` - {$r['smPRICE']} WHERE `userid`={$ir['userid']}");
$db->query("UPDATE `users` SET `money`=`money` + {$r['smPRICE']} where `userid`={$r['smADDER']}");
event_add($r['smADDER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] bought your {$r['smQTY']} {$r['smSTATS']} from the market for \$".number_format($r['smPRICE']).".",$c);
print "You bought the {$r['smQTY']} {$r['smSTATS']} from the market for \$".number_format($r['smPRICE']).".";
print "
[url='statsmarket.php']> Back[/url]";
}
function stats_add()
{
global $db,$ir,$c,$userid,$h;
$_POST['amnt'] = abs($_POST['amnt']);
$_POST['price'] = abs($_POST['price']);
if($_POST['amnt'])
{
if($_POST['amnt'] > $ir['strength']-10 || $_POST['amnt'] > $ir['IQ']-10 || $_POST['amnt'] > $ir['labour']-10 || $_POST['amnt'] > $ir['agility']-10 || $_POST['amnt'] > $ir['guard']-10)
{
echo "You are trying to add more stats to the market than you can add.
Look at the stats, at the stat that you have the least of. Subtract that number by 10.
That's the most you can add per listing for any stat.
For example, if your lowest stat is IQ with 100 IQ, the most you can list per listing for any stat is 90.
You must always have at least 10 of all stats.
Strength: {$ir['strength']}
Agility: {$ir['agility']}
Guard: {$ir['guard']}
Labour: {$ir['labour']}
IQ: {$ir['IQ']}
<a href='statsmarket.php'>> Back";
$h->endpage();
exit;
}
if($_POST['price'] > 200)
{
echo "You can only sell stats for up to 200 each.
<a href='statsmarket.php'>> Back";
$h->endpage();
exit;
}
$a = mysql_query("SELECT * FROM statsmarket WHERE smADDER='{$ir['userid']}'") or die(mysql_error());
if(mysql_num_rows($a) > 3)
{
echo 'You may only add a certain ammount of stats.';
$h->endpage();
exit;
}
$tp=$_POST['amnt']*$_POST['price'];
$db->query("INSERT INTO statsmarket VALUES('',{$_POST['amnt']},$userid,$tp,'{$_POST['sellstat']}')");
$db->query("UPDATE userstats SET {$_POST['sellstat']}={$_POST['sellstat']}-{$_POST['amnt']} WHERE userid=$userid");
print "Stats added to market!
[url='statsmarket.php']> Back[/url]";
}
else
{
print "[b]Adding a listing...[/b]
Look at the stats, at the stat that you have the least of. Subtract that number by 10.
That's the most you can add per listing for any stat.
For example, if your lowest stat is IQ with 100 IQ, the most you can list per listing for any stat is 90.
You must always have at least 10 of all stats.
<form action='statsmarket.php?action=add' method='post'><table width=70% border=2><tr><td>Stats to add to market: </td> <td>
<select type='dropdown' name='sellstat'>
<option value='strength'>Strength (Have {$ir['strength']})
<option value='agility'>Agility (Have {$ir['agility']})
<option value='guard'>Guard (Have {$ir['guard']})
<option value='labour'>Labour (Have {$ir['labour']})
<option value='IQ'>IQ (Have {$ir['IQ']})</select></td></tr><tr>
<td>How many stats:</td> <td><input type='text' name='amnt' value='' /></td></tr><tr>
<td>Price for each stat:</td> <td><input type='text' name='price' value='200' /></td></tr><tr>
<td colspan=2 align=center><input type='submit' value='Add To Market' /></tr></table></form>";
}
}
$h->endpage();
?>
You can try that.