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 send_skill_id2(var id, var* skill, var mode)
{
for (you = ent_next(NULL); you; you = ent_next(you)) {
if(you.client_id == id) {
send_skill_to(you,skill,mode);
break;
}
}
}
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_id2(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!
}
}