Page 1 of 1

Help Me With My Online Game [SOLVED]

Posted: Tue Apr 03, 2012 9:24 am
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

Re: Help Me With My Online Game

Posted: Tue Apr 03, 2012 1:17 pm
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

Re: Help Me With My Online Game

Posted: Tue Apr 03, 2012 3:31 pm
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

Re: Help Me With My Online Game

Posted: Tue Apr 03, 2012 5:20 pm
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

Re: Help Me With My Online Game

Posted: Thu Apr 05, 2012 2:59 pm
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