Game Development Community

Changing GUI from Server Side

by Jorge Luis Gandulfo · in Torque Game Engine · 10/02/2003 (6:12 am) · 5 replies

I want to swap the FpsGUI for the RacingGUI when i mount into a vehicle.

Im trying to do this, with no luck.

Im using Head, and VC.NET

PD: i was trying to call some function from the fps.cs in the server, but it didn't worked.

#1
10/02/2003 (6:28 am)
You need to use commandToClient
Do a search in the examples for detailed examples but basically, you define a function on the client, say

function clientCmdChangeGui(%switch){
   if(%switch)
      changeToRaceGui();
   else
      changeToFPSGui();
}

Notice, it is called clientCmd... that tells the scripts that it can be called by running

commandToClient(%client,"ChangeGui",%switch);
on the server. IE The scripts will look for a function with the prefix clientCmd then whatever name you pass to it, then run that, passing in the given arguments.

Notice that the same works for commandToServer, just change the function name prefix to serverCmd, and you dont need to specify and specific server in commandToServer's arguments, cause there is only one ;) This is useful for telling the server that the client wants something, like changing teams.

Oh, BTW this is all done through scripts. I suppose you could do it through the engine code, but this is much quicker.
#2
10/02/2003 (3:29 pm)
Tnx for the info!

I did this finally.

This allowed me to swap the GUI when i mounted my new JetBike and back to normal when i dismount it.

1 - In function Armor::onCollision, i added this part where the Mount is handled (This was made in Player.cs / server).

commandToClient(%obj.client, 'UpdateGameGUI', "JetBikeGUI");


2 - To handle the UnMount from the vehicle i used this code in DoDismount.

commandToClient(%obj.client,'UpdateGameGUI',"PlayerGUI");


3 - Then i added this function to game.cs in client, this do all the magic.

// Initialize GameGUI  and active it to gui screen.
function ClientCmdUpdateGameGui(%gui)
{
   echo ("UpdateGameGui");
   // The GameGUI isn't loaded here directly. Game gui is normally loaded
   // when the client first recieves a control object from the server. (This is
   // handled by the GameConnection scripts, located in serverConnection.cs)
   // But if we aren't in the editor and the game is currently in progress,
   // then we probably should load the gui...
   $Client::GameGUI = %gui;
   
   // The first control object has been set by the server
   // and we are now ready to go.

   // first check if the editor is active
   if (!Editor::checkActiveLoadDone())
   {
      // Activate if not already set...
      if (Canvas.getContent() != $Client::GameGUI.getId())
         Canvas.setContent($Client::GameGUI);
   }
}
#3
03/31/2006 (8:34 am)
I have tried to implement this.. to no avail. Yet I've done what Jorge's done : (


the UpdateGameGUI function doesn't seem to work for because the echo command is never printed on the console.

Is there something I'm missing?
#4
04/04/2006 (3:46 pm)
You were lucky i was checking old posts :)

Im not in front of a computer with torque atm, im on a trip so i cant tell what you might be doing wrong, but you should check this:

1 - Did you copied the ClientCmdUpdateGameGui function inside the game.cs in the Client directory? maybe you did it into the server scripts game.cs.

2 - Are you sure you are calling this function in a place that is actually executed?
You might check if this function works by manually executing it in the console as well.

Otherwise i cant help you with this little information :(
#5
04/04/2006 (4:31 pm)
I think this is probably a result of Tasty's troubles getting commandToClient() to work.
see this thread.