2 registered members (AndrewAMD, alibaba),
1,184
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
MP player...
#210185
06/08/08 19:35
06/08/08 19:35
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
What's the problem in this code? Can anyone please explain me...? on server, cube is moving and client can see it but client cannot move its cube... here's the code::
#include <acknex.h>
#include <default.c>
STRING* messages_str = "#50";
FONT* arial_font = "Arial#20";
TEXT* messages_txt =
{
pos_x = 10;
pos_y = 10;
layer = 10;
font(arial_font);
string (messages_str);
flags = visible;
}
ENTITY* cam;
VECTOR camVel;
void cameraAct();
void main()
{
if (!connection)
{
str_cpy(messages_str, "Can't find any server. Please try again later.");
wait (-4);
sys_exit(NULL);
}
if (connection == 2)
{
str_cpy(messages_str, "Running as a client");
level_load("test.wmb");
//cameraAct();
}
else
{
str_cpy(messages_str, "Running as a server");
level_load("test.wmb");
//cameraAct();
}
cam = ent_create("aim.mdl", vector(0,0,100), cameraAct);
}
void cameraAct()
{
wait(4);
while(1){
camVel.x = (key_w - key_s) * time_step * 15;
camVel.y = (key_a - key_d) * time_step * 15;
cam.pan -= mouse_force.x * time_step * 15;
cam.tilt += mouse_force.y * time_step * 15;
c_move(cam, camVel, nullvector, GLIDE);
if(connection == 2){
send_var_to (cam,camVel.x);
}
wait(1);
}
}
Last edited by cerberi_croman; 06/09/08 13:57.
Ubi bene, ibi Patria.
|
|
|
Re: MP player...
[Re: croman]
#210279
06/09/08 15:15
06/09/08 15:15
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
ooh come on, i can't believe that noone of you don't know how to solve this...
i would appreciate if you just try to help...
Ubi bene, ibi Patria.
|
|
|
Re: MP player...
[Re: croman]
#210357
06/10/08 01:06
06/10/08 01:06
|
Joined: Jan 2003
Posts: 517 Illinois
giorgi3
User
|
User
Joined: Jan 2003
Posts: 517
Illinois
|
Ok, I'll point you in the right direction.
If you look up ent_create you will see that the third parameter is the function (or action) that you want to associate with your new entity. In your case it is cameraAct (). What is very unclear to most MP newbies is that this function is actually executing on the server, even when the ent_create is run on the client.
Since the cameraAct function is running on the server, even for the clients entity, the connect == 2 will never be true.
"Huh?" you say?
Sorry, if this doesn't make any sense then you need to go look up the MP tutorials available on Acknex. Locoweeds tutorial goes into a lot of detail on this and lots more.
You can read through mine as well, but it is quite out of date.
Last edited by giorgi3; 06/10/08 01:09.
Giorgi3
10,000 parts flying in a close formation does not constitute an airplane. Some assembly is required.
|
|
|
Re: MP player...
[Re: giorgi3]
#210402
06/10/08 11:45
06/10/08 11:45
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
aah, thanks but still that didn't helped much... if anyone of you could tell me how to make this code works? all i want is that something moves on server and client.
i read locoweed's tutorial several times and looked in his mp lite-c code but i still cant figured it out...
can someone please help a bit?
Ubi bene, ibi Patria.
|
|
|
Re: MP player...
[Re: croman]
#210487
06/10/08 22:55
06/10/08 22:55
|
Joined: Mar 2003
Posts: 5,377 USofA
fastlane69
Senior Expert
|
Senior Expert
Joined: Mar 2003
Posts: 5,377
USofA
|
ooh come on, i can't believe that noone of you don't know how to solve this...
FYI... we are not a "one day customer support". If people don't post it's because they are busy, they don't know, or they just don't care. Please be patient with us and we'll be patient with you. aah, thanks but still that didn't helped much...if anyone of you could tell me how to make this code works? Actually, I thought Giorgi told you what to do already but I'll restate to emphasize the importance of his advice: Even though ent_create is called on the client, the object is controlled by the server exclusively. Even if you "my.x=" it on the client, the server will 'warp" it back to it's position on the next update (within 500 ms). Thus you have to make sure that the client sends a variable to the server for the server to know to move the client's object. Then, the server must transmit the position back to the client (automatically done by GS). You then create a camera routine that follows the object irregardless of whether you are client or server and Voila! you should be able to move and see on both client and server.
|
|
|
Re: MP player...
[Re: fastlane69]
#210536
06/11/08 11:52
06/11/08 11:52
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
sorry for not being patient but i lost my nerves with that code... giorgi have told me what i already knew but thanks anyway to him... BTW, i've managed to fix the code, my mood's much better now. sorry again...
#include "RakGS.h"
#include <acknex.h>
#include <default.c>
FONT* arial_font = "Arial#20";
TEXT* messages_txt =
{
pos_x = 10;
pos_y = 10;
layer = 10;
font(arial_font);
string (messages_str);
flags = visible;
}
//---------------------------------------------------------------------------------------------||
// some global vars, defines...
//---------------------------------------------------------------------------------------------||
#define force_x skill1
#define force_y skill2
#define force_z skill3
#define force_pan skill4
#define MAX_CONNECTIONS 8
VECTOR camVel;
var force[3];
var vecFrom[3];
var vecTo[3];
var people_connected;
var player_number;
//---------------------------------------------------------------------------------------------||
// function prototypes
//---------------------------------------------------------------------------------------------||
function playerAct();
function inputs();
//---------------------------------------------------------------------------------------------||
// main function
//---------------------------------------------------------------------------------------------||
function main()
{
video_mode = 8;
video_depth = 32;
video_screen = 2;
fps_max = 60; // lock fps at 60 for all players
fps_lock = ON;
dplay_smooth = 0; // dplay_smooth is causing too much overshoot and jerks
wait(-.3);
if(connection == 3){
people_connected = 1;
str_cpy(messages_str, "Connected as a HOST...");
}
if(connection == 2){
people_connected += 1;
send_var(people_connected);
str_cpy(messages_str, "Connected as a CLIENT...");
}
level_load("test.wmb");
wait(-.3);
player = ent_create("aim.mdl", vector(0,0,100), playerAct);
wait(-.3);
inputs();
while(!player)
{
wait(1);
}
}
//---------------------------------------------------------------------------------------------||
// function for handling inputs
//---------------------------------------------------------------------------------------------||
function inputs()
{
while(1){
player.force_x = (key_w - key_s) * time_step * 15;
player.force_y = (key_a - key_d) * time_step * 15;
player.force_pan -= mouse_force.x * 15 * time_step;
if(connection == 2){
send_skill(player.force_x, SEND_VEC);
send_skill(player.force_pan, 0);
}
wait(1);
}
}
//---------------------------------------------------------------------------------------------||
// move player function
//---------------------------------------------------------------------------------------------||
function movePl()
{
while(1){
my.pan = my.force_pan;
force[0] = my.force_x * 15 * time_step;
force[1] = my.force_y * 10 * time_step;
force[2] = 0;
move_mode = GLIDE|IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_YOU;
c_move(my, force, nullvector,move_mode);
// scan for floor if we are moving
if (my.force_x || my.force_y || my.force_z)
{
//Scan floor
trace_mode = IGNORE_SPRITES|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_MODELS|USE_BOX;
vec_set(vecFrom,my.x);
vec_set(vecTo,my.x);
vecTo[2] -= 400;
result = c_trace(vecFrom,vecTo,trace_mode);
my.z = target.z + ((my.max_z - my.min_z)/2);//Set to the floor
}
wait(1);
}
}
//---------------------------------------------------------------------------------------------||
// player action
//---------------------------------------------------------------------------------------------||
action playerAct()
{
my.emask |= ENABLE_DISCONNECT;
my.smask |= NOSEND_FRAME;
c_setminmax(my);
wait(-3);
ent_sendnow(my);
wait(-3);
movePl();
}
Ubi bene, ibi Patria.
|
|
|
|