Game Development Community

Replacement for LocalClientConnection on client side?

by Lee Latham · in Torque Game Engine · 05/02/2007 (11:48 pm) · 7 replies

Hello,

I've been happily using LocalClientConnection to identify the client while running in dual server/client mode, but when I separate into dedicated client it no longer works. I searched around in the forums and find that this is expected. Is there another way to get this information? What I'm doing is quite simple:

this is a replacement jump function, because I want a special vehicle jump to happen, IF the client is mounted on a vehicle.
function jumpy(%val)    
{                
   %obj = LocalClientConnection.getControlObject(); //this works on the combined server/client, but not client only
   %client = %obj.client; 
          //I suppose I could have done this on one line.  I'm a beginner, what can I say? :-)
   
    if (%obj.getClassName() $= "WheeledVehicle")
      serverCmdJumpBoost(%client);
      else
   $mvTriggerCount2++;
}
I tried turning this into a ServerCmd function, but the trigger command apparently
doesn'tt propagate to the client. Sure wish I understood how triggers worked!

Any input would be greatly appreciated (as usual!)

#1
05/03/2007 (12:32 am)
Hey Lee -

it sounds to me like you want to modify functionality on the server side, not the client side.

if you want a special jump to happen if the client is mounted to a vehicle,
it's the server which should make that call, not the client.

there's two quick uh thought-tests i find useful for deciding if something should happen server-side or client-side:
* if a smart and malicious user hacks their client, could they exploit this to affect the game for other players ?
if yes, then the thing should be server side, not client side.

* do i want the effect of this thing to be visible for all players, or just for one player ?
if yes, then again it probably belongs server side.

things get more complicated than that, but those are the first two i ask myself.

so to me it seems like you want a server-side jump() function which looks something like:
function serverSideJump(%client)
{
   %obj = %client.getControlObject();
   if (%obj.getClassName() $= "WheeledVehicle")
      jumpSpecial(%client);
   else
      jumpNormal(%client);
}
#2
05/03/2007 (12:36 am)
Alternatively, you could do something like:

function serverSideJump(%client)
{
   %obj = %client.getControlObject();
   %obj.doJump();
}

function WheeledVehicle::doJump(%this)
{
   // do the special jump
}

function Player::doJump(%this)
{
   // do the normal jump
}
#3
05/03/2007 (12:47 am)
Hi Orion!

Thanks for the responses. I believe I see where you are coming from. The only problem is that this involves the built in script jump command, which is simply the mysterious "$mvTriggerCount2++" business, which I have yet to find an explanation for. And that variable only seems to work when incremented on the client. Unless...turning the problem inside out...I could send the client a command from the server to do that?

I think I just blew my own mind :-) How would/could you do that?

Now I suppose I _could_ write my own player jump function...but it works so nice the way it is, triggering animations and such, it seems a bit of a waste.

This is the stock jump function:

function jump(%val)
{
   $mvTriggerCount2++;
}

I would be grateful if you (or anyone) could point me to a nice explanation of how the triggers work. Why is it incremented twice? How is it that in a WheeledVehicle it applies the brakes? If I could grasp that it might be a simple matter to solve my problem.
#4
05/03/2007 (12:57 am)
//-----------------------------------------------------------------------------
// (Client)
//-----------------------------------------------------------------------------

function jump(%val)
{
   commandToServer('Jumpy', %val);
}

function clientCmdJumpy(%val)
{
   if(%val)
      $mvTriggerCount2++;
   else
      $mvTriggerCount2--;
}

moveMap.bind( keyboard, space, jump );

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// (Server)
//-----------------------------------------------------------------------------

function serverCmdJumpy(%client, %val)
{
   if(%client.getControlObject().isMounted)
   {
      // Do vehicle jump code here
   }
   
   else
      commandToClient(%client, 'Jumpy', %val);
}
//-----------------------------------------------------------------------------

The trigger isn't incremented twice. Trigger 0 is primary fire, trigger 1 is alt fire, trigger 2 is jump and so on. The %val variable determines if a key has been pressed or released and is used to activate and deactivate the jump trigger accordingly.
#5
05/03/2007 (1:49 am)
Oh that is so freaky, Tim, thank you!

I'm pretty sure I grok it. I'm too sleepy now to properly contemplate it (try it out), but will do first thing tomorrow. CommandtoClient! Who'da thought it? ;-) So it's kind of a round trip deal....I do believe it makes perfect sense.

That %val business was disturbing me until this moment when I read your explanation. Torsion told me it was 1, but that's all I knew about it.

Thanks to you both for your trouble. So what does $mvTriggerCount3 do? or 4? Where would I look? I've searched the source but I can't make heads or tail of what I find there for that, and same with the scripts.
#6
05/03/2007 (2:12 am)
Think of triggers as actions. Each action is assigned a trigger (0 fire, 1 alt fire, 2 jump, 3 jet etc) and setting the corresponding trigger state to true will call that action.

That's what this line does:
$mvTriggerCount2++;
That sets the jump action to true.
$mvTriggerCount2--;
That sets the jump action to false.

$mvTriggerCount3 is used for jetting (like a turbo boost when in a vehicle). In Tribes2 it's also used for player jetting (flying through the air) but this functionality isn't in the engine as stock though you can add it in (search my profile, I've submitted a resource for it).

By default trigger 2 is also used as a handbrake when the controlling object is a wheeled vehicle (i.e. the main player object is the vehicle and not a player mounted in a vehicle). If a player is mounted to and controlling a vehicle trigger 2 is used to dismount. I shifted these triggers around in source so that I may still use the handbrake when a player is mounted in a vehicle.

%val = 1 on key press down and 0 on release. This gives you greater control over keyboard actions (e.g. press and hold down a key and a car horn sounds, release the key to stop the sound).

As for the "round trip deal", that's pretty much right. Some functions are only available on the server and others only on the client so sometimes you have to jump around a bit. Orion does a good job of explaining whether to initiate things on the server or the client.
#7
05/03/2007 (7:51 pm)
Tim: Thanks again for the "examples"...which I basically copy/pasted and it worked just fine. I do believe I understand it just fine, and I've learned some things :-)

May I ask a further question about triggers? I'm no coder so I'm struggling to grasp this. The stock jump command just does $mvTriggerCount2++, but never does the $mvTriggerCount2--, which makes me think the player must start bunny hopping--which is obviously not true. Is it a kind of event-driven system?

Also I've noticed that jump gets called twice every time...is this because of the press down and release signal? And how might one use the same concept for an arbitrary function, as opposed to one of the triggers? That seems quite useful...

Is there like a chunk of source which delineates what the triggers do? For example, I had no idea there was a vehicle boost until I'd already written my own. (and now I see you have a splendid looking jetpack resource, too. I'd found another jetpack resource after writing my own, and it was a similar script based one to my own, but I'd never seen yours until just now. I guess my resource searching skills need some work, too!)