AnonymousUser Posted January 5, 2013 Posted January 5, 2013 i've got an ajax gym but i'm having troubles trying to add the ability to use an item if they got it if not then use crystals... function refill() { global $db; define('refill_cost', ($_GET['stat'] == 'energy') ? 10 : 50); $crystals = mysql_result($db->query("SELECT `crystals` FROM `users` WHERE (`userid` = ". $_SESSION['userid'] .");"), 0, 0); if($crystals < refill_cost) { echo'<font style=color:red;>You don\'t have enough crystals to refill your '. ($_GET['stat']) .'.</font>'; exit(); } $db->query("UPDATE `users` SET `crystals` = `crystals` - ". refill_cost .", `". $_GET['stat'] ."` = `max". $_GET['stat'] ."` WHERE (`userid` = ". $_SESSION['userid'] .");"); echo ucwords($_GET['stat']) .' <font style=color:green;> has been refilled.</font>'; } Quote
The Phantom Posted January 5, 2013 Posted January 5, 2013 Well, you can use your crystal temple? Quote
The Phantom Posted January 5, 2013 Posted January 5, 2013 Try somethink like this? if( $ir['energy'] == "0" ) { echo" <table width='90%'><tr><td><p> You dont have any energy for taining <a href='crystaltemple.php?spend=refill'><font color='green'>[Refill Energy]</font></a></p></td></tr></table> <br /> "; } else { Quote
AnonymousUser Posted January 5, 2013 Author Posted January 5, 2013 it's using crystals now i wanna add ability to use the item BEFORE the crystals... Quote
sniko Posted January 5, 2013 Posted January 5, 2013 Quite simple, really. /* Put this at the top of the file */ define("__item__", 20); //Change the value (20) to the item id you want /* * Create a function to check if they have the required item If YES, return TRUE If NO, return FALSE */ function hasItem($itemid) { global $db, $userid; $get = $db->query("SELECT `inv_itemid` FROM `inventory` WHERE (`inv_itemid`={$itemid}) AND (`inv_userid`={$userid}) AND (`inv_qty` > 0)"); if( $db->num_rows($get) ) return TRUE; else return FALSE; } /* Now, use that function (above) to our advantage Put this segment (merge it in) with where you display the links */ if( hasItem(__item__) ) { echo '<a href="?spend=refill">Use Item</a>'; } else { echo '<a href="?spend=refill">20 Crystals</a>'; } /* Now either deduct the item, or crystals Merge it in with the query to deduct crystals */ if( hasItem(__item__) ) { item_remove($userid, __item__, 1); } else { $db->query("UPDATE `users` SET `crystals`=`crystals`-20 WHERE `userid`={$userid}"); } I use define() so we don't have to global something every function; that's if you use functions I'm unsure on the parameters, and name, of item_remove Change 20 to the amount of crystals you use Use common sense to merge the codes above into both systems Above code is untested. Should work. Quote
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.