Okay sorry guys... the player pointer isn't a player it's just a pointer...
JCL believe my code is a complete mess and I completely agree with him. So I decided to rewrite it using the multiplayer tutorial as a base. Also this time I'll actually explain what I'm trying to do.
I have items in my RPG... Theses items have an ID number that determines the type of item it is. When a player kills a monster the monster drops an item and a random ID number is assigned to it.
Now lets say there is an item on the ground and a client joins the game. Naturally the item's ID number will be zero (because all skills start at 0). Now what I've been doing until now is simply telling the server to tell all clients the ID Number any time a new client joins. This is stupid because all the other clients already know the item's ID number. In order to save traffic I just want to send the information to the new client.
So let's recap:
1) I need to create an item on the server machine.
2) The item must be assigned an ID number (This must be done on the server) and all connected clients must be informed of the item's ID number.
3) If a new client joins that doesn't know the item's ID number this new client (and alone this client) must be updated.
4) I have read (many times over) the tutorials although I will admit I did miss a thing or two, BUT my game works fine and I have ZERO problems when things are sent to all clients.
I've had problems sending information to individual clients for years now. If you look me up on the forums you'll realize I'm not constantly having new problems with multiplayer... IT'S THE SAME PROBLEM. I keep just letting the thread die because I'm hoping that over time someone else would have posted something or whatever but now my game is getting to the point where I need this. I want to release a demo soon. I have a mySQL database working and everything else is working fine. This is all I need now and I can't put it off any longer.
I decided to clean up my code. There is no way I can make it easier then this:
ENTITY* item; //a pointer not called player to eliminate confusion
var itemSkill1;//a global variable for the item's skill1 so that the engine doesnt return a "IDK what item.skill1 is" error
var itemClient_id;//this is the items's client_id of the item's maker. This should be zero because the SERVER made this entity
var vClientid; //a variable to indicate the client_id of a client that has just joined
PANEL* testPNL = {
flags = SHOW;
digits(0,0,"item.skill1: %.3f",*,1,itemSkill1);
digits(0,10,"dplay_id: %.3f",*,1,dplay_id);
digits(0,20,"item.client_id: %.3f",*,1,itemClient_id);
digits(0,30,"vClientid: %.3f",*,1,vClientid);
}
function on_server_event(void* str,var id) // automatically assigned to on_server
{
if(event_type == EVENT_JOIN) //if a client joined
{
vClientid = id; //store the ID of the client that just joined into a global variable
}
}
void fItem()
{
while(my.client_id < 0) wait(1); //this item is created on the server there for client_id will be zero but I'll include it anyway
item = my; //this is an item
if(connection & CONNECT_SERVER) //in my game the server would assign the item an ID number so i'll do the same here for skill1
{
my.skill1 = 1000;
}
else //if we're not a server we're a client
{
while(my.skill1 != 1000) //wait until our skill1 because the value we know it should be. In this case 1000
{
itemSkill1 = my.skill1; //since we're locked in this loop forever because send_skill_id isn't working I want
itemClient_id = my.client_id;//to update our client_id and skill1 values.
wait(1);
}
}
while(1)
{
wait(1);
itemSkill1 = my.skill1; //this only works on the server because the client never makes it to this point
itemClient_id = my.client_id; //because it's skill1 never changes from zero
if(connection & CONNECT_SERVER)
{
send_skill_id(vClientid,my.skill1,0); //the server sends the vClientid FOREVER but the client never seems to receive it
} //regardless of the fact that the client's dplay_id is equal to vClient_id which
else //is the where the server is sending information to.
{
if(my.skill1 != 0) //if the client would ever make it to this point the problem is solved and we break out of the while loop
{
break;
}
}
}
beep(); //two beeps indicate success!!
beep();
}
on_server = on_server_event; //if a client joins two parameters are passed: the player's name and the client identification number
//this is all in the manual if you look up on_server.
void main()
{
if (!connection) { // not started with -cl / -sv -cl?
if (!session_connect(app_name,"")) // no client found on the localhost?
session_open(app_name); // start as server
}
do{wait(1);}
while(dplay_status < 2); // wait until the session is opened or joined
dplay_localfunction = 2; //run actions on both server and client
level_load("valiance.wmb"); // load the level
if(connection & CONNECT_SERVER) //are we a server?
{
ent_create("testing.mdl",vector(100,0,0),fItem); //OMG a monster was killed!!! Drop an item ont he server!
}
}
So there you go so now everyone knows what's going on. IMO send_skill_id simply isn't working.
edit: send_skill_id IS sending the information HOWEVER the client never receives it. You can download the file I posted earlier and just delete the test.c and replace it with this new script.