Hi Andreas,
yes, I used entPlayer at the send_skill command.
I implemented your change, your proposed code now looks like this:
// Simple Multiplayer
// 3D Gamestudio A7 Version 7.05 commercial
// H.Berkelmann 2007
#include <acknex.h>
#include <default.c>
ENTITY* clPlayer;
ENTITY* svPlayer;
ENTITY* entPlayer;
var isMove = 0;
var isInput = 0;
var showX = 0;
var showY = 0;
function moveMe () { // movement for both on server
while (1) {
my.x += my.skill1 * time_step;
my.y += my.skill2 * time_step;
ent_sendnow (me);
isMove++;
if (isMove > 999) isMove = 0;
wait (1);
}
}
function getInput () { // wsad control on client and server separately
while (entPlayer == NULL) {
if (connection == 2) entPlayer = clPlayer;
if (connection == 3) entPlayer = svPlayer;
wait (1);
}
while (1) {
if (key_w == 1) entPlayer.skill1 = 5;
if (key_s == 1) entPlayer.skill1 = -5;
if (key_a == 1) entPlayer.skill2 = 5;
if (key_d == 1) entPlayer.skill2 = -5;
if (!key_any) {
entPlayer.skill1 = 0;
entPlayer.skill2 = 0;
}
if (connection == 2) send_skill (entPlayer.skill1, SEND_VEC|SEND_UNRELIABLE);
// send_skill (entPlayer.skill1, SEND_VEC|SEND_UNRELIABLE);
showX = entPlayer.skill1; // show input
showY = entPlayer.skill2; // show input
isInput++; // getInput running?
if (isInput > 999) isInput = 0;
wait (1);
}
}
////////////////////////////// main ///////////////////////////////////////
function main () {
level_load ("M.wmb"); // just a platform and a cylinder at +X for orientation
wait (-0.5);
vec_set(camera.x,vector(-200, 0 , 20));
while (connection == 0) wait (1);
if (connection == 2) { // client
clPlayer = ent_create ("BlueBox.mdl", vector (70, 30, 0), moveMe);
}
if (connection == 3) { // client / server
svPlayer = ent_create ("RedSphere.mdl", vector (70, -30, 0), moveMe);
}
wait (-0.5);
getInput();
}
PANEL* diag_pan = {
flags = VISIBLE;
digits (4,10,"Diagnostics",*,1,NULL);
digits (4,20,"connection =",*,1,NULL);
digits (80,20,3.0,*,1,connection);
digits (4,50,session_name,*,1,NULL);
digits (4,60,player_name,*,1,NULL);
digits (4,70,"Input :",*,1,NULL);
digits (80,70,3.0,*,1,isInput);
digits (4,80,"Move :",*,1,NULL);
digits (80,80,3.0,*,1,isMove);
digits (4,90,"Inp X :",*,1,NULL);
digits (80,90,3.0,*,1,showX);
digits (4,100,"Inp Y :",*,1,NULL);
digits (80,100,3.0,*,1,showY);
}
When I execute it, I can see at the diagnostics panel that moveMe()
and getInput() are running on the server, and getInput() on the client.
Both process the keyboard input. But - as you may expect - no change.
The red ball is moved on both by input on the server, the blue box does not
move at all.
I always try the variant with 'if (connection == 2) send_skill...' and
without the condition, because I am not sure here. Has no influence.