Ammo count and such?
by Mike "Tango Whiskey" Lawrence · in Torque Game Engine · 09/05/2005 (10:04 pm) · 9 replies
After spending the past 1.5 hours looking through the .cs files and searching GG, I'm stumped.
How does the game know when the crossbow is out of ammo? And how does it tell the weapon not to fire?
How does the game know when the crossbow is out of ammo? And how does it tell the weapon not to fire?
About the author
#2
So, for example, when/where is the stateTransitionONTimout[6] state set? And what the heck are these variables anyway? Can I use them as: crossbow.statTransitionOnTimeout[6] = um, what? or crossbow."NoAmmo" = .... which makes even less sense. What are these anyway? An array?
So many questions.
09/06/2005 (8:33 am)
Yeah, saw all that. Where are these states changed? Again, looking through the script files I see nothing that references weapon states. In fact, this is what started my quest. I wanted to set the no ammo flag when my player entered a trigger. So, for example, when/where is the stateTransitionONTimout[6] state set? And what the heck are these variables anyway? Can I use them as: crossbow.statTransitionOnTimeout[6] = um, what? or crossbow."NoAmmo" = .... which makes even less sense. What are these anyway? An array?
So many questions.
#3
Don't edit datablocks on the fly; they aren't set up to be updated properly and the results will be unpredictable.
09/06/2005 (10:56 pm)
All the weapon state stuff is implemented in C++, specifically, in game/shapeImage.cc, if memory serves.Don't edit datablocks on the fly; they aren't set up to be updated properly and the results will be unpredictable.
#4
ShapeBase.weaponstate[x] = something
-OR-
ShapeBase.weaponstate=something[x]
My pseudocode is not exactly precise, but the basic concept is where are these weaponstates actually changed as the game progresses?
09/07/2005 (5:00 pm)
Yes, ShapeBase has the definitions for the various weapon state arrays. The question is, where are these manipulated? For example, when I run out of ammo, I'm expecting some code somewhere to say:ShapeBase.weaponstate[x] = something
-OR-
ShapeBase.weaponstate=something[x]
My pseudocode is not exactly precise, but the basic concept is where are these weaponstates actually changed as the game progresses?
#5
Like the crossbow "onFire" funtion has something like
%obj.decInventory(%this.ammo,1);
Where the ammo is decreased by one.
09/07/2005 (9:59 pm)
In the weapon files themselves right (crossbow.cs?)Like the crossbow "onFire" funtion has something like
%obj.decInventory(%this.ammo,1);
Where the ammo is decreased by one.
#6
function ShapeBase::decInventory(%this,%data,%amount)
{
// Decrement the inventory by the given amount. The return value
// is the amount actually removed.
%total = %this.inv[%data.getName()];
if (%total > 0) {
if (%total < %amount)
%amount = %total;
%this.setInventory(%data,%total - %amount);
return %amount;
}
return 0;
--------------------- Which then takes us to:
function ShapeBase::setInventory(%this,%data,%value)
{
// Set the inventory amount for this datablock and invoke
// inventory callbacks. All changes to inventory go through this
// single method.
// Impose inventory limits
if (%value < 0)
%value = 0;
else {
%max = %this.maxInventory(%data);
if (%value > %max)
%value = %max;
}
// Set the value and invoke object callbacks
%name = %data.getName();
if (%this.inv[%name] != %value)
{
%this.inv[%name] = %value;
%data.onInventory(%this,%value);
%this.getDataBlock().onInventory(%data,%value);
}
return %value;
}
This looks like a dead end to me when it comes to weapon states. (This is as far as I got when I decided to post my question.)
I'm expecting something somewhere to refer to the ShapeBaseImageData datablock weapon state arrays. So far, it hasn't shown up.
09/08/2005 (9:43 am)
Which takes us to this in inventory.cs. Of interest here is the setinventory callfunction ShapeBase::decInventory(%this,%data,%amount)
{
// Decrement the inventory by the given amount. The return value
// is the amount actually removed.
%total = %this.inv[%data.getName()];
if (%total > 0) {
if (%total < %amount)
%amount = %total;
%this.setInventory(%data,%total - %amount);
return %amount;
}
return 0;
--------------------- Which then takes us to:
function ShapeBase::setInventory(%this,%data,%value)
{
// Set the inventory amount for this datablock and invoke
// inventory callbacks. All changes to inventory go through this
// single method.
// Impose inventory limits
if (%value < 0)
%value = 0;
else {
%max = %this.maxInventory(%data);
if (%value > %max)
%value = %max;
}
// Set the value and invoke object callbacks
%name = %data.getName();
if (%this.inv[%name] != %value)
{
%this.inv[%name] = %value;
%data.onInventory(%this,%value);
%this.getDataBlock().onInventory(%data,%value);
}
return %value;
}
This looks like a dead end to me when it comes to weapon states. (This is as far as I got when I decided to post my question.)
I'm expecting something somewhere to refer to the ShapeBaseImageData datablock weapon state arrays. So far, it hasn't shown up.
#7
09/08/2005 (9:49 am)
Quote:All the weapon state stuff is implemented in C++, specifically, in game/shapeImage.cc, if memory serves.
#8
I think is because I am calling a function that updates the label inside the decInventory inside the inventory.cs file that is on the server side of the code.
Now my question is this one: How do I know which one is the client that the ammo count is getting updated for? And how do I update a labelTextCtrl in the HUD only for this client?
Thanks
Juanma
05/07/2006 (1:25 pm)
I was looking at this thread because I wanted to show a label on the screen that tells the player what is the ammo count. It works great until the bots starts shooting, the counter gets all crazy. I think is because I am calling a function that updates the label inside the decInventory inside the inventory.cs file that is on the server side of the code.
Now my question is this one: How do I know which one is the client that the ammo count is getting updated for? And how do I update a labelTextCtrl in the HUD only for this client?
Thanks
Juanma
#9
In onFire for your weapon, do a commandToClient to %obj.client (or somesuch) and send the variable for how much ammo is left.
05/07/2006 (1:43 pm)
Juan, you should take a look at how commandToServer/Client works, and how storing of local variables work. To me it sounds like you're using globals. In onFire for your weapon, do a commandToClient to %obj.client (or somesuch) and send the variable for how much ammo is left.
Torque Owner Stephane Savioz
datablock ShapeBaseImageData(CrossbowImage)
// No ammo dry fire
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateSound[6] = CrossbowFireEmptySound;