Jump to content

Sql Timers


Scex

Recommended Posts

Great thanks for the quick reply!

So what kind of code would i use?

And wouldn't this be difficult if there was many different timers for different things/different times?

 

Would i use something like this

 

$thetime=date("U");

    $timelimit=$thetime-300*1;

 

 

 

...

 

}

        if($thetime<300)

        {

          print "$thetime";

        }

        else

        {

          $updateactions="Update users set lastaction='$thetime' where ID='$userstats3[iD]'";

          mysql_query($updateactions) or die("Could not update actions");

 

 

Link to comment
https://forums.phpfreaks.com/topic/135627-sql-timers/#findComment-706613
Share on other sites

I think you should just create a table, called `production_queue` or something

 

Into  this table insert

- player ID

- production item ID

- time of production end

 

Now every time player checks his/hers army or anything, check for items in production queue, that have been already produced, and add them to players inventory (don't forget to remove them from queue)

 

BTW:

date("U") is the same as time()

Link to comment
https://forums.phpfreaks.com/topic/135627-sql-timers/#findComment-706625
Share on other sites

Im really confused :S

 

Could you possibly write the code even a snippet of it

 

ill give you the body hang on

 

this is the main buyarmy.php page

 

 

<?

include ('connect.php'); 

session_start();

?>

 

<link rel="stylesheet" href="style.css" type="text/css">

 

<?php

if (isset($_SESSION['player']))

  {

    $player=$_SESSION['player'];

    $userstats="SELECT * from km_users where playername='$player'";

    $userstats2=mysql_query($userstats) or die("Could not get user stats");

    $userstats3=mysql_fetch_array($userstats2);

    if($userstats3[dead]=='Yes')

    {

      print "You have been slain by $userstats3[killer]<br>";

      print "<form action='revive.php' method='post'>";

      print "<input type='hidden' name='ID' value='$userstats3[iD]'>";

      print "<input type='submit' name='revives' value='revive'></form>";

    }

    else

    {

      $updaterefresh="update km_users set justattacked=0 where ID='$userstats3[iD]'";

      mysql_query($updaterefresh) or die("Died");

      print "<center><table class='maintable'>";

      print "<tr class='headline'><td>"; 

      print "<center><b>Welcome warrior, $player. So you have come to rid the world of evil monsters, do not take on more than you can handle! Monsters are listed in order of increasing difficulty.</b></center>";

      print "</td></tr></table></center><br><br>";

 

print "<align='center'><table class='tableone'><tr class='headline' size='100%'><td><center>Tarenza Training Grouds</center></td></tr>";

print "<tr class='center'><td>";

print "<table class='littletable'><tr class='headline'><td><center>Buy Attack</center></td></tr>";

print "<tr class='left'><td width='25%'>";

print "Each troop Cost gold and each village can support a max of 15,000 troops:<br><br>";

     

 

print "<font color='red'>Attacking Units:</font> <br><br>";

 

 

print "<align='center'><table width='100%' class='maintable'>";

print "<tr class='left'><td>";

print "<img src='../images/warrior.jpg' height='100' width='75'></img></td><td>";

print "You have <font color='red'>$userstats3[warr]</font> Warriors, what do you wish to do?<br>";

print "Note: Warrior Attack gain is <font color='red'>50</font><br>";

print "Your Current attack power is $userstats3[ovatk]<br><br>";

print "<form action='buywarr.php?ID=$userstats3[iD]' method='post'>";

print " <input type='text' name='warr' size='6'>";

print "<input type='submit' name='submit' value='Buy Warriors'></form>";

print "<form action='sellwarr.php?ID=$userstats3[iD]' method='post'>";

print " <input type='text' name='warrs' size='6'>";

print "<input type='submit' name='submit' value='Sell Warriors'></form></td>";

print "</table></align><br>";

 

include ('stats.php');

 

 

print "<table class='maintable'>";

      print "<tr class='headline'><td><center>Attacked!!</center></td></tr>";

      print "<tr class='mainrow'><td>";

      if($userstats3[numberattck]>0)

      {

        print "<font color='red'>You have survived $userstats3[numberattck] attacks since your last login.</font><br><br>";

        $resets="update km_users set numberattck='0' where playername='$player'";

        mysql_query($resets) or die("could not query");

      }

      print "</td></tr></table><br><br>";

      $getbattlerecords="SELECT * from km_battlerecords where victimid='$userstats3[iD]'";

      $getbattlerecords2=mysql_query($getbattlerecords) or die("Could not get battlerecords");

      print "<table class='maintable'>";

      print "<tr class='headline'><td colspan='4'><center>Battle records since last login</center></td></tr>";

      print "<tr class='mainrow'><td>Attacker ID</td><td>Attacker name</td><td>Result</td><td>Land lost</td></tr>";

      while($getbattlerecords3=mysql_fetch_array($getbattlerecords2))

      {

        print "<tr class='mainrow'><td>$getbattlerecords3[attid]</td><td>$getbattlerecords3[attname]</td><td>$getbattlerecords3[result]</td><td>$getbattlerecords3[landlost]</td></tr>";

      }

      print "</table><br><br>";

      $delrecords="Delete from km_battlerecords where victimid='$userstats3[iD]'";

      mysql_query($delrecords) or die("Could not delete battle records");

      print "Sean";

    }

  }

else

  {

    print "Sorry, not logged in  please <A href='login.php'>Login</a><br>";

 

  }

 

?>

 

 

This is the buywarr.php

 

<?php

 

include 'connect.php';

session_start();

?>

<center>

 

<iframe marginwidth="0" marginheight="0" width="468" height="60" scrolling="no" frameborder="0" src="http://rcm.amazon.com/e/cm?t=arcadeportal&p=13&o=1&l=bn1&browse=1000&mode=books&f=ifr">

 

 

<MAP NAME="boxmap-p13"><AREA SHAPE="RECT" COORDS="379, 50, 460, 57" HREF="http://rcm.amazon.com/e/cm/privacy-policy.html?o=1" ><AREA COORDS="0,0,10000,10000" HREF="http://www.amazon.com/exec/obidos/redirect-home/arcadeportal" ></MAP><img src="http://rcm-images.amazon.com/images/G/01/rcm/468x60.gif" width="468" height="60" border="0" usemap="#boxmap-p13" alt="Shop at Amazon.com">

 

 

</iframe>

 

</center><br><br>

<link rel="stylesheet" href="style.css" type="text/css">

<?php

if (isset($_SESSION['player']))

  {

    $player=$_SESSION['player'];

    $userstats="SELECT * from km_users where playername='$player'";

    $userstats2=mysql_query($userstats) or die("Could not get user stats");

    $userstats3=mysql_fetch_array($userstats2);

    if(isset($_POST['submit']))

    {

        $warr=$_POST['warr'];                 

        $warr=strip_tags($warr);

        $warrcost=2000;

$warrt=$warr*50;

$totalcost=$warr*$warrcost;

        $limit=$max;

$max=15000;

        $threshold=date("U")-60*1;   

        $thetime=date("U"); 

        print "<center>";

        print "<table class='maintable'>";

        print "<tr class='headline'><td><center>Tarenza Warrior Grounds</center></td></tr>";

        print "<tr class='mainrow'><td>";

        if($warr<0)

        {

          die("You cannot buy negative units");

        }

       

        else if($totalcost>$userstats3[gold])

        {

          die("You do not have that much gold, go back to <A href='index.php'>Main page</a>");

        }

        else if($warr+$userstats3[arc]+$userstats3[war]+$userstats3[pal]+$userstats3[warr]+$userstats3[bes]+$userstats3[cha]+$userstats3[ram]>$max)

        {

          die("You cannot have more than $max units per village, go back to <A href='index.php'>Main</a>");

        }

        else if($userstats3[lastaction]>$threshold)

        {

          die("You have to wait 1 minute after an attack to buy troops, go back to <A href='index.php'>Main</a>.");

        }

        else if($warr<=15000)

        {

          $getarmy="update km_users set gold=gold-'$totalcost', ovatk=ovatk+'$warrt', warr=warr+'$warr' where ID='$userstats3[iD]'";

          mysql_query($getarmy) or die("Can't get Warriors");

          print "$warr Warriors purchased. Go back to <A href='buyarmy.php'>Recruitment</a>.";

        }

        print "</td></tr></table>";

 

 

 

    }

  }

else

  {

    print "Sorry, not logged in  please <A href='login.php'>Login</a><br>";

 

  }

 

?>

 

 

My users table

 

users (

  ID bigint(21) NOT NULL auto_increment,

  playername varchar(15) NOT NULL default '',

  password varchar(255) NOT NULL default '',

  email varchar(255) NOT NULL default '',

  ovpoints bigint(21) NOT NULL default '0',

  attacked bigint(20) NOT NULL default '0',

  attackers int(10) NOT NULL default '0',

  fort int(10) NOT NULL default '0',

  bg int(10) NOT NULL default '0',

  townhall int(10) NOT NULL default '0',

  smithy int(10) NOT NULL default '0',

  stable int(10) NOT NULL default '0',

  arena int(10) NOT NULL default '0',

  tmill int(10) NOT NULL default '0',

  imill int(10) NOT NULL default '0',

  cmill int(10) NOT NULL default '0',

  timber int(10) NOT NULL default '0',

  iron int(10) NOT NULL default '0',

  coal int(10) NOT NULL default '0',

  warr bigint(20) NOT NULL default '0',

  ram bigint(20) NOT NULL default '0',

  scar bigint(20) NOT NULL default '0',

  bes bigint(20) NOT NULL default '0',

  cha bigint(20) NOT NULL default '0',

  scout bigint(20) NOT NULL default '0',

  trojan bigint(20) NOT NULL default '0',

  virus bigint(20) NOT NULL default '0',

  arc bigint(20) NOT NULL default '0',

  warl bigint(20) NOT NULL default '0',

  guar bigint(20) NOT NULL default '0',

  validated int(11) NOT NULL default '0',

  validkey varchar(255) NOT NULL default '',

  PRIMARY KEY  (ID)

Link to comment
https://forums.phpfreaks.com/topic/135627-sql-timers/#findComment-706664
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.