[Fixed]CoD-Style Client Inventory Not Working...
by CSMP · in Torque Game Engine · 08/19/2009 (5:42 pm) · 9 replies
OK, So I have an Inventory Selection Screen and I have it working for the Server, however if a Client joins it is setup with the Server's Inventory Selections, I would like the Client to have its own chosen Inventory.
Here is example code from my LoadOut function called by StartGame:
%player.incInventory( $Pref::LoadOut::PrimaryWeapon, 1 );
%player.incInventory( $Pref::LoadOut::PrimaryWeapon @ "Ammo", %player.maxInventory( $Pref::LoadOut::PrimaryWeapon @ "Ammo" ) );
Obviously my Inventory GUI is setting "$Pref::LoadOut::PrimaryWeapon" with the selected weapons name
I'm not exactly sure why the Client is being setup with the Server's Inventory, can someone help me to understand how to make each Player have there own Inventory Setup?
Here is example code from my LoadOut function called by StartGame:
%player.incInventory( $Pref::LoadOut::PrimaryWeapon, 1 );
%player.incInventory( $Pref::LoadOut::PrimaryWeapon @ "Ammo", %player.maxInventory( $Pref::LoadOut::PrimaryWeapon @ "Ammo" ) );
Obviously my Inventory GUI is setting "$Pref::LoadOut::PrimaryWeapon" with the selected weapons name
I'm not exactly sure why the Client is being setup with the Server's Inventory, can someone help me to understand how to make each Player have there own Inventory Setup?
#2
Also, I think setInventory and incInventory need o be passed datablocks, not strings. So you'd need to resolve datablock objects out of your stored strings before passing them to the inventory methods.
08/19/2009 (8:52 pm)
I think Ryan's on to it, a $pref is likely to be stored on the client, but you need to do inventory controls on the server. Maybe when a player joins a game, he sends a commandToServer with his inventory information.Also, I think setInventory and incInventory need o be passed datablocks, not strings. So you'd need to resolve datablock objects out of your stored strings before passing them to the inventory methods.
#3
So I'm setting it on the Server/Host and Clients, though I want each individual to have there own selected weaponry (right now Primary, Secondary and Belt)
The problem is I'm not sure what the commandToServer function would look like and where/when it would be passed, as I thought that the %player id would automatically set each clients $Pref::LoadOut::PrimaryWeapon, though I can see why a commandToServer would be needed now.
Also, I'm not sure what you mean by the setInventory and incInventory datablock part.(The mentioned string is the stock MG Starter Kit method)
08/19/2009 (10:38 pm)
Ok, by Server I mean Host, and each Client is recieving the Hosts Setup...So I'm setting it on the Server/Host and Clients, though I want each individual to have there own selected weaponry (right now Primary, Secondary and Belt)
The problem is I'm not sure what the commandToServer function would look like and where/when it would be passed, as I thought that the %player id would automatically set each clients $Pref::LoadOut::PrimaryWeapon, though I can see why a commandToServer would be needed now.
Also, I'm not sure what you mean by the setInventory and incInventory datablock part.(The mentioned string is the stock MG Starter Kit method)
#4
I suggest removing the inventory code from createPlayer and writing a new commandToServer. The command sends the client's weapon preferences, and then the server sets the inventory (like you've got above) for the client's player. Have a look at commands.cs for some examples of server commands. You'd probably want to send the server command from somewhere like GameCOnnection::initialCOntrolSet in serverConnection.cs.
What I was saying about datablocks - here's the default inventory scripts from starter.fps:
08/20/2009 (1:47 am)
Where is the script snippet you posted? I'm guessing it's in the default (according to starter.fps, I've never used the MG starter kit) GameCOnnection::createPlayer. That method is called on the server because the inventory needs to be managed by the server. However, you want the client to tell the server what gear to fill its inventory with.I suggest removing the inventory code from createPlayer and writing a new commandToServer. The command sends the client's weapon preferences, and then the server sets the inventory (like you've got above) for the client's player. Have a look at commands.cs for some examples of server commands. You'd probably want to send the server command from somewhere like GameCOnnection::initialCOntrolSet in serverConnection.cs.
What I was saying about datablocks - here's the default inventory scripts from starter.fps:
// Starting equipment %player.setInventory(Crossbow,1); %player.setInventory(CrossbowAmmo,10);Crossbow and CrossbowAmmo have no "punctuation like this" so they're the names of datablocks, not strings. I assumed the rest of the inventory system would work the same way, but if it works differently in the MG starter kit then never mind.
#5
There are 2 places that a connection to the server is made. One is in the joinServerGui.gui and the other is in the startMissionGui.gui. In these files you will find a line like the following:
%conn.setConnectArgs($pref::Player::Name);
Add the selected weapon to this call:
%conn.setConnectArgs($pref::Player::Name,"Your weapon name here");
This is passed to the function on the server GameConnection::onConnect in the clientConnection.cs file.You will need to add a parameter for your weapon name in the call. Now below this you will see a bunch of stuff being set on the %client variable, like gender, armor, ect. Add an entry for your weapon to this. This then call client.loadMission() which is in missionDownload.cs. This makes a call to %this.onClientEnterGame() which is in server/scripts/game.cs. This now makes a call to GameConnection::spawnPlayer in the same file which then calls GameConnection::createPlayer. This is where your inventory is setup, you should be able to access the variable you set above on the %client from the %this variable. So if you set it on the %client as %client.PrimaryWeapon you should be able to access it here as %this.PrimaryWeapon. I hope I didn't lose you in all this, but let me know if you have any questions.
08/20/2009 (2:12 am)
This is based on stock TGE 1.5.2:There are 2 places that a connection to the server is made. One is in the joinServerGui.gui and the other is in the startMissionGui.gui. In these files you will find a line like the following:
%conn.setConnectArgs($pref::Player::Name);
Add the selected weapon to this call:
%conn.setConnectArgs($pref::Player::Name,"Your weapon name here");
This is passed to the function on the server GameConnection::onConnect in the clientConnection.cs file.You will need to add a parameter for your weapon name in the call. Now below this you will see a bunch of stuff being set on the %client variable, like gender, armor, ect. Add an entry for your weapon to this. This then call client.loadMission() which is in missionDownload.cs. This makes a call to %this.onClientEnterGame() which is in server/scripts/game.cs. This now makes a call to GameConnection::spawnPlayer in the same file which then calls GameConnection::createPlayer. This is where your inventory is setup, you should be able to access the variable you set above on the %client from the %this variable. So if you set it on the %client as %client.PrimaryWeapon you should be able to access it here as %this.PrimaryWeapon. I hope I didn't lose you in all this, but let me know if you have any questions.
#6
You could do something like what Ryan outlines and use a GuiPopUpMenuCtrl in your joinServerGUI to populate your list and send that information to CommonGame::loadOut()
08/20/2009 (2:59 am)
Just to note that the MG Starter Kit uses a custom inventory solution.You could do something like what Ryan outlines and use a GuiPopUpMenuCtrl in your joinServerGUI to populate your list and send that information to CommonGame::loadOut()
#7
Oh, and the punctuation is because of the way I'm passing the Weapon Name in the $Prefs variable as I'm using the variable to decide the Directory name used for displaying the weapon in the GuiObjectView as well.(This was the easiest way I could figure out)
And, Why the MG Starter Kit is only using incInventory instead of setInventory I believe is because of the way the "SMS" Inventory is executed???
@Ryan, LOL, ya you lost me, but with some time of playing around with the scripts I'm sure the examples given will work for what I need, I just wasn't sure how to pass Client Info to the Server correctly and I believe I have the needed information to do so.
@Michael, Yeah, The "SMS" Inventory that the MG Starter Kit uses has made for a fun time decoding what I'm trying to accomplish, however I have managed so far, and I've actually got an InventoryLoadOutGui that both Server/Host and Client can set while in the MainMenuGui that decide the Primary, Secondary and Belt Item for each player.
@All, Thanks very much for the help, though I'm using the MG Starter Kit and it is differant, the help you all have supllied is very much relevant and would not be to hard to translate over to whats needed, Thanks Again!
08/20/2009 (11:17 am)
@Daniel, The code snippet is called from CommonGame::CreatePlayer(similiar to the Connection::CreatePlayer in stock tge).Oh, and the punctuation is because of the way I'm passing the Weapon Name in the $Prefs variable as I'm using the variable to decide the Directory name used for displaying the weapon in the GuiObjectView as well.(This was the easiest way I could figure out)
And, Why the MG Starter Kit is only using incInventory instead of setInventory I believe is because of the way the "SMS" Inventory is executed???
@Ryan, LOL, ya you lost me, but with some time of playing around with the scripts I'm sure the examples given will work for what I need, I just wasn't sure how to pass Client Info to the Server correctly and I believe I have the needed information to do so.
@Michael, Yeah, The "SMS" Inventory that the MG Starter Kit uses has made for a fun time decoding what I'm trying to accomplish, however I have managed so far, and I've actually got an InventoryLoadOutGui that both Server/Host and Client can set while in the MainMenuGui that decide the Primary, Secondary and Belt Item for each player.
@All, Thanks very much for the help, though I'm using the MG Starter Kit and it is differant, the help you all have supllied is very much relevant and would not be to hard to translate over to whats needed, Thanks Again!
#8
Thank you all so much every piece of info supplied was extremely helpful and I would not have been able to do it without your support.
Now I'm going to add the option of making sure that everyone starts with the same weapon only if the Server/Host has $Pref::Server::PresetWeapons = 1, as was happening before I got this working.
This has helped me understand a little more the concept of Server/Client architecture.
08/20/2009 (12:37 pm)
Success!! :)Thank you all so much every piece of info supplied was extremely helpful and I would not have been able to do it without your support.
Now I'm going to add the option of making sure that everyone starts with the same weapon only if the Server/Host has $Pref::Server::PresetWeapons = 1, as was happening before I got this working.
This has helped me understand a little more the concept of Server/Client architecture.
#9
08/20/2009 (7:59 pm)
Glad you worked it out!
Torque Owner Ryan Mick
Red Witch Entertainment