Game Development Community

what could be the easiest way to get any information about any specific client from server?

by Ahsan Muzaheed · in Torque 3D Professional · 08/08/2012 (10:38 am) · 2 replies

i was in need of all client's player name(nameBase field value of client).
so i went with these approaches:

01.from me(client) send a server command to transmit all client's namebase info 1 by 1 to me.
02.now from server send a client command to store all reciving info into a array.
03.now in client machine u have all client name in an array.




here is my code:

function serverCmdFillClientNameList(%client)
{
  %count = ClientGroup.getCount();
  for ( %i = 0; %i < %count; %i++ )
     commandToClient( %client,'FillClientNameList',%i,(ClientGroup.getObject(%i )).getFieldValue("nameBase");
}

function clientCmdFillClientNameList(%index,%name)
{
   $clientNameList[%index]=%name;
   //echo("$clientNameList[" @ %index @ "]--" @$clientNameList[%index]);
   //$clientNameList[%index+1]="";//just to detect where list finished
}


now in client u have to do this server command:

commandToServer('FillClientNameList');

all name will be stored in $clientNameList[] array(1 by 1)


well,it works fine.no problem.
but now i need a looooot of info about each client.
do i have to send all info in this way?
or there is any other way?
any builtin function?
or anything?

About the author

Torque 3D enthusiastic since 2010.Have been working in several T3D projects besides of Unreal Engine 4 and Unity 3D. NEED a hand with your project? SHoot me a mail. http://www.garagegames.com/community/forums /viewthread/138437/


#1
08/08/2012 (12:52 pm)
Those RPC calls are pretty much the easiest way to go about it. Of course you can improve upon what you're doing by using SetField() and GetField() utility functions. Like in this updating an ingame scoreboard example:
function serverCmdGetPlayers(%client)  
{
	// retrieve count of clients
	%count = ClientGroup.getCount();

	// let requesting client know how many records to expect to receive
	commandToClient(%client, 'PlayersListCount', %count);

	for(%i = 0; %i < %count; %i++)
	{
		// clear string
		%str = "";
		%pos = -1;

		// get player object of a client's connection object
		%player = ClientGroup.getObject(%i).player;

		// populate player record with properties
		%str = SetField(%str, %pos++, %player.getFieldValue("id"));
		%str = SetField(%str, %pos++, %player.getFieldValue("name"));
		%str = SetField(%str, %pos++, %player.getFieldValue("kills"));
		%str = SetField(%str, %pos++, %player.getFieldValue("deaths"));
		%str = SetField(%str, %pos++, %player.getFieldValue("xp"));
		%str = SetField(%str, %pos++, %player.getFieldValue("team"));

		// send player's record string to requesting client
		commandToClient(%client, 'PlayersListRecord', %i, %str);
	}

}

function clientCmdPlayersListCount(%count)
{
	echo("Player Records to Receive: ". %count);
	$PlayerRecordsCount = %count;

	// or clear scoreboard
	GScoreBoard.clear();
}

function clientCmdPlayersListRecord(%pos, %record)
{
	// store player record
	$PlayerRecords[%pos] = %record;

	// or instead just populate the scoreboard.
	GScoreBoard.addRow(GetField(%record, 0), %record);
}
#2
08/08/2012 (4:05 pm)
thanks for "%player = ClientGroup.getObject(%i).player; ".
it gave me an idea.

i was thinking to send some data from 1 client to another client.as there is no way to bypass server so i was thinking to do this:

01.
in function connect(),set a unique flag for each client.
%client.flag=$prviousFlag+1;//$prviousFlag=0;


02.
now send flag info in each client.
function serverCmdFillClientFlagList(%client)  
{  
  %count = ClientGroup.getCount();  
  for ( %i = 0; %i < %count; %i++ )  
     commandToClient( %client,'FillClientFlagList',%i,(ClientGroup.getObject(%i )).getFieldValue("flag");  
} 

function clientCmdFillClientflagList(%index,%flag)  
{  
   $clientflagList[%index]=%flag;  
   //echo("$clientNameList[" @ %index @ "]--" @$clientNameList[%index]);  
   //$clientNameList[%index+1]="";//just to detect where list finished  
}

03.
send server command to send data to that specific client:
function serverCmdSendDataToclient(%client,%flag,%data)  
{  
  %count = ClientGroup.getCount();  
  for ( %i = 0; %i < %count; %i++ ) 
{
 %reciver=ClientGroup.getObject(%i );
 if(%reciver.getFieldValue("flag") $= %flag) 
     commandToClient( %reciver,'TakeTheInfo',%data);
}  
}


03.
do the sending command in client:
commandToServer('SendDataToclient',$clientflagList[%index],%data);



the problem is to get this correct %index(in step 3) i have to do some more work.

ohh,
too much to do in script just to send a data.receiving from server was much shorter.

so i was thinking to find a data field,which is unique for each client.
anything like:
%client.id
?

if i can get one then may be i can add a c++ function to make this thing much easier.
or any different idea


**sorry for this long codes.
i just want to give full description to help u thinking.