Page 1 of 1

Grid Map System - Stamina Usage

Posted: Thu Nov 04, 2010 11:43 pm
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

Re: Grid Map System - Stamina Usage

Posted: Sun Nov 07, 2010 4:32 pm
by Infinity
But to make this works you need a crons or something like that?

Re: Grid Map System - Stamina Usage

Posted: Tue Nov 09, 2010 10:44 am
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.

Re: Grid Map System - Stamina Usage

Posted: Wed Nov 10, 2010 8:16 pm
by Infinity
But you need a browser opened to make this works?

Re: Grid Map System - Stamina Usage

Posted: Wed Nov 10, 2010 8:51 pm
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.

Re: Grid Map System - Stamina Usage

Posted: Wed Nov 10, 2010 11:50 pm
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)

Re: Grid Map System - Stamina Usage

Posted: Thu Nov 11, 2010 8:05 pm
by ConceptDestiny
Check to see if the player field is called 'hpoints' or 'hp', and alter appropriately. ;)

Re: Grid Map System - Stamina Usage

Posted: Thu Nov 11, 2010 8:16 pm
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 :$