How to find players at X, Y position?

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

How to find players at X, Y position?

Post by Callan S. »

Like, say a players entry in the database has an X and Y entry. How do I find all players that are at a particular X,Y position? The only method I know of is to use a while loop that ends once the database returns nothing and some sort of 'SELECT * FROM players WHERE x=whatever and y=whatever limit 1' call to the database.

Is that pretty much the best way? I'd like to show the names of other players that are standing around in a particular map location (like urban dead does)
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: How to find players at X, Y position?

Post by Chris »

What I'd recommend is you use open phpMyAdmin, select you table. And click the search tab at the top. There you'll get a list of options and ways to search through what you need. And once you have got what you want, use the query phpMyAdmin provides.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: How to find players at X, Y position?

Post by Jackolantern »

Wow, I actually never knew that! I always figured "What is the use of a search option in phpMyAdmin?", but that actually sounds very useful!
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: How to find players at X, Y position?

Post by Callan S. »

Cool tip, Chris! Thanks! But in terms of finding all the players at X,Y, basically it comes down to using a while script that keeps going until the DB call comes up a blank? Kinda like this, which I got the guts of from a highscore generator I found somewhere

Code: Select all

$playerinfo  = "SELECT name, FROM players WHERE x='$xtocheck' AND y='$ytocheck'";
$playerinfo2 = mysql_query($playerinfo);

while($playerinfo3 = mysql_fetch_array($playerinfo2))
{
etc
}
The while code is the way the best way to go through them all? Or is there a better method than that?
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: How to find players at X, Y position?

Post by Callan S. »

Oh, kind of related to this

Code: Select all

$locationwholeentry= $locationinfo3['location1'];
I'm going to have location1, location2, location3 etc in the database, representing the locations for the X dimension of a map.

In my code, is there a way to refer to location1 without typing one and using a variable there? So I have a nice elegant for loop when I'm drawing the database into RAM?

Edit: Oh wait, I figured it - just need to assemble a string with it all in it and just use that. Thanks anyway :)
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Post Reply

Return to “Coding”