Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-24-2010, 01:14 AM help with time
Novice Talker

Posts: 12
Trades: 0
ok here we go:
say a player has to use energy to attack, and when there energy runs out, and i want then to get 1 energy point every hour if there on line or not. how would i do this? also i want to make it stop when it gets to a point, lets say 5 points, then you have to use it or store it in a bank.

so if i learn this i can start on a banking system that will give a % of intrest to the player. and it will help with other time based things in the game.

So any input would be nice thanks for your time.
xwhitchx is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-24-2010, 03:38 AM Re: help with time
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
You could store the date/time a player ran out of energy and run a query to see if its been 5 or more hours, if so then thier energy is full.

Alternativley you could run a cronjob everyhour to check then adjust the energy accordingly.

Im not sure a banking system would have much relation to an energy system.
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-24-2010, 08:37 AM Re: help with time
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
To have some kind of automated "hourly" script..
Ie every hour add a point to every player.

You will need some kind of scheduled task on your server.

IN linux, Look at creating a crontab .

ie:
crontab -e
crontab -l ( to view )

in your crontab you can have a script that will execute every X minutes, Hours , Etc.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-24-2010, 06:39 PM Re: help with time
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I think you can get by without a scheduled cron task every hour, but just simply store the last value in the db along with a datetime stamp and process those values at each login or visit
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-26-2010, 05:00 PM Re: help with time
Novice Talker

Posts: 12
Trades: 0
ok well i looked up the Cron Jobs and im have cpanel so making one will be no problem, but im faces with a new problem. when it does get to this time, how do it make it so ALL users get 1 point, would it just be a mysql_query ('update * SET energy =$energy +1') ? or would it be somthing else?
xwhitchx is offline
Reply With Quote
View Public Profile
 
Old 06-26-2010, 05:16 PM Re: help with time
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
update table set field = field + value;
will increment 'field' in every row in the table
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-26-2010, 06:17 PM Re: help with time
Novice Talker

Posts: 12
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Code:
update table set field = field + value;
will increment 'field' in every row in the table
all right ill try that out, and let you guys know what happens
xwhitchx is offline
Reply With Quote
View Public Profile
 
Old 06-26-2010, 06:31 PM Re: help with time
Novice Talker

Posts: 12
Trades: 0
ok if i do it that way then it will only make all players energys to 1 set amount every hour, im wanting to add 1 point to the total of there energy and if they have 24 points in there energy field to not add anything.

sorry that im not getting this.


ok so i got this what i got so far, and it will update all the users to the same amount but not add 1 it just sets everyones to 3. so would i need to use WHILE() and Rows? becuz i had that same ''Resource id #2'' when i was trying to display the user name and stats.

Quote:
<?
$host="localhost";//hostname
$username="";//username
$password="";//datebase password
$db_name="";//datebase name
//function addEnergy()
//connect to database
mysql_connect("$host","$username","$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");
$test=yes;
if($test==yes)
{
$string = 'SELECT energy FROM users';
$currentEnergy = mysql_query($string);
$addedEnergy = $currentEnergy + 1;
$string2 = 'UPDATE users SET energy = \'' . $addedEnergy . '\'';
$addEnergy = mysql_query($string2);
echo $string.'$string=<br/>';
echo $currentEnergy.'$currentEnergy=<br/>';
echo $addedEnergy.'$addedEnergy=<br/>';
echo $string2.'$string2<br/>';
echo $addEnergy.'$addEnergy<br/>';

}
else
{echo'fail';}
?>

Last edited by xwhitchx; 06-26-2010 at 07:23 PM..
xwhitchx is offline
Reply With Quote
View Public Profile
 
Old 06-27-2010, 07:19 AM Re: help with time
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
And why exactly do you need that mess of code?
Code:
update users set energy = energy+ 1 where energy < 24;

USE the database server for what it is best at!!!!!!!!!!!
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-27-2010, 07:34 AM Re: help with time
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Start learning the basics of SQL
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-29-2010, 09:04 PM Re: help with time
Junior Talker

Posts: 2
Name: Hamlet
Trades: 0
Thanks!
hamster1981 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to help with time
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33222 seconds with 12 queries