player creation

Posted By: sheefo

player creation - 09/17/06 17:14

I am getting fed up with myself for asking so many questions. I need some help with making my RTS game support multiple players.

I need some advice on how to create in singleplayer, you as the "player" pointer and in multiplayer, every client has its own player and when the "player" pointer is used it only means that client. Basically, one client is not aware of another clients "player" existance.
The player is an invisible entity (used as the centre of orbit for the camera) and it has skills to hold attributes. Like "player.money" and so on.

Thanks for your time reading, but any idea?
Posted By: sheefo

Re: player creation - 09/19/06 12:48

PLEEEASE!!!
Posted By: Michael_Schwarz

Re: player creation - 09/19/06 14:14

i dont understand your request, could you say it a bit clearer so i can help you on this?
Posted By: sheefo

Re: player creation - 09/19/06 16:00

I want to create a player on each client, and it does not interfear with any other client. It's for my RTS, so I need in singleplayer, you to be the player but in multiplayer each client is a player.

BTW, by player I mean the "player" pointer.
Posted By: Michael_Schwarz

Re: player creation - 09/19/06 16:37

you would have to ent_create a "shell" for your player, by ent_create the entity is created on all clients. then you can set a pointer to it, like player2. On client side, you do ent_createlocal and update the position of your local cretaed player to the server wide created player->

vec_set(player2.x,player.x);
send_skill(player2.x,send_vec);
Posted By: sheefo

Re: player creation - 09/19/06 16:42

Can I create all players and handle them to an global array? So I can use 'ptr_for_handle' to retreave their data? How can I make an array be the same on all clients and the server?
Posted By: Michael_Schwarz

Re: player creation - 09/19/06 21:26

you could, yes. The problem is that handles or pointers are (afaik) different on each PC, depending of the order an entity was created during the level loading and the action got assigned.

You can give each entity an ID in a skill, for example skill100, just make sure the skill100 is updated to the server when you create your entity

send_skill(my.skill100,null);

then you can cycle trhough all entities via ent_next(which is really fast) and set the you pointer, then you can retrieve all data you want, or even in the same instance

if(your.id==2)
{
target_hp=your.hp;
target_shield=your.shield;
}
etc...
Posted By: sheefo

Re: player creation - 09/19/06 21:35

So I store the ID of the player in a skill and in the 'ent_next' loop I check each one for that ID then break the loop? No handles what so ever?

Do I have to put "send_skill(my.skill100, null)" in a loop? Or shall I send it when I create the new player?

EDIT: BTW, Thanks for having patients with me, and helping me
Posted By: Michael_Schwarz

Re: player creation - 09/19/06 21:42

you have to do the send_skill only when you create your player and/or change his ID, keep in mind, you have to send that as the player who controls the character and not as the one who searches.
Posted By: sheefo

Re: player creation - 09/20/06 10:53

Thanks a lot, but how I can display the players points on a score board when a player presses TAB. It shall only display locally, like on Age of Empires when you click the button and all players scores are displayed in the corner.

Also, how can my units be formatted? After I initialize every skill do I have to send_skill it? These question are really, how and when do I use send_skill and send_var?
Posted By: Michael_Schwarz

Re: player creation - 09/20/06 14:10

Quote:

Thanks a lot, but how I can display the players points on a score board when a player presses TAB. It shall only display locally, like on Age of Empires when you click the button and all players scores are displayed in the corner.

Also, how can my units be formatted? After I initialize every skill do I have to send_skill it? These question are really, how and when do I use send_skill and send_var?




you could store the score on the server and/or let it even calculate there:

Code:
 define skill99,done_something_great;
define skill98,score;

function completed_objective
{
my.done_something_great=1;
send_skill(my.done_something_great,0);
}

function calculate_score
{
while(1)
{
if(my.done_something_great)
{
my.score+=1; // Add score
my.done_something_great=0; // reset bool
send_skill(my.score,send_vec+send_all); // save bandwith by sending skill 98,99 and 100. and send to ALL clients
wait(1); //wait one frame to not add another score as the data needs time to be transferred.
}
wait(1);
}
}

action server_shell
{
//etc...

calculate_score();
}



to you question about when to send:

when you have changed a value you have to send it immediatley after you changed it like:

you.hp-=1;
send_skill(you.hp,0); // use send_all instead of 0 when executed on server

or when you change a var:

var bGodMode;
//...
bGodMode=1;
send_var(bGodMode);

its all that simple.

About skills you can remember that you should try to send the less as possible. send_vec sends a vector(e.g. the two consecutive skills->
send_skill(my.skill1,send_vec); sends my.skill1, 2 and 3)
so place the order of your skills wiseley the way you can send 3 important skills in one flush.

for vars there is to remember that its better to send a array than sending individual vars.
Every var you initialze(var somename;) has 3 (!) values, use them!

REMEMBER:
var somename; = var somename[3];

every time you send a var not using that 2 left parameters, you are wasting two bytes(2 zeros) of data!
Posted By: fastlane69

Re: player creation -handles and pointers - 09/20/06 16:41

Quick correction; maybe it's relevant, maybe not:

Pointers are unique to the local computer... after all they refer to a local memory address. Pointers are what the 3DGS engines uses to manipulate entities.

Handles however are global to the network... they refer to a global ID that the 3DGS server assigns to all global entities. Handles are never used to manipulate entities.

Thus if you want unique identification across a network without skills:

1) you would get the pointer to the global entity you want,
2) use the handle() command to get it's handle; you now have a unique, global identifier for that entity.
3) You can send this handle over the network as a var to another client or the server (using a skill or a network var),
4) and use a ptr_for_handle() to resolve that global handle to a local point; now you have the pointer to the SAME ENTITY but on a different computer.

In this case the following snippet:
Code:
if(your.id==2)
{
target_hp=your.hp;
target_shield=your.shield;
}
etc...



Gets replaced with something like this:
Code:

player=ptr_for_handle(sent_handle);
target_hp=player.hp;
target_shield=player.shield;
etc...


Posted By: sheefo

Re: player creation - 09/20/06 16:58

Quote:


send_skill(you.hp,0); // use send_all instead of 0 when executed on server




So everytime I send a var I have to do this?
Code:

ifdef server;
send_skill(you.hp, SEND_ALL);
ifelse;
send_skill(you.hp, 0);
endif;



With SEND_VEC I can send three skills at a time instead of each one individual even and they wont conflict because the skills are not meant as vectors?

BTW, I already have a handle array for each charater, I might use that if it remains the same on each client.
© 2023 lite-C Forums