User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 1 Oct 2003, 14:17   #1
chemical
Honorary Member
 
Join Date: Mar 2001
Location: Haugesund, Norway
Posts: 61
chemical is an unknown quantity at this point
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 -
chemical is offline   Reply With Quote
Unread 1 Oct 2003, 14:44   #2
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
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
pablissimo is offline   Reply With Quote
Unread 1 Oct 2003, 16:22   #3
chemical
Honorary Member
 
Join Date: Mar 2001
Location: Haugesund, Norway
Posts: 61
chemical is an unknown quantity at this point
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 -
chemical is offline   Reply With Quote
Unread 1 Oct 2003, 16:31   #4
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
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.
Structural Integrity is offline   Reply With Quote
Unread 1 Oct 2003, 17:14   #5
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
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
pablissimo is offline   Reply With Quote
Unread 1 Oct 2003, 17:36   #6
chemical
Honorary Member
 
Join Date: Mar 2001
Location: Haugesund, Norway
Posts: 61
chemical is an unknown quantity at this point
Thanks Pablissimo. This is ace!
__________________
- Forum Legend / Fulltime Planetarion Player -
chemical is offline   Reply With Quote
Unread 1 Oct 2003, 17:44   #7
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
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
pablissimo is offline   Reply With Quote
Unread 1 Oct 2003, 18:14   #8
Dave
Infallible
 
Join Date: Feb 2001
Location: Milton Keynes, UK
Posts: 604
Dave is an unknown quantity at this point
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.
Dave is offline   Reply With Quote
Unread 6 Oct 2003, 15:16   #9
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
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"
Mong is offline   Reply With Quote
Unread 7 Oct 2003, 10:38   #10
raz0r
Guest
 
Posts: n/a
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?
  Reply With Quote
Unread 7 Oct 2003, 13:04   #11
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: PHP, Ticker

A compiled language would be a good start.
__________________
You're now playing ketchup
pablissimo is offline   Reply With Quote
Unread 7 Oct 2003, 16:26   #12
Dave
Infallible
 
Join Date: Feb 2001
Location: Milton Keynes, UK
Posts: 604
Dave is an unknown quantity at this point
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.
Dave is offline   Reply With Quote
Unread 8 Oct 2003, 01:23   #13
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
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.
Raging.Retard is offline   Reply With Quote
Unread 9 Oct 2003, 10:34   #14
General Martok
used to register
 
Join Date: Feb 2002
Location: Netherlands
Posts: 979
General Martok has a spectacular aura aboutGeneral Martok has a spectacular aura about
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
General Martok is offline   Reply With Quote
Unread 9 Oct 2003, 13:19   #15
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
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! :-/
JetLinus is offline   Reply With Quote
Unread 27 Oct 2003, 04:02   #16
Rayden
Enforcer
 
Join Date: Jan 2003
Location: /dev/chair
Posts: 55
Rayden is an unknown quantity at this point
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!
Rayden is offline   Reply With Quote
Unread 28 Oct 2003, 16:27   #17
djbass
mmm.. pills
 
djbass's Avatar
 
Join Date: Apr 2000
Location: Australia
Posts: 2,152
djbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond repute
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.
djbass is offline   Reply With Quote
Unread 31 Oct 2003, 22:53   #18
Flayer
Wankoverable
 
Flayer's Avatar
 
Join Date: Apr 2002
Location: wherever I am
Posts: 726
Flayer is a glorious beacon of lightFlayer is a glorious beacon of lightFlayer is a glorious beacon of lightFlayer is a glorious beacon of lightFlayer is a glorious beacon of lightFlayer is a glorious beacon of light
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.
Flayer is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 12:46.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018