Jump to content
MakeWebGames

Query Question (Energy)


illegalife

Recommended Posts

How do i make it so it takes away 10% energy from a user, this query just

$db->query("UPDATE users SET energy=maxenergy-10 WHERE userid=$userid");

$db->query("UPDATE users SET energy=maxenergy WHERE energy>maxenergy");

and also how do i make it so it dies if its less then 10% energy

if($ir['energy'] < 1)

{

die("Sorry, it costs 10 energy to bust someone. You only have {$ir['energy']} energy. Come back later.");

Link to comment
Share on other sites

Re: Query Question (Energy)

Maybe somethign like this...

 

$percent = $ir['maxenergy'] / 10;

//Takes 10% from them
$update = sprintf("UPDATE users SET energy = energy - '%u' WHERE userid = '%u' ",
   ($percent),
   ($userid));
       mysql_query($update);

//This stops energy below "0"
$check = sprintf("UPDATE users SET energy = '%d' WHERE energy < '%d' AND userid = '%u' ",
   (0),
   (0),
   ($userid));
       mysql_query($check);

if($ir['energy'] < $percent)
{
die("DIE MESSAGE");
}

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.

×
×
  • Create New...