Jump to content

I dont know if this is at all possible.


mike1313

Recommended Posts

I have map for our users in our online MMORPG. We have a section, where you walk around starting at 0,0  thats x,y coords each time you click a direction it updates their coord in the db, but the way the x,y are displayed everytime they move, the number is always 1 behind is there anyway to display the output as a change everytime they click? so if they are at 1,1 they go north itll still display 1,1 until they click again I want them to be able to click once and itll show 1,2 is this at any way possible?

Link to comment
https://forums.phpfreaks.com/topic/44077-i-dont-know-if-this-is-at-all-possible/
Share on other sites

This just uses a simple text file

 

x=0

y=0

 

but pos is shown immediately

 

<?php 
$dx = isset($_GET['dx']) ? $_GET['dx'] : 0;
$dy = isset($_GET['dy']) ? $_GET['dy'] : 0;

if (($coords = @parse_ini_file('pos.txt'))==false) $coords = array();
$coords['x'] += $dx;
$coords['y'] += $dy;
/**
* check limits
*/
if ($coords['x'] < 0) $coords['x'] = 0;
if ($coords['x'] > 9) $coords['x'] = 9;
if ($coords['y'] < 0) $coords['y'] = 0;
if ($coords['y'] > 9) $coords['y'] = 9;

/**
* update pos.txt
*/
$f = fopen('pos.txt', 'w');
foreach ($coords as $k=>$v) fwrite($f, "$k=$v\r\n");
fclose($f);

echo "East: {$coords['x']}    North: {$coords['y']}<br>";
?>
<a href="?dy=1">Up</a><br>
<a href="?dx=-1">Left</a>    <a href="?dx=1">Right</a><br> 
<a href="?dy=-1">Down</a><br>

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.