[DE] Ich habe 2 Probleme bei Server/Client:
1. Wenn ein Spieler den Server verlässt, wird die enity nicht entfernt
2. wenn der 3. Client connected kommt ein Fehler
(Quelltext und Fehlermeldung, siehe unten)

[EN] I have 2 problems with Server/Client:
1. If a Player left the Server, the enity won't be removed
2. If the 3rd Client connected there comes an Error-MEssage
(Sourcecode and Error-Message, see under this text)

Fehlermeldung/Error-Message:
Quote:
---------------------------
2nd World CLIENT...: client.exe - Fehler in Anwendung
---------------------------
Die Anweisung in "0x10014a64" verweist auf Speicher in "0xffc44558". Der Vorgang

"written" konnte nicht auf dem Speicher durchgeführt werden.


Klicken Sie auf "OK", um das Programm zu beenden.
Klicken Sie auf "Abbrechen", um das Programm zu debuggen.
---------------------------
OK Abbrechen
---------------------------


Quelltext/Sourcecode:
Code:
// Codegrundgerüst by: cerberi_croman und virtualmarc

#include <acknex.h>
#include <default.c>
#include "status.c"
#include "windows.h"
#include "d3d9.h"


//---------------------------------------------------------------------------------------------||
// some global vars, defines...
//---------------------------------------------------------------------------------------------||
#define force_x skill1
#define force_y skill2
#define force_z skill3
#define force_pan skill4
#define force_tilt skill5
#define MAX_CONNECTIONS 8

VECTOR camVel;
var force[3];
var vecFrom[3];
var vecTo[3];


//---------------------------------------------------------------------------------------------||
// function prototypes
//---------------------------------------------------------------------------------------------||
void playerAct();
void inputs();
void server_called();
void client_called();
void donothing(){wait(1);}


//---------------------------------------------------------------------------------------------||
// 1st Person Kamera Funktion
//---------------------------------------------------------------------------------------------||
void pl_cam()
{
	while(1) {
		camera.pan = player.pan;
		camera.tilt = 0;
		camera.roll = 0;
		camera.x = player.x;
		camera.y = player.y;
		camera.z = player.z + 50;
		wait(1);
	}
}


//---------------------------------------------------------------------------------------------||
// 3rd Person Kamera Funktion
//---------------------------------------------------------------------------------------------||
/*
var dist_planar =  300; // Distanz vom Spieler
var cam_angle = 0;

void pl_cam()
{
	while(1) {
		camera = player.x - cos (cam_angle) * dist_planar; 
    	camera.y = player.y - sin (cam_angle) * dist_planar; 
    	camera.z = player.z; 
    	camera = cam_angle; 
    	camera.roll = 0; 
    	camera.tilt = 0;
	}
}
*/


//---------------------------------------------------------------------------------------------||
// main function
//---------------------------------------------------------------------------------------------||
int 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
	
	on_server = server_called; // on server event, call server_called()
   on_esc = donothing;
   
   wait(-.3);
   if(connection == 3){
   	people_connected = 1;
   	str_cpy(messages_str, "Connecting as a HOST...");
   	wait(-3);
   	reset(messages_txt, VISIBLE);
   	set(connected, VISIBLE);
   	set(status, VISIBLE);
   	video_window(NULL,NULL,16,"HOST...");
   }
   if(connection == 2){
   	str_cpy(messages_str, "Connecting as a CLIENT...");
   	wait(-3);
   	reset(messages_txt, VISIBLE);
   	set(connected, VISIBLE);
   	set(status, VISIBLE);
   	video_window(NULL,NULL,16,"2nd World CLIENT...");
	}

   level_load("2ndworld.wmb");
   wait(-.3);
   player = ent_create("aim.mdl", vector(0,0,0), playerAct);
   
   wait(-.3);
   
   inputs();
   
    pl_cam();
   while(1)
	{
		again:
		// constantly checks if server is still online
		if(dplay_bps == 0 && dplay_latency == 0 && connection == 2)	{
			if (MessageBox(NULL, "Server is offline and the game will shutdown.", "Error", MB_OK | MB_ICONSTOP) == IDOK){
				sys_exit(NULL);
			}
		}
		if(key_esc){
			while(key_esc){wait(1);}
			if(MessageBox(NULL, "Do you really want to quit?", "Quit?", MB_YESNO | MB_ICONQUESTION) == IDYES){sys_exit(NULL);ent_remove(player);}
				else{wait(1);goto again;}
		}
		wait(1);
	}
	if (event_type == EVENT_LEAVE)
	{
		people_connected -= 1; // one less person connected to server
		send_var(people_connected); // send number of people connected
	}
}


//---------------------------------------------------------------------------------------------||
// function for handling inputs
//---------------------------------------------------------------------------------------------||
void inputs()
{
	while(1){
		player.force_x = (key_w - key_s) * time_step * 7;
		player.force_y = (key_a - key_d) * time_step * 7;
		player.force_pan -= mouse_force.x * 2 * time_step;
		
		if(connection == 2){
			send_skill(player.force_x, SEND_VEC);
			send_skill(player.force_pan, 0);
		}
		
		wait(1);
	}
}


//---------------------------------------------------------------------------------------------||
// move player function
//---------------------------------------------------------------------------------------------||
void movePl()
{
	while(1){
		my.pan = my.force_pan;
		my.tilt = my.force_tilt;
	
		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);
		
		if (my.force_x || my.force_y || my.force_z)
		{
			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);

	set(me, SHADOW);
	movePl();
}


//---------------------------------------------------------------------------------------------||
// function Server_Called(): server was called
//---------------------------------------------------------------------------------------------||
void server_called()
{
	if ((event_type == EVENT_JOIN) && (people_connected < MAX_CONNECTIONS))
	{
		people_connected += 1; // another person connected
		send_var(people_connected); // send number of people connected
	}
	if (event_type == EVENT_LEAVE)
	{
		people_connected -= 1; // one less person connected to server
		send_var(people_connected); // send number of people connected
	}
	if (event_type == EVENT_DISCONNECT)
	{
		ent_remove(player); // remove ent of player that quit
	}
}


//--------------------------------------------------------------------
// player events
//--------------------------------------------------------------------
void player_events()
{
	if (event_type == EVENT_DISCONNECT)
	{
		ent_remove(player); // remove ent of player that quit
	}
}



mfg, Marc V.