Checking every user in area...

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Checking every user in area...

Postby poppop » 17 May 2008, 18:47

Hi again,

I'm trying to work out the best way to do my game.

If i have one room with all users in. ALL users --> so hopefully 1000's one day ;)

Everytime someone moves, they send their X and Y position to the server.

Is it then feasible to loop through every single users "area" variable to see if they should recive a players location?

So:
1. Player4000 moves.
2. Sends his x/y to server --->
3. loop through all players to check area...

If(Player(X).area == Player4000's area){
Send Player4000's X/Y to Player(X)
}



Would this be an ok way to see if certain players need others locations, or should i just send the locations of every player to every other player?

Cheers.
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 17 May 2008, 21:05

You could break it down into areas.

For example, on your server extension, keep an array of all players in a area.

AreaA = ["PlayerA", "PlayerB"...]
AreaB = [...]

then if PlayerB moves. Server see which area that player comes from, then sends the update to all the players in that area. And you could run a check for areas that surround AreaA to see if any players need to be nodified about the new position of playerB.
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Postby poppop » 17 May 2008, 22:14

that seems like a really good idea BigFIsh, it's a bit late now, but i'm going to give this a look in the morning and see how i can use it.

Cheers :lol:
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Postby poppop » 18 May 2008, 16:53

Right, i've had a think, and i dont really know how this could work :(

In my "demo" / "test", there are 21 zones. -- but this is very small compared to how i see the final game.

I dont think it would work having 21 arrays like this: Array1, Array2, Array3, etc

So the only way i can think of doing it is with a multidimensional array:

Code: Select all

var zoneArray = new Array;
var subZoneInfo = new Array;

subZoneInfo = ["zoneCode", "playerID"]
zoneArray.push(subZoneInfo)


But then i would need to loop through the ZoneArray to see who is in what zone. So would this be any better then just running through every player, and checking a user variable for their zone???

I hope this makes sense. Thanks for the Help bigFish anyway! cheers :)
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 18 May 2008, 20:39

You could try this:
myZones = [{zoneCode:52, zoneUsers: users, zoneInfo:...}, {zoneCode:53, zoneUsers: users, ....... }];

Where users is an array of users object.

But then i would need to loop through the ZoneArray to see who is in what zone.


What do you mean by that? What I was thinking.. that each zone has a user array that contains all the users in that zone.

If a user leaves that zone, then the user will be deleted from the zone's user array and then automatically be added to the new user array for the new zone.

When a player moves, he sends to the server his new position along with the zone code. Sever quickly searchs for the zone code in the myZone array, and when it is found, it will take the user array from that zone object and stuff it in the _server.sendResponse{res, -1, null, users, "str"} and let the server do the work.

You might like to check www.gotoAndPlay.it 's forum. It's a better place to ask these type of questions.
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Postby poppop » 19 May 2008, 09:46

Thanks again for the help.

I think i get it now :lol:


Cheers.


-- but i still cannot get it to work. I've asked in another thread for help.

Regards,

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 43 guests