Jump to content

How to make a value in the Database raise every minute


Recommended Posts

Hi.

 

I am trying to figure out how to make a value in the database raise every minute.

Lets say, I want the HP to raise every minute.

The max HP is 100. I want it to raise 5 HP/ Hour. And the player don't have to be online. Anyone who know how I can do it =?

 

Thanks for any help.

 

//Feelay

hi..

 

soudns liek your writing a game - meanign youll ve getting a lot of database trafic.

 

instead why not have a text file for the HP  - and then hevery tiem someone reads it - check if the time is + 60 seconds - then write new values to it.

 

eg  have the file say:

 

last_time: "timestamp"

HP: 5;

 

then jsut check to see if the timestamp is as above and then do the same.  you could do the same through mySQL if you wanted.

 

gdlk

<?php
$current_timestamp = time();
$current_date = date( 'l  jS M Y, g:i A', $current_timestamp );
echo( 'The current time-stamp is: ' . $current_timestamp . '. To put that into a human-readable format, the current date from afore-mentioned time-stamp is: ' . $current_date );
?>

ok.. some people on another forum helped me a bit.. but neither me or they can solve this problem..

The health keeps showing 1HP when the max is 280, and the hp should raise 5hp every 2 seconds..

Here is the code:

 

<?php
session_start();
include "database.php";
include "hptime.php";
include "level.php";
$nuser=mysql_real_escape_string($_SESSION['user']);
$auser=mysql_real_escape_string($_SESSION['admin']);

if($nuser){
$userfinal=$nuser;
}elseif($auser){
$userfinal=$auser;
}
#################################################################

// TID
$updatedR = mysql_query("SELECT hptime FROM characters WHERE user='$userfinal'"); //hämta förra tiden från databasen
$updated = mysql_result($updatedR, 0, 'hptime');
$currentTime =time(); //tiden just nu
$difference = $currentTime - $updated;

// HP
$healthR = mysql_query("SELECT temphealth FROM characters WHERE user='$userfinal'");//hp, etc. kan du nog fixa från annat värde som du hämtat.
$health = mysql_result($healthR, 0, 'temphealth');

// HEAL
$addHealth = floor($difference / 2); // we need to know how many hours have passed - we get an round value (though it is a "float" number) by using floor()
$addHealth = (int) $addHealth * 5; // this is how much health will be added, if you add 5HP per hour - I'm not sure whether (int) is necessary, but better safe than sory

$health += $addHealth;

if ($health > $user['maxhp']) { $health = $user['maxhp']; } // we don't want the health to go over max hp!
$updated = time(); // we also need to update the alteration time.

mysql_query("UPDATE characters SET temphealth='$health' AND hptime='$updated' WHERE user='$userfinal'"); //Uppdatera HP och TIME
?>

 

Thanks for any replie

 

//Feelay

If you need a value in a database to increase every 2 seconds without any human involvement then your only way is is an automatic script that constantly runs on the server.

 

You could try setting a cookie that stores what the users hp is and what the time was and then when the user logs back in you check that cookie then update the database with the required hp depending on how long they have been logged off.

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.