Jump to content
MakeWebGames

Recommended Posts

Posted

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>';
       }
Posted

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

{ 
Posted

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.

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