Grid Map System - Stamina Usage

Post all your tuts or request for tuts here.
Post Reply
ConceptDestiny
Posts: 261
Joined: Wed Apr 28, 2010 8:35 am

Grid Map System - Stamina Usage

Post by ConceptDestiny »

Thought I'd post up what I coded so far in regard to the stamina system for use with the map grid. Just do a search & insert.

Edited the following to include the $_GET stamina.

Code: Select all

				<?php
				$stamina=$_GET['stamina'];
				if ($playerinfo3['mapr']!=$row||$playerinfo3['mapc']!=$column)
				{
				$updatenewloc="Update players set mapr=$row,mapc=$column,stamina=$stamina where name='$player'";
						mysql_query($updatenewloc) or die("Could not update new location");

				$playerinfo3['mapr'] = $row;
				$playerinfo3['mapc'] = $column;
				$pllevel = $playerinfo3['level'];
				$playerinfo3['stamina'] = $stamina;	
				}
				?>
Then applied the relevant code changes to the map, so once the player's stamina reaches 0, then you are unable to move.

Code: Select all

<div id="grid1"><a href="<?php if ($playerinfo3['stamina'] == '0'){ /* DO NOTHING */ } elseif ($nwestinfo3['tile'] == "boundry"){echo "map.php";}else {echo "../locations/map.php?row=$rowminus1&column=$columnminus1&stamina=$staminaminus1";}  ?>"><img src="../images/<?php echo $nwestinfo3['tile']; ?>.png"width="130" height="130" border="0" title="Travel North-West"/></a></div></td>
You could add the following beside your stamina bar indicator to warn the player.

Code: Select all

<?php if ($playerinfo3['stamina'] == '0') {echo "<font style='text-decoration:blink'>!!</font>";} ?>
Now I just need to prevent the player from fast-traveling, then it will be sorted. ;) If anybody else has any further suggestions, feel free to add your input! :D
User avatar
Infinity
Posts: 45
Joined: Sun Oct 31, 2010 12:27 pm

Re: Grid Map System - Stamina Usage

Post by Infinity »

But to make this works you need a crons or something like that?
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Grid Map System - Stamina Usage

Post by Chris »

Here's a good alternative to crons:

Code: Select all

<?php

// loop forever and ever and ever and ever and ever and ever and ever and ever and ever and ever.. You get the point. It's 0.. but also infinity
while( true )
{
    // stuff to do
    // for example a simple database update
    mysql_query("UPDATE `table` SET `loop` = `loop`+1");

    // stop the server from timing out by making it let the script run for an extra 61 seconds (i give in an extra second just in case)
    set_time_limit(61);

    // sleep, stops the server from going mental. Just imagine you went on for forever without sleep :D
    // lucky for us computers don't need to sleep too much
    sleep(60); // 1 minute (60 seconds)
}
 
Now just run that script from the server. And it will update stuff every minute.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Infinity
Posts: 45
Joined: Sun Oct 31, 2010 12:27 pm

Re: Grid Map System - Stamina Usage

Post by Infinity »

But you need a browser opened to make this works?
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Grid Map System - Stamina Usage

Post by Jackolantern »

Infinity wrote:But you need a browser opened to make this works?
No, because you have to remember that PHP is a server-side scripting language. Once a script starts, it doesn't care if a browser is receiving output. For example, a web server set up with cron jobs runs PHP scripts on its own, with no user-initiated action, and they don't have to display any output. They just make changes on the server and they are done.
The indelible lord of tl;dr
User avatar
Infinity
Posts: 45
Joined: Sun Oct 31, 2010 12:27 pm

Re: Grid Map System - Stamina Usage

Post by Infinity »

Uhmm It makes sense. But uhmm, something it's going wrong with me code, I have tested it and aparently it only makes one loop.
I have added a counter that refreshes a value of a table of MySQL to see what happens, and looks like so, it only increments it one time.
I have noticed too that if I leave it on my browser time latter it's shown this message:
Could not update hp
Here is my code:

Code: Select all

<?php
  include_once 'connect.php';
?>
<?php

// loop forever and ever and ever and ever and ever and ever and ever and ever and ever and ever.. You get the point. It's 0.. but also infinity
while( true )
{
    // stuff to do
    // for example a simple database update
  $updateplayer="update players set hpoints=hpoints+'1'";
  mysql_query($updateplayer) or die("Could not update hp");

  $updateserver="update server set loops=loops+'1'";
  mysql_query($updateserver) or die("Could not loop");


    // stop the server from timing out by making it let the script run for an extra 61 seconds (i give in an extra second just in case)
    set_time_limit(61);

    // sleep, stops the server from going mental. Just imagine you went on for forever without sleep :D
    // lucky for us computers don't need to sleep too much
    sleep(60); // 1 minute (60 seconds)
}

Why only works one time? Can be a problem of the host I'm working with? (a free one x_X)
ConceptDestiny
Posts: 261
Joined: Wed Apr 28, 2010 8:35 am

Re: Grid Map System - Stamina Usage

Post by ConceptDestiny »

Check to see if the player field is called 'hpoints' or 'hp', and alter appropriately. ;)
User avatar
Infinity
Posts: 45
Joined: Sun Oct 31, 2010 12:27 pm

Re: Grid Map System - Stamina Usage

Post by Infinity »

Yes, the name it's ok, it's very strange because it make the actions properly one time, I mean it updates the db one time, but at the second one it crashes :/

That's why I don't know what it's happening here :$
Post Reply

Return to “Tutorials”