Game Development Community

Client calling Server, do yo hear Server?

by Xavier "eXoDuS" Amado · in Torque Game Engine · 12/21/2001 (9:09 pm) · 9 replies

stupid title :)
Well my situtation here is this...

i have a gui (PlayerSetupDlg.gui), which also has a cs (PlayerSetupDlg.cs) the cs has a function that determines the player model the player wants (using some dts viewer) and set a variable with the filename of the model. Now what i want to do is in player.cs, change the line that sets the players shape to read the variable in the client side. How would i pass a variable from the client side script to the player.cs server side script?

Or maybe there's another easier way to do model changing?

#1
12/21/2001 (9:47 pm)
There are several ways to do this, you might want to take a look the Crime Force demo, it allows you to select a team on the client, and gives you different player shapes based on your team. This is essentially what you want to do. The demo comes with all the script source.
#2
12/22/2001 (8:09 am)
Crime FOrce's mechanism is better presented than others, but at times hard to follow (still great work, though). IF you stop in the IRC channel after the 26th, I can show you the kluge I did for Lore.
#3
12/22/2001 (9:43 am)
yes, but crimeforce does this selection once you are in the game, i want to change the model from outside the game... so sending a commandtoserver might not work...
I would like to store the playermodel in a $Pref:: and then read it from there...
maybe its possible?
#4
12/23/2001 (6:36 am)
damm crime force is looking damm sweet!
#5
01/11/2004 (9:22 pm)
Xavier, im trying to do the exact same thing with my game where I choose the player outside of the game. So far my game will load up with all the clients having the same exact model as the server. Also all the info like ammo, is only shown on the server side. Anyone know what I might be doing wrong?
#6
01/12/2004 (1:17 pm)
K, you are saving that info in pref, what you need to do is ask the client for those values before you create the player object. here is what i did in my code, might not be the best solution but it works fine.

note that the below is not just copy/paste code .. rather try understand what it do and implement it as you will just break your own code if you copy this as is.

in game.cs (on server side)
in function GameConnection::onClientEnterGame(%this)
....
//%this.spawnPlayer();
commandToClient(%this, 'LetsSpawn'); // as client for its info
then all this in game.cs:
function GameConnection::spawnPlayer(%this, %model,%skin)
{
   %spawnPoint = pickSpawnPoint();
   %this.createPlayer(%spawnPoint,%model,%skin);
}

// leslie - from the client
function serverCmdspawnPlayer(%client, %model, %skin)
{
  %client.spawnPlayer(%model,%skin);
}
//-----------------------------------------------------------------------------
function GameConnection::createPlayer(%this,%spawnPoint,%model,%skin)
{
  ...
// gonna create the player now (i name all my player datablocks something like
// namePlayer where name could be Player1, Boy, Alien or whatever else models
// i used
  %playerDataBlock = %model @ "Player";

    // Create the player object
    %player = new Player() {
        dataBlock = %playerDataBlock;
        client = %this;
    };
    
    MissionCleanup.add(%player);

    // Player setup...
    %player.setTransform(%spawnPoint);
    %player.setShapeName(%this.name);
    %player.setSkinName(%skin); // leslie - skin/model select support

    %this.camera.setTransform(%player.getEyeTransform());
    %this.player = %player;
    %this.setControlObject(%player);
    
}

tahts it for the server side, on the client, in client.cs i have
// command from server (it wants to spawn us a player)
function clientCmdLetsSpawn()
{
    // send the server some usefull info
    commandToServer('spawnPlayer',
        $Pref::Player::model,
        $Pref::Player::skin );
}

that should do it.
#7
01/13/2004 (5:30 pm)
Thanks a lot Leslie! This has helped out a ton for my game. Took me like over an hour to get this method working in my game after reading through your code and understanding it, but its now working with client and server being different models. Again thanks a lot!
#8
01/14/2004 (1:14 pm)
Always to glad to help. i'm only now starting to get a real grip on how torque works. best way to learn is to try build something with it and find ways to implement what you want to be done, a month later you have more experience and descover that you orginal idea to do something might actually be implemeted better another way. if i was to start from scratch i would try building a single player game with torque first, as it can be a pain to properly understand the server/client stuff (well it was for me anycase :p )
#9
01/29/2008 (11:53 pm)
I just used this code to create a drop down for player model selection.

One additional thing I had to do was store the player's choices in the GameConnection object in script so when he respawns he still has access to the choices we created when he entered the game.

Something like this (on the server in game.cs):

function serverCmdAckGetClientSpawnOptions(%client, %model, %skin)
{
    // call the gameConnection::SpawnPlayer code
    // using the player options

    // store the data
[B]    %client.playerDataBlock = %model @ "PlayerBody";[/B]

    %client.spawnPlayer(%model, %skin);
}

Then later on in the same file:

// Create the player object
   %player = new Player() {
      dataBlock = [B]%this.playerDataBlock;[/B]
      client = %this;
   };
   MissionCleanup.add(%player);