Create a simple display in HUD to show keys or other inventory
by Jesse P · 08/01/2008 (10:26 am) · 8 comments
Open starter.fps/client/ui/playGui.gui
At the top there you should see GameTSCtrl(PlayGui) block of code. After that section of code enter the following code that is in bold:
Next open your starter.fps/client/scripts/playGui.cs
Add the following code to the very end of the script:
Now open the script that you define your keys in, for example mine is defined in the same script that I have my door code which is named door.cs in the server/scripts directory, but yours will be different.
Wherever your item's onCollision is written enter the code that is in bold below.
Next open starter.fps/server/scripts/player.cs
enter the following inside the function Armor::onAdd(%this,%obj) at the end
That's it if you want to always keep the display of the key on the screen during a level since a key is a reusable item, however if you ever want to make the graphic disappear in the HUD once used, for example if it is an item that is not reusable, simply add another function in the playGui.cs such as the following example:
Then place the command clientCmdMyItemUsed(); wherever you define your code for what to do upon use of the item.
I hope this helps, it is my first resource.
At the top there you should see GameTSCtrl(PlayGui) block of code. After that section of code enter the following code that is in bold:
//--- OBJECT WRITE BEGIN ---
new GameTSCtrl(PlayGui) {
canSaveDynamicFields = "1";
Profile = "GuiContentProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "0 0";
Extent = "640 480";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
hovertime = "1000";
applyFilterToChildren = "1";
cameraZRot = "0";
forceFOV = "0";
noCursor = "1";
helpTag = "0";
[b]
new GuiBitmapCtrl(KeyBlueDisplay) {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "top";
position = "670 420"; // Whatever location you want it to appear in the display
Extent = "16 32";
MinExtent = "8 8";
canSave = "1";
Visible = "0"; // Initially sets it to invisible until you find the key
hovertime = "1000";
bitmap = "./keyblue.png"; // Whatever your key thumnail graphic is
wrap = "0";
};
[/b]Next open your starter.fps/client/scripts/playGui.cs
Add the following code to the very end of the script:
function clientCmdKeyBlue()
{
KeyBlueDisplay.visible = 1;
}Now open the script that you define your keys in, for example mine is defined in the same script that I have my door code which is named door.cs in the server/scripts directory, but yours will be different.
Wherever your item's onCollision is written enter the code that is in bold below.
function BlueKey::onCollision(%this,%obj)
{
[b]clientCmdKeyBlue(); // Calls the function which displays the blue key in HUD.[/b]
...
}Next open starter.fps/server/scripts/player.cs
enter the following inside the function Armor::onAdd(%this,%obj) at the end
[b]
if(%obj.getClassName() !$= "Player")
return; // Only for player, don't reset inventory if a bot is spawned
else
{
KeyBlueDisplay.visible = 0;
}
[/b]This makes it so at the start of each level the inventory display is reset, that way it doesn't show "phantom items" that you don't actually have. Make sure you enter a youritem.visible=0 line for every item you have displayed in your inventory HUDThat's it if you want to always keep the display of the key on the screen during a level since a key is a reusable item, however if you ever want to make the graphic disappear in the HUD once used, for example if it is an item that is not reusable, simply add another function in the playGui.cs such as the following example:
function clientCmdMyItemUsed()
{
MyItemDisplay.visible = 0;
}Then place the command clientCmdMyItemUsed(); wherever you define your code for what to do upon use of the item.
I hope this helps, it is my first resource.
#2
08/01/2008 (10:03 pm)
Nice work Jesse... :-)
#3
08/02/2008 (12:49 pm)
@Tom that's a good idea, what I later did in mine was add it into a grid and gave it a background with little boxes and such so it looks cool, each key and item has it's own box that it will appear in when found
#6
08/03/2008 (9:09 pm)
hello if i using crowbow what i need to change this function clientCmdKeyBlue() to?
#7
and inside that function you would add your clientCmd.... command
for example if you were to change the name of the clientCmdKeyBlue() example in this resource to clientCmdUsingCrossbow()
then added to the end of the crossbow.cs it would look like this:
Now I used a different test with a different weapon but it should work with the crossbow, as for changing the image when you switch weapons I imagine you could have each weapon set all other weapons visibility to 0 or something. Hope this helps
08/04/2008 (5:26 pm)
@Charin I played around with it and am pretty sure I figured it out, you can create the following new function in the crossbow.cs function CrossbowImage::onLoad(%this, %obj, %slot)
{
}and inside that function you would add your clientCmd.... command
for example if you were to change the name of the clientCmdKeyBlue() example in this resource to clientCmdUsingCrossbow()
then added to the end of the crossbow.cs it would look like this:
function CrossbowImage::onLoad(%this, %obj, %slot)
{
clientCmdUsingCrossbow();
}Now I used a different test with a different weapon but it should work with the crossbow, as for changing the image when you switch weapons I imagine you could have each weapon set all other weapons visibility to 0 or something. Hope this helps
#8
08/04/2008 (5:27 pm)
@Tom that looks cool!

Torque 3D Owner Tom Feni
probably add it to the picture so it will show up when they come up, but I also need to make it so they pop up in as I get them, so if there is only 3 keys out 6 in the level I can have it align just the three. Kind of like slots.. Maybe the inventory gui resource can help.. :)
TomFeni