Game Development Community

Getting the client's GameConnection in script

by Aaron Murray · in Torque Game Engine · 11/23/2001 (8:58 pm) · 3 replies

I'm pretty sure this has been answered somewhere before, but I can't find it, and a link to whereever this is explained will be just as appreciated as an answer.

I'm just wondering how I would go about getting a reference to the client who's running the current script's GameConnection variable. In the code, you get it like this...

GameConnection * con = GameConnection::getServerConnection();

So I'm just wondering how I would go about doing this in the script, in a function which isn't passed any %client variable or anything. Thanks!

#1
11/25/2001 (9:43 am)
If you aren't passed %client, or some object which is tagged with it's owner client (such as the player), then then there is no way to know. The only time a script can be said to be "run" by a client is when a function is execed by a remote server command event. Otherwise script calls are all generated locally by the server.
#2
11/25/2001 (10:48 am)
Oh... Hmm, guess I didn't understand exactly how the scripts work... Alright, thanks for the reply!
#3
04/02/2002 (4:37 am)
well, this may not be what you want, but:

function clientCmdfoo()
{
commandToServer('moo');
}

function serverCmdmoo(%client)
{
commandToClient(%client, 'loo', %client);
}

funciton clientCmdloo(%client)
{
// the code you actually want to run goes here
}

Right: when you use commandToServer('function') then 'function' gets called with the first argument being the client which called it. You then just get the server to tell the client to run the function you originally wanted and you have hold of the client pointer.

Anyway, I bet someone's going to tell me this isn't very efficient, packet wise...