Simple moving example

Posted By: Dark_samurai

Simple moving example - 10/21/06 14:11

Hi guys,
I tried more than 5 times to write a code where each PC can move around with one Player, but I wasn't able to write such a code. Please post an example code, so that I can learn from it.
Thanks!

Dark_samurai
Posted By: Locoweed

Re: Simple moving example - 10/26/06 04:34

Here you go dude.

Multiplayer Barebones

That should work for you over LAN. That is as simple as it gets man, enjoy. Welcome to the joys of multiplayer, the fun has only begun. Don't be fooled by the 175 lines of code, you will have a monster in your closet. But the code is simple and small enough to help figure out how to get started.

The first thing you will have to figure out is what functions/actions are being ran on the host/server and what is being ran on the client. From there life gets easier.

Use Cursor keys to move.

When you run from WED for Host this should be Command Line:
simple.wdl -nx 50 -d hires -diag -cl -sv

For Clients on LAN:
simple.wdl -nx 50 -d hires -diag -cl

Loco
Posted By: Germanunkol

Re: Simple moving example - 10/26/06 10:49

http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/698114/an/0/page/0#Post698114

I answered to that threat a while ago, and maybe some of that answer will help you... hope it does, and I too welcome u to the fun world of MP games!

Micha
Posted By: Dark_samurai

Re: Simple moving example - 10/26/06 14:10

I think it's not that difficult to program a multiplayer program (at the moment) cause I wrote a very cool chat program with features like kick someone, make Votings, write at someone specific,... I only had problems with c_move, cause I didn't know where I have to run it. But I will take a look at this.
Thank you!

PS: I think 175 lines is "nothing" and please excuse my bad english.
Posted By: Locoweed

Re: Simple moving example - 10/27/06 00:14

The monster is still in the closet. But that is what makes it fun.

It's not getting it to run, it's getting it to run well over the internet that is a nightmare.

Trial and error. Test and tweak. Study. Test and tweak. The main thing is having someone you can constantly test with over the net.

And your welcome,
Loco
Posted By: Dark_samurai

Re: Simple moving example - 10/27/06 18:33

Quote:


It's not getting it to run, it's getting it to run well over the internet that is a nightmare.





If there would be no problems and nightmares, live would be boring!

So I've got it run now, but there is still one problem:
I have "overshootings" because of the Dead Rekoning. If I write that:

Code:

action player_move
{
my.polygon = on;
while(1)
{
player_dist.x = my.skill30 * time;
player_dist.y = my.skill31 * time;
player_dist.z = my.skill32 * time;
player_rote.pan = my.skill33;
player_rote.tilt = my.skill34;
player_rote.roll = my.skill35;
c_rotate(me,player_rote,ignore_passable + glide + use_polygon);
c_move(me,player_dist,nullvector,ignore_passable + glide + use_polygon);
ent_sendnow(me);
wait (1);
}
}


it works.

But if I only refresh the Entity, when it movement parameters are changed, it won't.

Code:

function Steuerung_Player()
{
var player_distold[3];
var player_roteold[3];
while(1)
{
if(Player)
{
player_distold[0] = player.skill30;
player_roteold[0] = player.skill33;
player.skill30 = 15 * (key_w - key_s);
player.skill33 = 2 * (key_a - key_d);

if(Player_distold[0] != player.skill30 || Player_roteold[0] != player.skill33)
{
send_skill(player.skill30,SEND_VEC);
send_skill(player.skill33,SEND_VEC);
ent_sendnow(Player);
}

camera.pan = player.pan;
camera.x = player.x;
camera.y = player.y;
camera.z = player.z + 30;
}
wait(1);
}
}


Posted By: PHeMoX

Re: Simple moving example - 10/28/06 17:24

Quote:

The first thing you will have to figure out is what functions/actions are being ran on the host/server and what is being ran on the client. From there life gets easier.




