Help Me With My Online Game [SOLVED]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
amir
Posts: 6
Joined: Wed Mar 21, 2012 8:46 am

Help Me With My Online Game [SOLVED]

Post by amir »

Hi,
I'm Making a online game i'm Done With Everything Except Times.
What I mean is (Example):
Like Player Send a Car to deliver something And When Car Is back player Get Money And experience . i want to Make A time for car so when Player Send a Car, 20 minutes After, player get money and experience not at the moment


My Online Game Is A Text-Based
Any Idea?

Thanks
Last edited by amir on Thu Apr 05, 2012 3:01 pm, edited 1 time in total.
(: (Please excuse my bad English) :)
User avatar
Foofighter
Posts: 121
Joined: Sun Mar 04, 2012 1:52 pm

Re: Help Me With My Online Game

Post by Foofighter »

Hi,
there are 2 simple ways , with Javascript or without.

without Javascript you can basically save (timestamp + drivetimecar) in your DB when the car starts, then check the following timestamp - time() == 0 .

br
Foo
amir
Posts: 6
Joined: Wed Mar 21, 2012 8:46 am

Re: Help Me With My Online Game

Post by amir »

Foofighter wrote:Hi,
there are 2 simple ways , with Javascript or without.

without Javascript you can basically save (timestamp + drivetimecar) in your DB when the car starts, then check the following timestamp - time() == 0 .

br
Foo
hi
Thanks For Replying but can you give me more details please
(: (Please excuse my bad English) :)
User avatar
Foofighter
Posts: 121
Joined: Sun Mar 04, 2012 1:52 pm

Re: Help Me With My Online Game

Post by Foofighter »

Code: Select all

<?php
$stats_get = mysql_query("SELECT * FROM `xyz` WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$stats = mysql_fetch_assoc($stats_get);

$zeit = time();

if (isset($_POST['drive']))
    {    
    $zeit=time() + 1200;
        mysql_query("UPDATE xyz SET car_time = $zeit WHERE id ='".$_SESSION['uid']."'");
    }
//----------------------------------------------------------------------------------------------------------
if($stats[''car_time']>0)
{
$rest = $stats['car_time'] - time();
if($rest == 0) 
{
mysql_query("UPDATE xyz SET EXP = EXP + x , money = money + y, car_time = 0, WHERE id ='".$_SESSION['uid']."'");
}
}
?>
//---------------------------------------------------------------------------------------------------------
Car: <?php echo $stats['car']; ?><br>
<?php  if ($stats['car_time'] > 0)
{
     ?> estimated arrival of car: <?php $rest= $stats['car_time] - time(); if ($rest <0){$rest = 0;} echo"$rest"?> <?php  
}                                                                 
else     
        { ?> 
                 <form action="#" method="post">
                    <input type="submit" value="Send car" name="drive" >
                </form>
<?php   } ?>
Thats how i do it i just adapted it for your example, but thats for sure not the best way cause iam pretty much a beginner at this..
the 1200 is the value in seconds for your 20min.

br
Foo
amir
Posts: 6
Joined: Wed Mar 21, 2012 8:46 am

Re: Help Me With My Online Game

Post by amir »

Foofighter wrote:

Code: Select all

<?php
$stats_get = mysql_query("SELECT * FROM `xyz` WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$stats = mysql_fetch_assoc($stats_get);

$zeit = time();

if (isset($_POST['drive']))
    {    
    $zeit=time() + 1200;
        mysql_query("UPDATE xyz SET car_time = $zeit WHERE id ='".$_SESSION['uid']."'");
    }
//----------------------------------------------------------------------------------------------------------
if($stats[''car_time']>0)
{
$rest = $stats['car_time'] - time();
if($rest == 0) 
{
mysql_query("UPDATE xyz SET EXP = EXP + x , money = money + y, car_time = 0, WHERE id ='".$_SESSION['uid']."'");
}
}
?>
//---------------------------------------------------------------------------------------------------------
Car: <?php echo $stats['car']; ?><br>
<?php  if ($stats['car_time'] > 0)
{
     ?> estimated arrival of car: <?php $rest= $stats['car_time] - time(); if ($rest <0){$rest = 0;} echo"$rest"?> <?php  
}                                                                 
else     
        { ?> 
                 <form action="#" method="post">
                    <input type="submit" value="Send car" name="drive" >
                </form>
<?php   } ?>
Thats how i do it i just adapted it for your example, but thats for sure not the best way cause iam pretty much a beginner at this..
the 1200 is the value in seconds for your 20min.

br
Foo
Hi

Wow Amazing I don't know how to say thanks , it's really amazing
thanks
(: (Please excuse my bad English) :)
Post Reply

Return to “Beginner Help and Support”