[Help]Check map of chars

12/05/2010 10:32 ryuchetval#1
Hello....I would need some help in finding if there's any character on a map id like: (this is for LOTF 5165)
Code:
bool CharOnMap(MapId)
{
Character C;
C = Game.World.H_Chars[MapId]
if (C!=null)
return true;
else return false;
}
But I don't think this works so I want to know how I find out if the map contains at least 1 character...
Thanks :)
12/05/2010 12:08 _DreadNought_#2
I'd do this.

Code:
public static bool CharsOnMap(int MapID)
{
foreach(GameClient Client in ConnectedClients.Values)
if (Client.Entity.MapID == MapID) { return true; } }
return false;
}
I didnt really understand what you wanted to do.

so just do if (CharsOnMap(MAPID)) or whatever and it'l work.

This just sees if there are ANY characters on the map specified.
12/05/2010 12:30 ryuchetval#3
oh great thanks :)
12/05/2010 13:22 Basser#4
Quote:
Originally Posted by _DreadNought_ View Post
I'd do this.

Code:
public static bool CharsOnMap(int MapID)
{
foreach(GameClient Client in ConnectedClients.Values)
if (Client.Entity.MapID == MapID) { return true; } }
return false;
}
I didnt really understand what you wanted to do.

so just do if (CharsOnMap(MAPID)) or whatever and it'l work.

This just sees if there are ANY characters on the map specified.
I'll teach you Linq sometime. =)
12/05/2010 16:45 .Ocularis#5
Oh how I love not even looking at loft anymore.
12/05/2010 19:05 ryuchetval#6
yeah that's a good decision...
12/08/2010 00:50 Korvacs#7
Code:
        public bool MapIsEmpty(int MapID)
        {
            GameClient Target = ConnectedClients.Values.Find((GameClient Client) => { return Client.Entity.MapID == MapID; });

            if (Target == null)
                return true;

            return false;
        }
Something like this would be best.
12/08/2010 07:39 ChingChong23#8
or depending how your server is structured

public boolean playersOnMap(int mapID) {
return World.getMap(mapID).size() > 0;
}
12/08/2010 12:19 Syst3m_W1z4rd#9
Code:
public bool AnyPlayersInMap(ushort MapID)//Since mapids are ushort
{
    int i = 0;
    foreach (Game.Character C in World.H_Chars.Values) {
        if (C.Loc.Map == MapID)
            i++; }

    if (i > 0)
        return true;

    return false;
}
Code:
public int PlayersInMap(ushort MapID)//Since mapids are ushort
{
    int i = 0;
    foreach (Game.Character C in World.H_Chars.Values) {
        if (C.Loc.Map == MapID)
            i++; }

    return i;
}
12/08/2010 14:14 _Emme_#10
Quote:
Originally Posted by 1337 H4X0R View Post
Code:
public bool AnyPlayersInMap(ushort MapID)//Since mapids are ushort
{
    int i = 0;
    foreach (Game.Character C in World.H_Chars.Values) {
        if (C.Loc.Map == MapID)
            i++; }

    if (i > 0)
        return true;

    return false;
}
I'm not saying your method is good or not, but if you're doing it that way simply do:

Code:
public bool MapHasPlayers(ushort Map)
{
foreach(GameClient client in Kernel.GameClients)
 if(client.Entity.MapID == Map)
  return true;

return false
}
Might just stick in that I recommend a public dictonary for all spawned objects on the server, with that you could simply call something like this:

Quote:
public bool MapHasPlayers(Maps map)
{
return (Kernel.Objects[map].Lenght > 0);
}
12/08/2010 16:30 ChingChong23#11