|
1 Oct 2003, 14:17
|
#1
|
Honorary Member
Join Date: Mar 2001
Location: Haugesund, Norway
Posts: 61
|
PHP, Ticker
Me and my friend are trying to make an online game, and I was wondering... how would I create the ticker in PHP? How can I make it run each hour... and how would I go trouh all the accounts and raise the amount of resources needed.
__________________
- Forum Legend / Fulltime Planetarion Player -
|
|
|
1 Oct 2003, 14:44
|
#2
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
You could make it run every hour by setting it up with cron with any parameters you need. That bit's easy enough.
The resource bit would, I guess, be done by querying your database to return all users then running whatever formulae you need to calculate resources on each user before UPDATEing their records and moving on.
This on your own server or a web host?
__________________
You're now playing ketchup
|
|
|
1 Oct 2003, 16:22
|
#3
|
Honorary Member
Join Date: Mar 2001
Location: Haugesund, Norway
Posts: 61
|
Well, I've been thinking about crontabs. Was the first to hit me, but is there a another way to do it? I want to be able to pause ticks etc.
I know I have to query each user.. but exactly how do I do it in PHP... Needed help with the actual code there.. if somebody got any exaples please show me.. Just need to add 250 metal to their accounts at first, I could figure out the rest.
I have my own server, yes!
__________________
- Forum Legend / Fulltime Planetarion Player -
|
|
|
1 Oct 2003, 16:31
|
#4
|
Rawr rawr
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
|
Quote:
Originally posted by chemical
Well, I've been thinking about crontabs. Was the first to hit me, but is there a another way to do it? I want to be able to pause ticks etc.
I know I have to query each user.. but exactly how do I do it in PHP... Needed help with the actual code there.. if somebody got any exaples please show me.. Just need to add 250 metal to their accounts at first, I could figure out the rest.
I have my own server, yes!
|
You can leave a browser open and do some META refreshes. As soon as you close the page your ticker stops.
OR you can do some fancy stuff that updates resources the moment someone logs in. Calculating how many ticks have passed since the last pageview and then update accordingly.
|
|
|
1 Oct 2003, 17:14
|
#5
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
I did an ASP ticker that basically calculated resources, finished research and constructions, armies returning to base if over an hour had passed since their last login with ticks happening hourly from when they signed up (so if someone signed up at 13:54 they'd always tick at 54 minutes past the hour).
You can even work that for combat too, just have code tick both the attacker and defender if it's required before letting the battle calc run.
You could still pause ticks with a crontab, just have a field in a settings table in your db along the lines of 'ticking' which can be either true or false. Then in your tick script, get field from db, see if you're ticking or not, if so then tick otherwise don't.
C'est superb.
Example code for querying each user...
Code:
$dbSession = @mysql_connect( HOST, USERNAME, PASSWORD );
if ( !$dbSession )
die( 'Couldn't connect to DB' );
if ( !@mysql_select_db( DATABASE_NAME ) ) {
mysql_close( $dbSession );
die( 'Couldn't open table: DATABASE_NAME' );
}
$dbResult = mysql_query( 'SELECT * FROM tblUsers' );
$dbFields = mysql_fetch_array( $dbResult, MYSQL_ASSOC );
while( $dbFields ) {
mysql_query( 'UPDATE tblUsers SET Money=' . ( $dbFields[ 'Money' ] + 250 ) . ' WHERE UserID=' . $dbFields[ 'UserID' ] );
$dbFields = mysql_fetch_array( $dbResult, MYSQL_ASSOC );
}
mysql_close( $dbSession );
That'd probably add 250 to each person's money, but I bet there's eight-hundred better ways to do it. Plus that wouldn't be very good for combat, you'd need more queries in there to see who is meant to be attacking who for each user.
__________________
You're now playing ketchup
|
|
|
1 Oct 2003, 17:36
|
#6
|
Honorary Member
Join Date: Mar 2001
Location: Haugesund, Norway
Posts: 61
|
Thanks Pablissimo. This is ace!
__________________
- Forum Legend / Fulltime Planetarion Player -
|
|
|
1 Oct 2003, 17:44
|
#7
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Bear in mind I'veonly been doing PHP for a few weeks so I could in fact be spouting complete bollocks.
Most of it reads ok though
__________________
You're now playing ketchup
|
|
|
1 Oct 2003, 18:14
|
#8
|
Infallible
Join Date: Feb 2001
Location: Milton Keynes, UK
Posts: 604
|
Try learning PHP on a basic level before you go into creating a game.
If you have however been programming PHP for a while then it should be fairly obvious to you what to do.....
As for the resources bit, I've edited mine slightly as it does calls to a conres table to check for addtional resources....
Code:
$query = "SELECT id, m_roids, c_roids, e_roids FROM accounts";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$m_add = 250;
$c_add = 250;
$e_add = 250;
if ($row[1] < 100)
$m_add += (350-$row[1])*$row[1];
else
$m_add += 250 * $row[1];
if ($row[2] < 100)
$c_add += (350-$row[2])*$row[2];
else
$c_add += 250 * $row[2];
if ($row[3] < 100)
$e_add += (350-$row[3])*$row[3];
else
$e_add += 250 * $row[3];
$query = "UPDATE accounts SET metal=metal+$m_add, crystal=crystal+$c_add, eonium=eonium+$e_add WHERE id=$row[0]";
mysql_query($query);
}
Basicaly adds 250 'base' resources, and then roid resources.
250 if you have over 100 of that type, 350 otherwise.
|
|
|
6 Oct 2003, 15:16
|
#9
|
Forever Delayed
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
|
Re: PHP, Ticker
There's a reason ticker-based games shouldn't be coded in server-side scripts like PHP & ASP.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"
O2 Rip-off campaign
<vampy> plus i hate people ... i despise humanity as a whole
pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
|
|
|
7 Oct 2003, 10:38
|
#10
|
Guest
|
Re: PHP, Ticker
Quote:
Originally Posted by Mong
There's a reason ticker-based games shouldn't be coded in server-side scripts like PHP & ASP.
|
What should they be coded in then?
|
|
|
7 Oct 2003, 13:04
|
#11
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: PHP, Ticker
A compiled language would be a good start.
__________________
You're now playing ketchup
|
|
|
7 Oct 2003, 16:26
|
#12
|
Infallible
Join Date: Feb 2001
Location: Milton Keynes, UK
Posts: 604
|
Re: PHP, Ticker
Quote:
Originally Posted by Mong
There's a reason ticker-based games shouldn't be coded in server-side scripts like PHP & ASP.
|
Indeed there are.
But if you dont know any compiled languages, then what other option do you have?
Besides, with Zend Accelerator, my ticker script runs fast enough so that it doesnt matter.
|
|
|
8 Oct 2003, 01:23
|
#13
|
Street Tramp
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
|
Re: PHP, Ticker
Quote:
Originally Posted by Mong
There's a reason ticker-based games shouldn't be coded in server-side scripts like PHP & ASP.
|
Any 'decent' ticker should do most of the processing within the DB server itself rather than in the code, so its not *that* crucial.
__________________
Chimney Pots.
|
|
|
9 Oct 2003, 10:34
|
#14
|
used to register
Join Date: Feb 2002
Location: Netherlands
Posts: 979
|
Re: PHP, Ticker
I asked spinner on the last real life Rucphen meet how he made the game tick, and he used cronjobs, how i don't kno anymore after that bottle of whiskey and quite a few beers (fecking cold, needed alcohol)
__________________
R1: ??:?? | R2: 51:6 | R3: 37:12 | R4: 186:13 | R5: 13:17 | R6: 1:25
R7: 15:14 | R8: 34:4 / 52:10 ¤ | R9: 16:2 | R9.5: 34:6 / 41:6 ¤
R10: 2:2 | R10.5: 15:4 | R11: 28:8 | R12: 22:9
Damn, outdated and too lazy to edit, retired now
-----
Started playing again Still too lazy to update though
|
|
|
9 Oct 2003, 13:19
|
#15
|
Friendly geek of GD :-/
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
|
Re: PHP, Ticker
I'm quite sure the actual ticker itself is coded in C++... Some time ago (~ >2 years ago) in creator's hour a creator said that (was it even spinner?).
And then there was a thread once on the forums, about "making your own pa like game", and ppl started discussing, until after some time, Spinner turned up and said: "Hey, GO AWAY PLS! If you don't like PA it's ok, but hey, pls DON'T discuss your own game on our boards" (something like that).
He also gave some "tipps" for those "game-making-n00bs", like:
- sooner or later money WILL be a problem, etc, moan, bla
- don't use that kiddy php or mysql stuff, after having passed the 100k user boundary, you will simply see your server going down. use C++., the language of choise
I'm not too sure about that, but I _do_ think that some time, dunno when, this quote: "C++ is the language of choise" (in exactly THIS spelling ^^) was said by a creator.
Ah well, maybe I've dreamt it all ^^
__________________
[ »] Entropy increases! :-/
|
|
|
27 Oct 2003, 04:02
|
#16
|
Enforcer
Join Date: Jan 2003
Location: /dev/chair
Posts: 55
|
Re: PHP, Ticker
you have more control over a compiled 'ticker'..
i've been fiddling with the idea of writing an engine in c++ which runs as a deamon and the php/asp interface to the public. everything happens in the engine. that way nothing is static!
|
|
|
28 Oct 2003, 16:27
|
#17
|
mmm.. pills
Join Date: Apr 2000
Location: Australia
Posts: 2,152
|
Re: PHP, Ticker
Quote:
Originally Posted by JetLinus
I'm quite sure the actual ticker itself is coded in C++... Some time ago (~ >2 years ago) in creator's hour a creator said that (was it even spinner?).
And then there was a thread once on the forums, about "making your own pa like game", and ppl started discussing, until after some time, Spinner turned up and said: "Hey, GO AWAY PLS! If you don't like PA it's ok, but hey, pls DON'T discuss your own game on our boards" (something like that).
He also gave some "tipps" for those "game-making-n00bs", like:
- sooner or later money WILL be a problem, etc, moan, bla
- don't use that kiddy php or mysql stuff, after having passed the 100k user boundary, you will simply see your server going down. use C++., the language of choise
I'm not too sure about that, but I _do_ think that some time, dunno when, this quote: "C++ is the language of choise" (in exactly THIS spelling ^^) was said by a creator.
Ah well, maybe I've dreamt it all ^^
|
I documented a long time ago after talking with spinner & fudge & vish how their engine worked. Every element of the game ran from compiled code done in C++ and ran off a Sybase database. This included the pages which were fast-cgi (a modification of CGI protocol that retains the program in memory instead of loading it for every instance of a page).
=[DJ Bass]=
__________________
CSS : the result of letting artists design something only an engineer should touch.
|
|
|
31 Oct 2003, 22:53
|
#18
|
Wankoverable
Join Date: Apr 2002
Location: wherever I am
Posts: 726
|
Re: PHP, Ticker
use a loop and check the time between it?
__________________
Don't worry, life is too long.
Last edited by Flayer; 1 Nov 2003 at 00:17.
|
|
|
|
All times are GMT +1. The time now is 12:46.
| |