jds137 Posted August 1, 2008 Share Posted August 1, 2008 In the game, I have bought, the energy refill is unlimited atm, and I wanted to ask you all for a code to limit energy refills to 3 a day, as well as make them go up in price each refill. like $25, then $75, then $150 lets say. I tried fixing this, but I am not the greatest at coding atm. <?php include "globals.php"; if(!$_GET['spend']) { print "Welcome to the crystal temple! You have [b]{$ir['crystals']}[/b] crystals. What would you like to spend your crystals on? [url='crystaltemple.php?spend=refill']Energy Refill - {$set['ct_refillprice']} Crystals[/url] [url='crystaltemple.php?spend=IQ']IQ - {$set['ct_iqpercrys']} IQ per crystal[/url] [url='crystaltemple.php?spend=money']Money - \$".number_format($set['ct_moneypercrys'])." per crystal[/url] "; } else { if($_GET['spend'] == 'refill') { if($ir['crystals'] <$set['ct_refillprice']) { print "You don't have enough crystals!"; } else if($ir['energy'] == $ir['maxenergy']) { print "You already have full energy."; } else { $db->query("UPDATE users SET energy=maxenergy,crystals=crystals-{$set['ct_refillprice']} WHERE userid=$userid"); print "You have paid {$set['ct_refillprice']} crystals to refill your energy bar."; } } else if($_GET['spend'] == 'IQ') { print "Type in the amount of crystals you want to swap for IQ. You have [b]{$ir['crystals']}[/b] crystals. One crystal = {$set['ct_iqpercrys']} IQ.<form action='crystaltemple.php?spend=IQ2' method='post'><input type='text' name='crystals' /> <input type='submit' value='Swap' /></form>"; } else if($_GET['spend'] == 'IQ2') { $_POST['crystals']=(int) $_POST['crystals']; if($_POST['crystals'] <= 0 || $_POST['crystals'] > $ir['crystals']) { print "Error, you either do not have enough crystals or did not fill out the form. [url='crystaltemple.php?spend=IQ']Back[/url]"; } else { $iqgain=$_POST['crystals']*$set['ct_iqpercrys']; $db->query("UPDATE users SET crystals=crystals-{$_POST['crystals']} WHERE userid=$userid"); $db->query("UPDATE userstats SET IQ=IQ+$iqgain WHERE userid=$userid"); print "You traded {$_POST['crystals']} crystals for $iqgain IQ."; } } else if($_GET['spend'] == 'money') { print "Type in the amount of crystals you want to swap for money. You have [b]{$ir['crystals']}[/b] crystals. One crystal = \$".number_format($set['ct_moneypercrys']).".<form action='crystaltemple.php?spend=money2' method='post'><input type='text' name='crystals' /> <input type='submit' value='Swap' /></form>"; } else if($_GET['spend'] == 'money2') { $_POST['crystals']=(int) $_POST['crystals']; if($_POST['crystals'] <= 0 || $_POST['crystals'] > $ir['crystals']) { print "Error, you either do not have enough crystals or did not fill out the form. [url='crystaltemple.php?spend=money']Back[/url]"; } else { $iqgain=$_POST['crystals']*$set['ct_moneypercrys']; $db->query("UPDATE users SET crystals=crystals-{$_POST['crystals']},money=money+$iqgain WHERE userid=$userid"); print "You traded {$_POST['crystals']} crystals for \$".number_format($iqgain)."."; } } } $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted August 15, 2008 Share Posted August 15, 2008 Re: Need help limiting energy refills That should be easy just do this... Add to your users table in your database. a row called energyfill Now in your temple page find $db->query("UPDATE users SET energy=maxenergy,crystals=crystals-{$set['ct_refillprice']} WHERE userid=$userid"); print "You have paid {$set['ct_refillprice']} crystals to refill your energy bar."; change it to this $db->query("UPDATE users SET energyfill=energyfill+1, energy=maxenergy,crystals=crystals-{$set['ct_refillprice']} WHERE userid=$userid"); print "You have paid {$set['ct_refillprice']} crystals to refill your energy bar."; Now in temple page find else if($ir['energy'] == $ir['maxenergy']) { print "You already have full energy."; } Add right after that. if($ir['energyfill'] > 3) { print "You have already filled your energy 3 times today."; } That should do it.. Quote Link to comment Share on other sites More sharing options...
Tonka Posted August 15, 2008 Share Posted August 15, 2008 Re: Need help limiting energy refills instead of if($ir['energyfill'] > 3) { print "You have already filled your energy 3 times today."; } this will allow users to refill 4 times use this if($ir['energyfill'] >= 3) { print "You have already filled your energy 3 times today."; } Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted August 15, 2008 Share Posted August 15, 2008 Re: Need help limiting energy refills You would be better of using a separate table, that just has user id, item id and date/time used. That way, if you need to track (say) how many times a particular item is used in a week, a line or two of code is all that is needed rather than loading up the user table with yet another useless row. This is also a cron-less solution, something that should always be strived for Quote Link to comment Share on other sites More sharing options...
Halo Posted August 16, 2008 Share Posted August 16, 2008 Re: Need help limiting energy refills Add in day cron: $db->query("UPDATE users SET energyfill=0"); Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted August 17, 2008 Share Posted August 17, 2008 Re: Need help limiting energy refills opps forgot that lol Quote Link to comment Share on other sites More sharing options...
jds137 Posted August 21, 2008 Author Share Posted August 21, 2008 Re: Need help limiting energy refills thanks, that worked well, I was wondering what I forgot... lol 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.