Game Development Community

Server && Client GameConnection

by DALO · in Technical Issues · 09/15/2008 (12:17 pm) · 6 replies

Hello,
I have a question about server/client connections. In my game, the server keeps track of certain variables for each client in the GameConnection class. Now if one of my clients sets some trigger off then I want to be able to do an effect only on the client side. How do I get access the variables on the GameConnection server side? I read somewhere that there are 2 GameConnnection id's and it seems that the client's Id is always +1 than the server id. This is in engine btw.
Thx.

#1
09/17/2008 (6:29 pm)
To do a client side only effect which is triggered on the server side a simple commandToClient should work.

If you have data that is needed on both the client and server then you should probably make it a static-field rather than just a dynamic field. Eg, add it to initPersistFields and pack/unpackUpdate, there should be some tutorials on this on the TDN. But if you really only use it on one side it just get's set on the other, you can probably do something simpler using just remote procedure calls (commandTo's).
#2
09/17/2008 (8:42 pm)
Ok, first let me ask this. If I want to create a new precipitation object and have it so that only that 1 client will have precipitation, how would I go about doing that? Because if I ever turn it on, then all clients will see the precipatation. That won't work, different levels need different precip for clients. I was thinking of 2 approaches,
1: have a variable indicating that if client's precip variable is X and X is true then render precip for that client, else, return out of the processtick function and don't render anything. I'm not sure if that would work........?
2: Somehow turn of the client/server calls and make it render client only. So if I comment out everything in initPersistFields and pack/unpack functions, would this stop the client server calls and just make it client only?
Thx for you help.
#3
09/17/2008 (9:08 pm)
I haven't used the precipitation object, but in general, if you create it on the server it will be ghosted to all clients, but you can create it for only one client.
// server side
commandToClient( %client, 'CreatePrecipitation' );

// client side
function clientCmdCreatePrecipitation()
{
   $myRain = new Precipition();

   // if you want it to be deleted when the mission ends
   MissionCleanup.add( $myRain );   
}

If this is something you need only one of but you want to turn on/off you could create it for each client is a variety of places, like maybe in GameConnection::initialControlSet(%this) And use commandToClient to turn it on/off, unless the client already knows when to do that.
#4
09/17/2008 (9:45 pm)
Yeah, I thought I tried that before and had no such luck. So in attempts to try again, when my character/client goes to a new level a commandToClient(%client, 'startPrecip', %client) is called.
Here is my function:
function clientCmdstartPrecip(%client){
   
   %temp = new Precipitation() {
      canSaveDynamicFields = "1";
      Position = "782.748 -124.769 178.293";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      nameTag = "FairyDust";
      dataBlock = "specks";
      minSpeed = "0.0005";
      maxSpeed = "0.0051";
      minMass = "0.001";
      maxMass = "0.005";
      maxTurbulence = "0.028";
      turbulenceSpeed = "0.013";
      rotateWithCamVel = "0";
      useTurbulence = "1";
      numDrops = "5000";
      boxWidth = "270";
      boxHeight = "40";
      doCollision = "0";
   };
     
   %client.precip = %temp;
}

When this function is called I get this message in the console:
Quote:
Object 'specks' is not a member of the 'GameBaseData' data block class
game/client/scripts/effects.cs (25): Register object failed for object (null) of class Precipitation.
Maybe my new precipitation is wrong? I do have a datablock in my server side scripts environment.cs

datablock PrecipitationData(specks){
   
   //soundProfile = "Highland";
   dropTexture = "~/data/environment/spark";
   dropSize = 0.5;
   useTrueBillboards = false;
   splashMS = 250;
};

Does this look alright to you? What would cause the error? Another thing is that when the person that is hosting the game, and they go to a new level. The precip that they create effects everyone......?
Thx again.
#5
09/18/2008 (12:05 pm)
First, client commands do not receive a %client argument like sever commands do, the ServerConnection object would be the equivalent I suppose.

As I said, I have not used precipation objects myself, so I can't say if there is anything wrong with your PrecipitationData code. But in general you cannot reference a server side object on the client side by name. Although datablocks are all "networked" and guaranteed to have the same id, the name is NOT.

If you are using TGEA objects have an internalName field which IS networked, so you could do a findByInternalName on the ServerConnection (which derives from SimGroup among other things).

An easier thing might be to have the server directly tell the client the datablock id, like after the mission is downloaded, do a commandToClient that passes the precipdata id and the client stuffs that in a global var to be used later. Actually, just pass it in the same commandToClient that creates the Precipition!

Quote:
Another thing is that when the person that is hosting the game, and they go to a new level. The precip that they create effects everyone......?
As long as you are creating the Precipition object in a clientCmd function I wouldn't expect that to happen. If that IS what's happening, i'm sure its fixable but I don't know the solution without some research.
#6
09/19/2008 (6:48 am)
Hey James, yeah that %client was just an extra parameter being passed in, not being used anymore anyways. Ok, so I have attempted to try what you suggested, thx for your help btw, where I pass a list of Id numbers created by the server for the specific precip datablocks and in return it got rid of that error message I had before when the client starts the precip. Unfortunately it's still a no go. The precip object exists, but the client cannot see it. If the client that is hosting the server advances to the same level the precip still shows on all clients......Bummer. I may just make a new post and see if anyone else knows. Thanks again for your input.