I could have started a new thread, but since you mention this, I've got some questions about it. I've looked at the code, but how exactly do you make sure a function only get's run on the client? I'm making a game on which there are only 2 player, the server and the client.

Basically it's a strategy game, so the only thing I'm doing is spawn two camera's. However the mouse code I'm using for selecting entities for both players, only works on the server for some reason.

How can I make sure it runs both on the server ánd the client? Should I use 'proc_client(my,mouse_function);'?

How to best set stuff like this up? Should I only start those functions upon a join event? Do these function then still run on the server?

(I'm probably asking before having looked into it good enough, sorry for that )

Cheers
Posted By: Dark_samurai

Re: Simple moving example - 10/29/06 08:27

Write it like that:

Code:

function main()
{
level_load(Strategy_wmb);
while(connection == 0) {wait(1);}
wait(1);
Mouse_movement(); //Start the function, which controls the camera movement
}


function Mouse_movement()
{
.
.
.
}




Each PC which enters the session starts the function Mouse_movement().
Posted By: PHeMoX

Re: Simple moving example - 10/29/06 09:20

Okey, so starting a function in the main function, won't start it on the server?? I thought those functions run on the server

Cheers
Posted By: Dark_samurai

Re: Simple moving example - 10/29/06 09:33

Quote:


Okey, so starting a function in the main function, won't start it on the server??





Yep!

Dark_samurai
Posted By: PHeMoX

Re: Simple moving example - 10/30/06 11:27

Okey, but this is still true, when the server is actually also a client? All functions started in the normal main, should actually not run on the server/not be visible there?

Cheers
Posted By: giorgi3

Re: Simple moving example - 10/30/06 21:18

ok, it looks like we all need to do a little review on WHAT RUNS WHERE. I believe that this is covered in both Locoweeds tutorial and mine, but since nobody reads mine anymore
Quote:


Rule # 1. By default, entities created with ent_create have their actions or functions run on the Server.

Rule # 2. Everything else by default runs on the same computer as the function that called it is running on.

Rule # 3. There are ways of getting around rules 1 and 2.

...

Any function called from main() will run on both the client(s) and the server. Since main runs on both, all functions called from main also run on the client(s) and the server.






Ways around this?? Try the connection variable.


The connection variable is a predefined variable that is automatically set to 0 when A6 starts up. It changes to the following values depending on how the engine was started.

0 - The engine was not started in any multiplayer mode
1 - The engine was started with –sv (Server Session)
2 - The engine was started with – cl (Client Session)
3 - The engine was started with –sv –cl (Server/Client Session)

SO ....

Code:
  main() {
if (connection == 1) {
server_only_function(); // -sv only
}

if (connection == 2) {
client_only_function(); // -cl only
}

if (connection == 3) {
server_client_function(); // -sv AND -cl
}
}
Or even cooler still:

if (connection & 1) {
any_client_function(); // (-cl) or (-sv AND -cl)
}



Posted By: Locoweed

Re: Simple moving example - 10/31/06 03:59

I took a quick glace at how your code is written Dark_samurai,

I would check out these 2 dplay variables and make sure they are set correctly for how you have your code written.

dplay_smooth & dplay_entrate.

You probably need to adjust those if you are going to be updating entities with ent_sendnow() manually.

Loco
Posted By: PHeMoX

Re: Simple moving example - 10/31/06 18:26

Thanks for your explanation Giorgi3! At the moment I'm still gathering and looking into mp tutorials, but since I'm also trying some stuff out at the same time, it's very tempting to just ask around. Sorry for this, sort of lazyness.

Cheers
Posted By: giorgi3

Re: Simple moving example - 11/01/06 02:27

No Problem. Ask all you want. It's all part of the learning process. And MP requires a lot of study/questions to get the concepts down.

And just to reiterate a tip from Loco. Test over the internet as much as possible. A LAN hides the two biggest issues in MP, Latency and Bandwidth. Both can rear there ugly head once you move your game to the internet.
Posted By: Dark_samurai

Re: Simple moving example - 11/01/06 19:06

@Locoweed: I played around with the variables and the code, but I still can't get it run without overshootings. Should I use dead reckoning, or is it better not to make use of it? I recognized that your MPbarebones also has overshootings. Can you please give me a modified version of it, without overshootings?

Dark_samurai
Posted By: Locoweed

Re: Simple moving example - 11/02/06 02:49

Try to set dplay_smooth = 0; to start with.
Posted By: giorgi3

Re: Simple moving example - 11/02/06 03:04

Hi Dark_samurai

Unfortunately the dplay_smooth algorithm has (or at least had) some bugs in it that causes overshooting. The ent_sendnow was suppose to help, but it didn't completely eliminate the problem. The issue seems to be the algorithm doesn't handle rapid changes in motion very well. You might start by just shutting it off, but that presents some other issues.

Here are a couple of MP form threads that might be of interest.

locoweed's script - overshoot revisited

MP Smoothing via c-script
Posted By: Dark_samurai

Re: Simple moving example - 11/03/06 16:39

@giorgi3: Thanks for the Links!

I had an idea:
The client controls his own character and also starts c_move. Then he saves the position of his character. He sends it to the server, which sends it to the other clients. Those correct the position of the character (for example Player3.x = Send_position[1];...).
But now I noticed, that the last part don't work. If the script should correct the position, I can't see a difference. Isn't it possible to change the position of an entity localy?

I hope you understand my idea and problem.

Dark_samurai
Posted By: giorgi3

Re: Simple moving example - 11/03/06 17:37

Um...... Yes, I understand your idea. From the MPSmoothing script referenced above:


Code:
 

/*******************************************************************************************************

Design Concept:

This concept is rather simple. I'm going to change the rotation and movement to be handled on the
client side. The servers job will then be to simply 'echo' each clients movements to all the other clients.

Traditionally 3dgs expects this to be handled on the server. To prevent the server from
sending it's automatic updates, I am setting nosend_angles and nosend_origin flags on all entities.

As we gather_input from the client keyboards, each client will apply the keyforces to it's own entity. Then
each client will send the movement coordinates of the entity via skills to the server.

The server will take these coordinates coming in from the clients and 'move' the corresponding entity. Then
the server will 'echo' these movements to all the other clients via other skills.

And finally a "client_move" function will use these 'echo' skills to move the 'echo entities' of other clients.
To smooth the movement effect client_move will use vec_lerp to interpolate the current position and rotation
of the clients' entities with these 'echoed' position updates coming from the server. Simple huh!


Note: This is not a prediction algorithm. Under very high latency this code will break down.

**********************************************************************************************************/



So, you can use that script as a reference if you like.

Also note that in the thread of discussions about this script, we kinda concluded that this method wouldn't scale well in a real game. I wrote it just so I could 'see' the client movement smoothed out without the overshoot problems you get with dplay_smooth enabled.





Posted By: Dark_samurai

Re: Simple moving example - 11/03/06 19:18

Thank you! I looked at the code and really don't understand why my code don't work: I have an Entity which is created on the server. Now I want to move it with c_move on the client side. But it tells me: Invalid Arguments???

Code:

my = Objekt_numb;
if(my != null) {c_move(my,move_dist,nullvector,glide);}



Dark_samurai
Posted By: BERG

Re: Simple moving example - 11/06/06 06:55

this is a little off topic, but how do u run a game over the internet with A6, ie, what is the command line in the run prompt box?
Posted By: oriongu

Re: Simple moving example - 11/07/06 18:52

Create a bat file whith this for the server:

game.exe -sv
you can specify -port . ex(-port 2306)
there is a -tcp option , but i never tested it. i suppose it forces the server to run on a tcp protocol, by default its on UDP protocol.

and this for the client:

game.exe -cl -ip yourip ex(-ip 85.58.35.125)

if you are behind a router , you will have to foward the specifief port UDP to your computer local ip .

hope this helps.
© 2024 lite-C Forums