Jump to content

quick help.


seany123

Recommended Posts

in my database i have value named awake and another named maxawake.

 

this code should basically make "awake" + 5 until it reaches "maxawake"

 

but for some reason it isnt doing it..

 

can someone tell me if ive done something wrong?

 

$awakeupdate = $player->awake + 5;
$query = $db->execute("update `players` set `awake`=? where `id`=? and `awake`<`maxawake`",
array($awakeupdate, $player->id));

Link to comment
Share on other sites

I understand, that you want to do something like this

pseudocode:
while (player.awake < player.maxawake) {
   player.awake = player.awake+5;
}

 

And your code does

pseudocode:
if (player.awake < player.maxawake) {
   player.awake = player.awake+5;
}

 

In other words, if you want it to increase player.awake several times, until it reaches player.awakemax, you need to use a loop

 

something like that

 

while (($player->awake + $awakeupdate) < $player->maxawake) {
$awakeupdate += $player->awake + 5;
}
$query = $db->execute("update `players` set `awake`=? where `id`=? and `awake`<`maxawake`",
array($awakeupdate, $player->id));

 

or you can just check, how many 5s you need to add to player.awake to get player.maxawake

$multiplier = (int)(($player->maxawake - $player->awake)/5);
$awakeupdate = $mulitplier * 5;
$query = $db->execute("update `players` set `awake`=? where `id`=? and `awake`<`maxawake`",
array($awakeupdate, $player->id));

 

Link to comment
Share on other sites

no sorry maybe i havnt made myself clear enough.

 

The code above is in a page which is called every X amount of minutes. (its essentially working as a Cron)

 

So i only need it to run once each times the page is called.

 

but for some reason the "awake" value isnt increasing.

Link to comment
Share on other sites

How you connect to database? Is it mysqli?

 

Try doing:

$awakeupdate = $player->awake + 5;
$query = "update `players` set `awake`= `$awakeupdate` where `id`= `$player->id` and `awake`<`maxawake`";
echo $query;

 

And see if query doesn't have errors, and if 'where' conditions are valid.

Link to comment
Share on other sites

for example: this is a cron i use to gain 25% hp.

 

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $hp = $row['hp'] + ($row['maxhp'] * .25);
   $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp;
   $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']);
   mysql_query($query) or die(mysql_error());
}

Link to comment
Share on other sites

<?php
if(!defined('IN_GAME')) die('HACK');

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $energy = $row['energy'] + ($row['maxenergy'] * .20);
   $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy;
   $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $nerve = $row['nerve'] + ($row['maxnerve'] * .20);
   $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve;
   $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $hp = $row['hp'] + ($row['maxhp'] * .25);
   $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp;
   $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']);
   mysql_query($query) or die(mysql_error());
}
<?php
if(!defined('IN_GAME')) die('HACK');

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $energy = $row['energy'] + ($row['maxenergy'] * .20);
   $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy;
   $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $nerve = $row['nerve'] + ($row['maxnerve'] * .20);
   $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve;
   $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $hp = $row['hp'] + ($row['maxhp'] * .25);
   $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp;
   $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']);
   mysql_query($query) or die(mysql_error());
}

update `players` set `awake`= `awake`+5 where `awake`<`maxawake`

?>

Link to comment
Share on other sites

D'oh... That's SQL query, and you're supposed to use it just like other queries, i.e.

 

$query = "UPDATE `players` SET `awake`= `awake`+5 WHERE `awake`<`maxawake`";
mysql_query($query) or die(mysql_error());

 

This should increase `awake` by 5 for all players whose `awake` is lower than their `maxawake`

Link to comment
Share on other sites

$query = "UPDATE `players` SET `awake`= `awake`+5 WHERE `awake`<`maxawake`";
mysql_query($query) or die(mysql_error())

 

is that how it should be done?

 

im sorry i didnt sleep at all last night lol.

 

because i put that code in and still not letting me on my website.

Link to comment
Share on other sites

<?php

if(!defined('IN_GAME')) die('HACK');

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $energy = $row['energy'] + ($row['maxenergy'] * .20);
   $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy;
   $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $nerve = $row['nerve'] + ($row['maxnerve'] * .20);
   $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve;
   $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $hp = $row['hp'] + ($row['maxhp'] * .25);
   $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp;
   $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']);
   mysql_query($query) or die(mysql_error());
}
<?php
if(!defined('IN_GAME')) die('HACK');

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $energy = $row['energy'] + ($row['maxenergy'] * .20);
   $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy;
   $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $nerve = $row['nerve'] + ($row['maxnerve'] * .20);
   $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve;
   $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $hp = $row['hp'] + ($row['maxhp'] * .25);
   $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp;
   $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = $db->execute("update `players` set energy = IF((maxawake + 5)>maxawake, maxawake, (energy + 10))" )
}

?>

Link to comment
Share on other sites

Did you notice that you have your script repeated in this file? Look, there's

<?php
if(!defined('IN_GAME')) die('HACK');

 

in the middle, and after that all the script is repeated from the beginning. Also you didn't put error_reporting(E_ALL) as I told you. It would give you error message on that.[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.