Advertisement

Handle Online Players.

Started by May 17, 2005 07:22 PM
4 comments, last by X5-Programmer 19 years, 9 months ago
Hi there, I have some few questions about handle the players for an ( rpg game that I have been working on ). The problem I have here is to get the camera follow the exakt player. This is how my idea looks like how I handle the players. The server got an (online players) vector of the players data structure to hold all the current online players on the map. vector<WPlayerData> sOnlinePlayers; Now to the client part. Client got the same structure as server using an vector to hold the players. vector<WPlayerData> cOnlinePlayers; 1. When a new player connect he recv an Unique ID and all the players he got in the databas, and from there chose wich one he wants to play with and press "Enter World". 2. The client sends an packet to the server to recv the sOnlinePlayers vector, to get all the current online players on the map. 3. The client send an packet to server to add him into the sOnlinePlayer vector. and also send out to all the clients connected "new player enter world. Add me to the client cOnlinePlayers vector". 4. Render/Update the players in cOnlinePlayers vector. The problem I have is that I can't get the camera to follow the right character and it looks like this.

Vector3 camPos; //camPos
camPos = cOnlinePlayers[ my_unique_id ].m_Position; //playerPos

m_Camera.SetCamera( camPos ); //Setcamera

But this suxs. if an player leave the game he gets removed from the cOnlinePlayer vector, And then my character does not have the same ID pos in the cOnlinePlayers vector as before right?. So how can I fix this?. My idea was to do something like this.

int pID;

for( itr = cOnlinePlayers.begin(); itr != cOnlinePlayers.end(); itr++ )
{
    if( itr->GetID() == my_unique_id ) { pID = itr->GetID(); }
}

and from there use the pID as the position id in the vector. camPos = cOnlinePlayers[ pID ].m_Position; //playerPos m_Camera.SetCamera( camPos ); //SetCamera ------------- Well I hope anyone can indicate what I have been writing here because I am not good at explain and my english is not the best to.. Anyway, I hope you guys can point me somewere.
-[ thx ]-
PS: If you know some oheter ways to do this, give some examples on how you
should do it in an ( server,clinet ) game structure.
-[ thx ]-
Advertisement
Did you try your idea? Did it work?

I would use a std::map<> from player ID to player.
enum Bool { True, False, FileNotFound };
I have the camera working now.. But is this an good way to handle the players?
and what is the difference between the vector and map?

I mean, what can you do that you can't using an vector?.

How do you setup your handeling for player?.

thanks.
-[ thx ]-
Too many spelling errors...... Head hurts..... Must stop reading!!! [headshake]
k, thanks for that.

really nice help from you there.

[Edited by - X5-Programmer on May 20, 2005 11:41:29 AM]
-[ thx ]-

This topic is closed to new replies.

Advertisement