Jump to content
MakeWebGames

Need help limiting energy refills


jds137
 Share

Recommended Posts

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();
?>
Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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.";
}
Link to comment
Share on other sites

Guest Anonymous

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

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...