Inventory: magazine + rounds
by Vincent D · in Torque Game Engine · 01/09/2008 (12:51 pm) · 9 replies
Hello,
For some time now Ive been thinking of how to achieve a system like this:
Each magazine holds a specific amount of rounds. When the players reloads he changes the magazine but if it's not empty he will keep the magazine. So all the magazine's need to keep track of the rounds left.
Optionaly certain guns can use the same magazine type, so I'll need to keep track which magazine is in which gun. Lastly the number of magazines a players carries need to be dynamic.
Any suggestions of how to do this in torque? The problem is that the current scripted inventory system only stores the number of objects in the players inventory.
Thanks in advance, Vincent
For some time now Ive been thinking of how to achieve a system like this:
Each magazine holds a specific amount of rounds. When the players reloads he changes the magazine but if it's not empty he will keep the magazine. So all the magazine's need to keep track of the rounds left.
Optionaly certain guns can use the same magazine type, so I'll need to keep track which magazine is in which gun. Lastly the number of magazines a players carries need to be dynamic.
Any suggestions of how to do this in torque? The problem is that the current scripted inventory system only stores the number of objects in the players inventory.
Thanks in advance, Vincent
#2
01/09/2008 (1:00 pm)
I've used that in some previous projects, but what I need now is that for example I have in one magazine 14 rounds left, in another 24 while my current weapon uses a magazine which is full.
#3
Let's say your avatar is using the good ol' inconspicuous Desert Eagle .50 AE. You have designed the game to use the basic 7 round fifty cal magazine found at your local hardware. If you go the path of Rainbow Six, all you have left to decide is how many clips you will allow the player to have. For our firearm example, we'll say the player can carry 1 main weapon, 1 side arm, 4 grenades, 4 main weapon magazines, and 3 secondary weapon magazines. We'll skip all the stuff you probably already know and get straight to the pseudo code for the reload system using the Deagle as an example:
The reload system Scott posted is a great starting point. After that, you just need a simple array and some variables to keep track of what clip you are on.
// Note that this code is highly unoptimized and mostly just pseudo code to get you going. In fact, you can probably place some of these inside your weapon or player blocks
So, that's some rough code. I'm tired, so I might have made a mistake. Post a reply if you get something working or need more help.
*EDIT* - Well bollocks. I just re-read your post and saw that you need your clip count to be dynamic. That throws a wrench in the pie, doesn't it?
The next thing to do is create an inventory slot for the clips and use that as a counter instead. See what i mean?
01/09/2008 (7:33 pm)
So, you are looking for a realistic ammo system similar to what you might find in a Rainbow Six game? Heck, that's easy: in fact, you can do it completely in script.Let's say your avatar is using the good ol' inconspicuous Desert Eagle .50 AE. You have designed the game to use the basic 7 round fifty cal magazine found at your local hardware. If you go the path of Rainbow Six, all you have left to decide is how many clips you will allow the player to have. For our firearm example, we'll say the player can carry 1 main weapon, 1 side arm, 4 grenades, 4 main weapon magazines, and 3 secondary weapon magazines. We'll skip all the stuff you probably already know and get straight to the pseudo code for the reload system using the Deagle as an example:
The reload system Scott posted is a great starting point. After that, you just need a simple array and some variables to keep track of what clip you are on.
// Note that this code is highly unoptimized and mostly just pseudo code to get you going. In fact, you can probably place some of these inside your weapon or player blocks
// Desert Eagle clip system
$Clip_Count = 4;
$Clip_Capacity = 7;
$Current_Clip = 0;
$Curr_Clip_Empty = false;
for(%i = 0; %i < $Num_Clips; %i++)
$deagleclips[%i] =$Clip_Capacity;
maxInv[Secondary_Ammo] = Clip_Capacity; // Give the player only one clip at a time
function DeagleImage::ReloadAmmoClip(%this, %obj)
{
// Just checking to see if the clip we are removing has ammo left over
if (%obj.getInventory(%this.ammo) > 0)
{
// We have some rounds left, so store the count in the current array index
$deagleclips[$Current_Clip] = %this.ammo;
// Move to the next clip in the inventory
$Current_Clip++;
// Start over in the queue of clips to use
if($Current_Clip >= $Num_Clips)
$Current_Clip = 0;
// Set the player's ammo to amount of rounds in the new clip
%obj.setInventory(Secondary_Ammo, $deagleclips[$Current_Clip]);
}
}So, that's some rough code. I'm tired, so I might have made a mistake. Post a reply if you get something working or need more help.
*EDIT* - Well bollocks. I just re-read your post and saw that you need your clip count to be dynamic. That throws a wrench in the pie, doesn't it?
The next thing to do is create an inventory slot for the clips and use that as a counter instead. See what i mean?
#4
I also think this way is kind of a hack in the current inventory system.
I'm willing to write a new inventory system if that's what it takes to make something like this work. But I have no clue how to do a system where objects, or specific object data, are stored in the inventory. I think it would be fairly easy to create a scriptObject for each object in the inventory but I guess that would'nt be very efficient (can anyone confirm that?).
Another thing I thought of is giving the player a max amount of slots where stuff can be stored like
More suggestions are welcome, and thanks for your responses so far
01/10/2008 (4:54 am)
I've thought about the way you suggest doing this, but I think the problem was intergrating this in the current inventory system. If I remove a specific magazine it will create a 'gap' in the magazine queue.I also think this way is kind of a hack in the current inventory system.
I'm willing to write a new inventory system if that's what it takes to make something like this work. But I have no clue how to do a system where objects, or specific object data, are stored in the inventory. I think it would be fairly easy to create a scriptObject for each object in the inventory but I guess that would'nt be very efficient (can anyone confirm that?).
Another thing I thought of is giving the player a max amount of slots where stuff can be stored like
slot[0] = DeagleMagazine TAB [number of rounds] slot[1] = Medpack TAB [medicines left in pack]
More suggestions are welcome, and thanks for your responses so far
#5
Since ammunition and magazines will play an integral part in our game, we will actually be creating a new object in C++ so that it works with our inventory system. Our player must be able to pick up a magazine, use it, store it, drop it, and trade it with other entities. With that kind of functionality, we believe it deserves its own console object.
With its own object and functionality, you can add it to the existing inventory system easy sleazy.
01/10/2008 (5:36 am)
You're right Vincent. The code is a bit of a hack as it is presented, but once you start integrating the variables into the Player and WeaponImage datablocks, it will definitely clean up.Since ammunition and magazines will play an integral part in our game, we will actually be creating a new object in C++ so that it works with our inventory system. Our player must be able to pick up a magazine, use it, store it, drop it, and trade it with other entities. With that kind of functionality, we believe it deserves its own console object.
With its own object and functionality, you can add it to the existing inventory system easy sleazy.
#6
01/10/2008 (10:37 am)
Michael: That's exactly what I plan on doing, except I'm not using the inventory system.
#7
01/11/2008 (1:42 am)
Michael, you say integrating the variables into the player and weaponImage datablocks. That means it can't be used in multiplayer.
#8
01/11/2008 (5:10 am)
Sorry, should have said Player object, not player datablock.
#9
The playerObject has 2 arrays; magazines and magRounds. The first one stores the magazine type and the second one the rounds left in it. These 2 should always be used together.
I'm using an slot based system for my weapons. When I add an weapon to the inventory I also give it a slot number which is used for switching weapons. So when I press 1, 2 , 3 the weapon in the corresponding slot will be selected. This is also stored in the playerObject.
The change I made in this slot based weapon system is that after the weapon data, I now store the rounds left in the weapon.
Then in the reload function ( which I called 'changeMagazine') I put any rounds still left in the old magazine at the end of the magazine array and select the first magazine from that array and add it to the weaponSlot array.
This all may sound a bit confusing but it may look like this when playing:
I've already implented this and it works as it should work.
01/13/2008 (8:24 am)
The past few days I gave this another few thoughts and I came up with the following.The playerObject has 2 arrays; magazines and magRounds. The first one stores the magazine type and the second one the rounds left in it. These 2 should always be used together.
I'm using an slot based system for my weapons. When I add an weapon to the inventory I also give it a slot number which is used for switching weapons. So when I press 1, 2 , 3 the weapon in the corresponding slot will be selected. This is also stored in the playerObject.
The change I made in this slot based weapon system is that after the weapon data, I now store the rounds left in the weapon.
Then in the reload function ( which I called 'changeMagazine') I put any rounds still left in the old magazine at the end of the magazine array and select the first magazine from that array and add it to the weaponSlot array.
This all may sound a bit confusing but it may look like this when playing:
PlayerObject.magazines = DeagleMag TAB DeagleMag TAB M16Mag PlayerObject.magROunds = 7 TAB 4 TAB 4 // so in first 'field' is a DeagleMag with 7 rounds weaponSlot[1] = M16 TAB 18 // weapon TAB rounds in weapon
I've already implented this and it works as it should work.
Associate Scott Burns
GG Alumni