Jump to content

Query help.


SieRobin

Recommended Posts

Ok, so I'm running a web-based RPG, and I have 3 cron jobs set up. I have turns set at every 6 minutes, Hit Points regeneration every 5 minutes, and revive if dead over 30 minutes.

My problem is, is that I want it to be able to query something if they're alive but are missing HP it will tick 1 HP every 5 minutes. The way I currently have it set up, doesn't work, because if you set a session for it, all it will really do is tick if you're logged in and missing HP and also it will only revive you if you're logged in. The other way I tried doing it was removing the session and just pulling it from the users.. well it will always tick, but if they're dead it will still tick, if they're dead I don't want them to recieve HP. Does anyone have any ideas on how I could set this up, so it will only query HP Regen if you're Alive and query Revive only if you're Dead.

Thanks for the help in advanced :D

Regen Over-Time
[code]<?php
session_start();    
include "connect.php";
if (isset($_SESSION['player']))
    {
    $player=$_SESSION['player'];
    $stats="SELECT * from users";
    $stats2=mysql_query($stats) or die("Could not retrieve the users stats.");
    $stats3=mysql_fetch_array($stats2);
    if ($stats3['dead']=='Dead')
        {
        mysql_query("update users set hp=1, dead='Alive'") or die("Could not query");
        }
    }
?>[/code]

Revive Over-Time
[code]<?php
session_start();    
include "connect.php";
if (isset($_SESSION['player']))
    {
    $player=$_SESSION['player'];
    $stats="SELECT * from users";
    $stats2=mysql_query($stats) or die("Could not retrieve the users stats.");
    $stats3=mysql_fetch_array($stats2);
    if ($stats3['dead']=='Dead')
        {
        mysql_query("update users set hp=1, dead='Alive'") or die("Could not query");
        }
    }
?>[/code]
Link to comment
Share on other sites

Question 1: getting around the session issue: just don't use them. have cron hit a separate PHP file all by itself to check for alive or dead. rephrase your question if this doesn't make sense.

Question 2:
your code will set hp=1 and dead="Alive" to every user it sees, but only if the first one is dead.
[code]
    $stats="SELECT * from users";
    $stats2=mysql_query($stats) or die("Could not retrieve the users stats.");
    $stats3=mysql_fetch_array($stats2);
    if ($stats3['dead']=='Dead') {
        mysql_query("update users set hp=1, dead='Alive') or die("Could not query");
    }
[/code]

the following will fix your dead users:
[code]
    mysql_query("update users set hp=1, dead='Alive' WHERE dead='Dead'") or die("Could not query");
[/code]

Revive Over-Time: Your code is missing (well, you pasted the same code twice). Here's a guess:
[code]
    $player=$_SESSION['player'];
    $stats="SELECT * from users";
    $stats2=mysql_query($stats) or die("Could not retrieve the users stats.");
    while($stats3=mysql_fetch_array($stats2))     mysql_query("update users set hp=".$stats3['hp']+1." WHERE user = '".$stats3['user']."'") or die("Could not query");
[/code]

Sorry, one last update... had to loop the last one -- but a better SQL programmer might be able to tell you how to increment that HP instead of looping PHP to do it. also, I'm guessing that you're user field is called "user" -- if not, you'll have to change it in the code to match.
Link to comment
Share on other sites

Oops, sorry about that..

[code]<?php
include "connect.php";
    $stats="SELECT * from users";
    $stats2=mysql_query($stats) or die("Could not retrieve the users stats.");
    $stats3=mysql_fetch_array($stats2);
    if ($stats3['dead']=='Alive') {
          if ($stats3['race']=='Troll') {
        mysql_query("update users set hp=(hp+2) where hp<mhp") or die("Could not query.");
        } else {
        mysql_query("update users set hp=(hp+1) where hp<mhp") or die("Could not query.");
      }
  }
?>[/code]
Link to comment
Share on other sites

I'm not sure about your SQL incremental code there -- but if it works, I'll make a note for my own use :)

Based on this new information here's a SQL rewrite that should work (if your incremental code works, that is)

[code]<?php
include "connect.php";
mysql_query("update users set hp=(hp+2) where hp<mhp AND `dead` = 'Alive' AND `race` = 'Troll'") or die("Could not query.");
mysql_query("update users set hp=(hp+1) where hp<mhp AND `dead` = 'Alive' AND `race` != 'Troll'") or die("Could not query.");
?>[/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.