Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005
    Posts
    51

    A debate, save us!

    This is based on a small game server.

    Okay, let's assume there are 8 players online. ID 0, ID 1, ID 2, ID 3, ID 4, ID 6, ID 9 and ID 14.

    PHP Code:
    new gPlayersOnline
    PHP Code:
    stock GetPIndex()//<--Player Index
    {
        
    gPlayersOnline 0;//Reset to 0!
        
    for(new i=0;i<GetMaxPlayers();i++)
        {
            if(!
    IsPlayerConnected(i)) continue;
            
    gPlayersOnline++;
        }

    So gPlayersOnline is now set to 8, great! But we don't actually know the player ID's for these people.

    PHP Code:
    for(new i=0;i<gPlayersOnline;i++)
    {
       
    SendClientMessage(i0xFFFFFF00"Hello online player!");
    }

    AKA

    SendClientMessage
    (00xFFFFFF00"Hello online player!");
    SendClientMessage(10xFFFFFF00"Hello online player!");
    SendClientMessage(20xFFFFFF00"Hello online player!");
    SendClientMessage(30xFFFFFF00"Hello online player!");
    SendClientMessage(40xFFFFFF00"Hello online player!");
    SendClientMessage(50xFFFFFF00"Hello online player!");
    SendClientMessage(60xFFFFFF00"Hello online player!");
    SendClientMessage(70xFFFFFF00"Hello online player!"); 
    So this would send to ID 0, 1, 2, 3, 4, 5, 6 and 7 as it is set to 8, but what about player ID's 9 and 14 I specified earlier?

    The basic question is, without storing their playerID and utilising it, would it send the message to list A:
    0
    1
    2
    3
    4
    5
    6
    7

    or list B like I want it to:
    0
    1
    2
    3
    4
    6
    9
    14


    This is a general coding issue, not directly related to the game. Thanks!

  2. #2
    Join Date
    Apr 2009
    Location
    Pittsburgh, Pennsylvania
    Posts
    583
    I'm not 100% sure how you're coding it... but this is extremely simple if its done properly using UDP.

    info.port
    info.address

    info.port would be the clients port (can be used to "manage" a client uniquely along with their ip address), info.address would be the clients ip address.

    game servers SHOULD be done in UDP as the latency is MUCH lower than than TCP. But if its managed properly, and you have a decent "grasp" you should be fine.

    I suggest doing a little research on how to manage clients using udp and tcp (which ever you plan on using, but i highly suggest udp because of low latency)

    I've personally been coding a game on the side using node.js UDP. Nothing "major" but it does work.


    To answer your question:

    Code:
    0
    1
    2
    3
    4
    5
    6
    7
    As it is just going down the number of clients.

  3. #3
    One solution would just be to iterate through all possible slots again. If you do not want to store the IDs & also are thinking of applying the concept to a wider range of applications.

    Code:
    for(new i=0;i<GetMaxPlayers();i++)
        {
            if(!IsPlayerConnected(i)) continue;
            SendClientMessage(i, 0xFFFFFF00, "Hello online player!");
        }

Similar Threads

  1. Hot Summer Specials at Sago Networks SAVE SAVE SAVE
    By Sago-Sean in forum Dedicated Hosting Offers
    Replies: 0
    Last Post: 06-08-2010, 09:55 AM
  2. Replies: 0
    Last Post: 11-11-2009, 08:52 AM
  3. Replies: 12
    Last Post: 09-16-2009, 02:16 AM
  4. Debate Poll 4500 Unique Per debate
    By Lightsky in forum Advertising Offers
    Replies: 0
    Last Post: 06-12-2007, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •