Player teams - Need help with commandToServer ?
by Peder Husom · in Torque X 3D · 05/05/2011 (1:37 pm) · 8 replies
Hi
I'm pretty new to Torque, but not to programming - so the syntax was pretty easy to catch up with.
The thing I'm having problem with is understanding what to edit. I want to add teams to the player. As in; team 1 vs. team 2.
But would I add that in the datablock(and which of them?) or the .cs file?
And I can't find any proper beginner documentation. The docs that come with the Torque is.. *bad*.
Btw; Any books I can buy? Prefer e-books as I don't have a static(is that correct english?) adress yet.(On the move)
I'm pretty new to Torque, but not to programming - so the syntax was pretty easy to catch up with.
The thing I'm having problem with is understanding what to edit. I want to add teams to the player. As in; team 1 vs. team 2.
But would I add that in the datablock(and which of them?) or the .cs file?
And I can't find any proper beginner documentation. The docs that come with the Torque is.. *bad*.
Btw; Any books I can buy? Prefer e-books as I don't have a static(is that correct english?) adress yet.(On the move)
#2
I searched the resources for "team"/"teams" but the search returns things from the blogs, forums, and the whole site?
05/06/2011 (6:20 am)
When you say engine changes, does that mean changes in the sourcecode? :)I searched the resources for "team"/"teams" but the search returns things from the blogs, forums, and the whole site?
#4
05/06/2011 (8:05 pm)
Yeah, that's the resource I meant, and there's another one for T3D as well. The one Greg linked to has no source code changes, only script.
#5
Here is the function in my "commands.cs":
It returns the error
Unable to find object: '' attempting to call function 'preparePlayer'
Soo.. seems like there is no %this, %game or $game in the commands.cs -- so how do I get to the GameCore::preparePlayer(%game, %client) function?
By the way, the resource is relaying on clientside it seems. So had to swap around on things. (Actaully learned everything I know about Torque thanks to that :D )
05/11/2011 (11:00 am)
Okey, got something working here.. But I got a problem with spawning the player..Here is the function in my "commands.cs":
function serverCmdzmSelectClass( %client , %classid )
{
if( %classid < 1 || %classid > 5 )
{
error(" :: ZM Server :: ");
error(" Client = " @ %client );
error(" Sent a invalid class-id: " @ %classid );
return false;
}
// Translates the %classid to the corrent $PlayerClass
switch$( %classid )
{
// Heavy
case 1:
%client.class = $PlayerClass_Heavy;
// Medic
case 2:
%client.class = $PlayerClass_Medic;
// Engineer
case 3:
%client.class = $PlayerClass_Engineer;
// Scout
case 4:
%client.class = $PlayerClass_Scout;
// Sniper
case 5:
%client.class = $PlayerClass_Sniper;
// Should never happen - but who knows?
default:
// Invalid data, disconnect player - need to be added
error(" :: ZM Server :: ");
error(" Invalid class-id, catched by switch-statement! ");
}
%client.classId = %classid;
echo(" :: ZM Server :: ");
echo(" Client = " @ %client );
echo(" Selected class with id: " @ %classid );
echo(" Now going to prepare spawn. ");
// Time to spawn the player
%this.preparePlayer( $game , %client );
}It returns the error
Unable to find object: '' attempting to call function 'preparePlayer'
Soo.. seems like there is no %this, %game or $game in the commands.cs -- so how do I get to the GameCore::preparePlayer(%game, %client) function?
By the way, the resource is relaying on clientside it seems. So had to swap around on things. (Actaully learned everything I know about Torque thanks to that :D )
#6
server -> client
client -> server
just basic server -> client -> server model there... adapt as necessary.
05/17/2011 (2:44 pm)
just some things to go after here:server -> client
//the following is on the server
function printTo(%client, %number) {
commandToClient(%client, 'HelloWorld', %number);
}
//the following is on your client script
function clientCMDHelloWorld(%number) {
echo("Server Says: Hello World!");
echo("Server Says: Print number "@%number@"");
}client -> server
//the following is on the client
function ImHere(%number) {
commandToServer('sendPresentMessage', %number);
}
//the following is on the server
function serverCmdsendPresentMessage(%client, %number) {
echo("Client "@%client@" is present and gave me number "@%number@"");
}just basic server -> client -> server model there... adapt as necessary.
#7
What is $game? Some sort of global variable? Is this the game Script Object?
This is obviously Torque 3D script so this question/problem shouldn't be in the TorqueX forums... but to get to the script object that handles the gametype stuff outside of the actual gametype code simply call the function using the name of the script object which in turn passes the correct gametype class/namespace for you - GameTypeXYZ would be the class, GameCore is the superclass:
05/17/2011 (3:02 pm)
// Time to spawn the player %this.preparePlayer( $game , %client );
Quote:There is no %this (nor %game) in that function - check your argument names. Local variables are only in scope for the functions that use them. If it's not created in said function or passed to said function it doesn't exist.
It returns the error
Unable to find object: '' attempting to call function 'preparePlayer'
Soo.. seems like there is no %this, %game or $game in the commands.cs -- so how do I get to the GameCore::preparePlayer(%game, %client) function?
What is $game? Some sort of global variable? Is this the game Script Object?
This is obviously Torque 3D script so this question/problem shouldn't be in the TorqueX forums... but to get to the script object that handles the gametype stuff outside of the actual gametype code simply call the function using the name of the script object which in turn passes the correct gametype class/namespace for you - GameTypeXYZ would be the class, GameCore is the superclass:
// Time to spawn the player game.preparePlayer(%client); // notice that game is the object name itself, not a variablegame = the gametype ScriptObject. The script object will then pass the relevant gametype class namespace (GameCore or GameTypeXYZ) to function preparePlayer() as the first argument. %client gets passed as normal for the second argument.
#8
06/21/2011 (7:15 am)
Wrong forum? :)
Torque Owner Willbkool
Gamebox Creations