hobbes Posted November 2, 2008 Share Posted November 2, 2008 Here's a script for the Crystal Market that allows you to buy a certain amount of crystals rather than all of them at once (as in the stock mccode). I am sure many experienced scripters can update this to make it more simple, but it works and I haven't had any problems with it. First things first, open your cmarket.php and add the following case statement at the top: case "get": get_crystals(); break; Here are the edited crystal_buy and crystal_get functions that I am using. Place these in your cmarket.php script. This one is an edited version of the crystal_buy function. You can replace the whole function with this one. function crystal_buy() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM crystalmarket cm WHERE cmID={$_GET['ID']}"); //non-existant crystals if(!$db->num_rows($q)) { print "Error, either these crystals do not exist, or they have already been bought. "; $h->endpage(); exit; } $r=$db->fetch_row($q); //crystal price $price=$r['cmPRICE'] / $r['cmQTY']; $id=($_GET['ID']); print "How many crystals would you like to buy? You can buy a maximum of {$r['cmQTY']} crystals for $ \$".number_format($price)." each. <form name='buy' action='cmarket.php?action=get&ID={$id}' method='post'> <input type='int' name='qty' class='texta' size='8'> <input type='submit' value='Buy Crystals'> </form>"; } And the new function, get_crystals: function get_crystals() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT * FROM crystalmarket cm WHERE cmID={$_GET['ID']}"); //non-existant tokens if(!$db->num_rows($q)) { print "Error, either these crystals do not exist, or they have already been bought. "; $h->endpage(); exit; } $r=$db->fetch_row($q); $id=($_GET['ID']); $qty=($_POST['qty']); $price=($r ['cmPRICE'] / $r['cmQTY']); $total=($qty * $price); $cmprice=($r['cmPRICE'] - $total); $cmqty=($r['cmQTY'] - $qty); //not enough money if($total > $ir['money']) { die("You do not have enough money to purchase {$qty} crystals."); } if(!is_numeric($qty)) { die('Your quantity must be numeric! (and no white spaces)'); } if(!isset($qty)) { die('You must enter how many crystals you would like to purchase.'); } if($qty > $r['cmQTY']) { die('There are not that may crystals available to purchase'); } $db->query("UPDATE users SET crystals=crystals+{$qty} where userid=$userid"); $db->query("UPDATE crystalmarket SET cmQTY={$cmqty} WHERE cmID={$id}"); $db->query("UPDATE crystalmarket SET cmPRICE={$cmprice} WHERE cmID={$id}"); if($cmqty < 1) { $db->query("DELETE FROM crystalmarket WHERE cmID={$id}"); } $db->query("UPDATE users SET money=money-{$total} where userid=$userid"); $db->query("UPDATE users SET money=money+{$total} where userid={$r['cmADDER']}"); $db->query("INSERT INTO clogs VALUES('',$userid,{$r['cmADDER']},{$qty},{$total},unix_timestamp());",$c); event_add($r['cmADDER'],"{$ir['username']} bought {$qty} crystals from the market for \$".number_format($total).".",$c); print "You bought the {$qty} crystals from the market for \$".number_format($total)."."; } My version is slightly different as I use something other than crystals, but I have edited it down to a pure mccode stock substitute. This is my first php script post on CE, so be nice. :roll: Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted November 3, 2008 Share Posted November 3, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All I don't have time to edit it but * is a bad idea mate, sorry about not having time to edit it. Quote Link to comment Share on other sites More sharing options...
Neji_Hyuuga Posted November 3, 2008 Share Posted November 3, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All i added it mate but it was still like the normal cmarket for me mate i never got to option to buy a certain amount of them Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted November 3, 2008 Share Posted November 3, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All nice work Quote Link to comment Share on other sites More sharing options...
hobbes Posted November 3, 2008 Author Share Posted November 3, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All I don't have time to edit it but * is a bad idea mate, sorry about not having time to edit it. Why is it a bad idea to buy a set amount rather than a large lump sum? Many games allow players to buy a certain amount of crystals, points, etc. Could you be a bit more specific? Not quite sure why it's not working for you Neji, as long as it directs to the buy function in cmarket, the following should display how many 'crystals' you want to buy. print "How many crystals would you like to buy? You can buy a maximum of {$r['cmQTY']} crystals for $ \$".number_format($price)." each. <form name='buy' action='cmarket.php?action=get&ID={$id}' method='post'> <input type='int' name='qty' class='texta' size='8'> <input type='submit' value='Buy Crystals'> </form>"; Quote Link to comment Share on other sites More sharing options...
Neji_Hyuuga Posted November 4, 2008 Share Posted November 4, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All i got it to add mate but when i went on the cmarket i had to click on buy to type in a amount of how many i wanted and then once i typed in the box i got a query error but it still let me buy the crystals how do i stop that error can anyone plz help me with it Quote Link to comment Share on other sites More sharing options...
hobbes Posted November 4, 2008 Author Share Posted November 4, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All yea, obviously you have to clickon buy before you pick the qty you want to purcahse ;) what is the query error? Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted November 5, 2008 Share Posted November 5, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All * is a bad idea when you can simply do for example You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. the above is a example this obviously wont work if you do not change things in it lol Quote Link to comment Share on other sites More sharing options...
HITMAN 17 Posted November 6, 2008 Share Posted November 6, 2008 Re: Crystal Market - Buy Amount of Crystals, Not All this works for my v1 version Quote Link to comment Share on other sites More sharing options...
HITMAN 17 Posted February 10, 2009 Share Posted February 10, 2009 Re: [mccode] Crystal Market - Buy Amount of Crystals, Not All great if mod actually worked Quote Link to comment Share on other sites More sharing options...
Dave Posted February 11, 2009 Share Posted February 11, 2009 Re: [mccode] Crystal Market - Buy Amount of Crystals, Not All I made something simular on www.copsandcrooks.com (Dead game, I know most of its crap just wanted to piss around with Mccodes LITE). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.