Game Development Community

Grabbing the client

by Camel Taylor · in Torque Game Engine · 10/12/2006 (12:56 am) · 2 replies

I have never thought about this before and never have read anything on the subject, but how do I get the players handle? Does a function that exist that simply , returns the client handle. I figured the best way of proably doing this is by going throught the client some how, since the clilent points to player obj. However I can't figure out how to grab a handle out of the air. I need to figure this out so that I can simpley press a button have the function grab the player's handle.

Thank you for any help

P.S. I know that I could make a global variable that just keeps a copy of the player handle at creation of the player object, I just wanted to know if there are any ingame scripts that handle this sort of situation. I'm really trying to do everything in game script

#1
10/12/2006 (2:30 am)
If I understand you right, you're talking about a multiplayer environment, so a client/server thing, right? If so, it's easy. If you press a key on the client, you invoke a commandToServer command. Look in client/scripts/client.cs.

Just as example - put into client/scripts/client.cs this function:
function testGetTheClient()
{
   commandToServer('[b]TestGetClientPressingTheKey[/b]');
}
Put in a key command in client/scripts/default.bind.cs like this:
moveMap.bind( keyboard, "alt g", testGetTheClient);

Then, in "server/scripts/commands.cs" put in this function:
function serverCmd[b]TestGetClientPressingTheKey[/b](%client)
{
   echo("The id of the client that called this function here is: " @ %client);
}

So, if you start up your game and press ALT + g you should see in the console a line outputting the client's id. Is that what you wanted?

Note: This is all written out of the head and not tested. It should work if I didn't make a stupid typo somewhere... :-)

Martin
#2
10/15/2006 (1:02 am)
I don't know what i was thinking, or rather I did know. I keep thinking of things from a single player perspective, and ignoring the whole client server set up. I should have just used commandtoclient and commandtoserver which i did; after all I am making a two player project. Everything works fine now thanks for the reply