Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6624179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:17+00:00 2026-05-25T21:37:17+00:00

I have a problem with my file. I’m making Travian Clone script and we

  • 0

I have a problem with my file. I’m making Travian Clone script and we went really far. Now we decided to add artefacts into game.

Goal is to show closest artefacts to the current village we are in. The code is:

function getDistance($coorx1, $coory1, $coorx2, $coory2) {
          $max = 2 * WORLD_MAX + 1;
          $x1 = intval($coorx1);
          $y1 = intval($coory1);
          $x2 = intval($coorx2);
          $y2 = intval($coory2);
          $distanceX = min(abs($x2 - $x1), $max - abs($x2 - $x1));
          $distanceY = min(abs($y2 - $y1), $max - abs($y2 - $y1));
          $dist = sqrt(pow($distanceX, 2) + pow($distanceY, 2));

          return round($dist, 1);
      }


        unset($reqlvl);
        unset($effect);
        $arts = mysql_query("SELECT * FROM ".TB_PREFIX."artefacts WHERE id > 0");
        $rows = array();
        while($row = mysql_fetch_array($arts)) {
            $query = mysql_query('SELECT * FROM `' . TB_PREFIX . 'wdata` WHERE `id` = ' . $row['vref']);
            $coor2 = mysql_fetch_assoc($query);

            $wref = $village->wid;
            $coor = $database->getCoor($wref);
            $dist = getDistance($coor['x'], $coor['y'], $coor2['x'], $coor2['y']);

            $rows[$dist] = $row;

        }
        ksort($rows, SORT_ASC);
        foreach($rows as $row) {
            echo '<tr>';
            echo '<td class="icon"><img class="artefact_icon_'.$row['type'].'" src="img/x.gif" alt="" title=""></td>';
            echo '<td class="nam">';
            echo '<a href="build.php?id='.$id.'">'.$row['name'].'</a> <span class="bon">'.$row['effect'].'</span>';
            echo '<div class="info">';
            if($row['size'] == 1){
                   $reqlvl = 10;
                   $effect = "village";
               }elseif($row['size'] == 2 OR $row['size'] == 3){
                   $reqlvl = 20;
                   $effect = "account";
               }
            echo '<div class="info">Treasury <b>'.$reqlvl.'</b>, Effect <b>'.$effect.'</b>';
            echo '</div></td><td class="pla"><a href="karte.php?d='.$row['vref'].'&c='.$generator->getMapCheck($row['vref']).'">'.$database->getUserField($row['owner'],"username",0).'</a></td>';
            echo '<td class="dist">'.getDistance($coor['x'], $coor['y'], $coor2['x'], $coor2['y']).'</td>';
            echo '</tr>';
        }
?>

but the code seems to be wrong because its showing all same distances. 14.8 to me. I know i maybe have bad explanation but u will probably understand what I need.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:37:17+00:00Added an answer on May 25, 2026 at 9:37 pm

    I can’t help with your current code I’m afraid but you could try using the Haversine Formula instead:

    // Where: 
    // $l1 ==> latitude1 
    // $o1 ==> longitude1 
    // $l2 ==> latitude2 
    // $o2 ==> longitude2 
    function haversine ($l1, $o1, $l2, $o2) { 
      $l1 = deg2rad ($l1); 
      $sinl1 = sin ($l1); 
      $l2 = deg2rad ($l2); 
      $o1 = deg2rad ($o1); 
      $o2 = deg2rad ($o2); 
    
      $distance = (7926 - 26 * $sinl1) * asin (min (1, 0.707106781186548 * sqrt ((1 - (sin ($l2) * $sinl1) - cos ($l1) * cos ($l2) * cos ($o2 - $o1))))); 
    
      return round($distance, 2);
    }  
    

    Credit goes to this post on go4expert.com, I’ve used this function in the past and found it works very well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem a problem in making a php file run because of the
Now I create a small PHP Application, here I have problem for using file
i have problem on my php file upload script , i am trying to
I have problem with copying sdf file to WM emulator. My solution structure MyApp.DataLayer
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have a problem downloading particular file types by WebClient. So there are no
I have problem with session in cakephp.I have one file chat.php that is in
I have a problem with a simple included file. The file being included is
I have a problem reading a txt file to insert in the mysql db
I have some problem with my .htaccess file. Here I am adding my problem.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.