Game Development Community

Question on control im writing for weapon inventory

by Don Cramer · in Torque Game Engine · 01/30/2005 (9:14 pm) · 4 replies

I am still new to torque but could not resist writing some sort of code for the engine. I did not see a weapon hud i liked so made my on. GuiWeaponHud.. See screenshot below for what im working on (botom left of screenshot)

www.donstoys.com/guiweaponhud.jpg

GuiWeaponHud is subclassed from a GuiBitmapCtrl.

The control consists of a image/frame (the black border/lines in the screenshot) and images of the weapons in inventory are displayed (2 images per weapon, the image displayed depends on if we have it or not) and the ammount of ammo in inventory.

I update the weaponHud through script inside the weapon.cs inside the oninventory and onmount functions. Works great except for one issue which i will explain.

I setup the hud in game.cs inside the function:

function GameConnection::createPlayer(%this, %spawnPoint)

the weaponHud is reset (clears out ammo and inventory amount)..... then I add a crossbow and 10 ammo to the player...

when the game starts to run my hud shows 0 ammo and no weapons. But when i fire, pickup ammo or another weapon the hud works fine. If I kill myself (ctrl-k) when i re-enter the mission the hud does reset and it does have the proper ammo/weapon in the hud.

Adding some echo's so i know when my hud functions are called I can see that when a mission is first started, I can see my hud calls to set weapon and ammo inventory HOWEVER these calls are made BEFORE the weaponHud is even finished initializing.

In my weaponHud when the path to images is loaded the hud tries to load all weapon images up to MAX_WEAPONS (which i have defined in the source) and I can see missing texture messages for weapon slots I do not use (yet). These messages appear in the log AFTER my calls to initialize the weaponHud.

I solved this issue by scheduling the calls to init the control 1 second after the player is created and this works fine, the hud is initialized properly.

My question is, what funtion if any is called once a mission is completely loaded or the playgui is loaded and the player is given control. I tried a few different places in game.cs and others with no luck.

Also. Im using torque 1.3 (not the cvs head, the downloadable version from when i bought torque). I am using the default scripted inventory that comes with torque. Is there a way to access the inventory items from inside of C. Perhaps if this is possible I can get rid of the scripting required to update the control and pull the ammo/weapon info directly (like guihealtbarhud does).

Thanks for any and all responses..

I will release this as a resource if anyone is interested.

#1
01/30/2005 (9:40 pm)
I've run into a similar issue, and wound up setting up an ack system from the client to the server requesting an initial setting for the dataset you need.

What's basically happening (or, at least what was happening with me) is that the client was setting up it's dataset and display before the server had any updates available, and therefore didn't change the initial values until a change had been made. You can set up a request for a dataset initialization sometime during the mission startup similar to how the mission startup ack's work, or possibly catch an instant on the server after player spawn and send a one-time initialization of the ammo count.
#2
01/31/2005 (12:11 pm)
Try GameConnection::OnClientEnterGame()

a script function in game.cs that is called once a client has loaded the map and has just entered the game
#3
01/31/2005 (1:55 pm)
OnClientEnterGame calls spawnplayer which then calls createPlayer, which is where I am running my init routines now. So that wont work :)

Thanks anyways!
#4
01/31/2005 (2:52 pm)
I think you need to make a messageHandler. . .like how the clocks get synced up.