Game Development Community

FPS Inventory System

by Ronald J Nelson · in Torque Game Engine · 05/17/2006 (3:25 pm) · 6 replies

Well I am finally getting around to this point and am in need of some assistance.

What I am looking to do is have a weapon inventory system that has certain slots for certain weapon types (such as knives, handguns, rifles)and others for items like health kits. I want to be able to make the wepon type slots be able to drop a weapon and pick up a different weapon and load it into that slot. The system I see in place currently forces you to have a preload of weapons that are enabled as you get them.

Has anyone managed to come up with something similar to what I need? If so would you be willing to share your work?

#1
05/18/2006 (4:57 am)
Hi Ron,

I stumbled across a C++ tutorial on the SDK home page for modifying the inventory system; it's at this location.

I haven't tried this personally: I just got TGE two days ago, and my brain is still alternating between "wow" and "what have I gotten myself into". =)

Hope that helps!

-- John
#2
05/19/2006 (2:36 am)
Yeah been there and it really didn't work for me. I believe I am missing something somewhere because I can't get any of the systems I have tried to work. I can pick up items no problem, but I can never use the inventory to switch between them.

I would really like to use this one but for some reason something isn't working for me quite right.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3467

Any suggestions would be really helpful and any help would be appreciated.
#3
05/19/2006 (6:22 pm)
OK I really could use some help on this one I think I found the issue with the code I am using from that resource but I have no idea what it is I did wrong.
#4
05/20/2006 (12:41 am)
OK found out my mistake and feel pretty dumb for not delting one of the functions that was supposed to be replaced.

Has anyone come up with a system that allows you to specifically pick a certain inventory slot you put an item into?

For example:

Slots
1.Health
2.knife
3.handgun
4.mainweapon
5.grenades

If you pick up a mainweapon it puts it into the main weapon slot. If there is already one there then you will have to throw the weapon to get a different one however if it is the same weapon you can increment the ammo supply.

Help please.
#5
05/20/2006 (1:27 am)
I have a system pretty close to that. I store a reference to the image (or two in my case) in an array on the player object, and call functions that mount images based off these slots. It's not really that hard to get, I've ripped out most of the original inventory system and only use the inc/dec inventory functions (and even those are modified). If you look over the existing and other inventory systems, it's all in script and not that hard to do your own. I think it's a pretty good way to learn to write logical systems in script.

You'll just want to add some identifier variables to in your weapon datablocks to check what "type" they are, and then decide what to do with them when they're picked up from their item version. You can see my code, but it's not something you can use directly for your purposes (I mean really, it wouldn't work). I don't need to worry about picking up weapons in my game, but it has a basic "slot" setup. You list your skills as intermediate programmer and skilled in script, so I'm just assuming you can write something like this on your own.

function Player::setLoadout(%player, %loadout, %primary, %secondary){
   //Equip base weapons
   //Are we even using this?
   //%player.setInventory(%primary @ "Item",1);
   //%player.setInventory(%secondary @ "Item",1);
   
   //If guns, add ammo
   %primaryImage = %primary @ "Image";
   if(%primaryImage.weaponType $= "Gun"){
      %player.setInventory(%primaryImage.clip,%primaryImage.clipMax);
      %player.setInventory(%primaryImage.ammoType,%primaryImage.ammoMax/2);
   }
   
   %secondaryImage = %secondary @ "Image";
   if(%secondaryImage.weaponType $= "Gun"){
         %player.setInventory(%secondaryImage.clip,%secondaryImage.clipMax);
         %player.setInventory(%secondaryImage.ammoType,%secondaryImage.ammoMax/2);         
   }
   
   %player.loadout[%loadout] = %primaryImage SPC %secondaryImage;
   
   //We're assuming loadouts are set in order, coz' they should be
   %player.totalLoadouts = %loadout;
}

function Player::mountLoadout(%player, %loadout){
   
   %primaryImage = getWord(%player.loadout[%loadout], 0);
   %secondaryImage = getWord(%player.loadout[%loadout], 1);
   
   //Force remount so animations sync
   %player.unmountImage(%player.iSPrimary);
   %player.unmountImage(%player.iSSecondary);
   
   //OMG HACK!
   //This should be in an onUnmount callback or something
   NoSecondGunImage::onUnZoom(%secondaryImage, %player, %player.iSSecondary);   
   
   %player.mountImage(%primaryImage,%player.iSPrimary);
   %player.mountImage(%secondaryImage,%player.iSSecondary);
     
   %player.currentLoadout = %loadout;
}

function serverCmdMountLoadout(%client, %loadout){
%player = %client.player; 
   if(isObject(%player) && %player.isValidLoadout(%loadout) != 0 && %player.canChangeLoadout() != 0)
      %player.mountLoadout(%loadout);
}

function serverCmdUpLoadout(%client){
%player = %client.player;   
      
   if(isObject(%player) && %player.canChangeLoadout() != 0){
      
      %loadout = %player.isValidLoadout(%player.currentLoadout + 1);      

      if(%loadout != 0)
         %player.mountLoadout(%loadout);
      else
         %player.mountLoadout(1);
   }
   
}

function serverCmdDownLoadout(%client){
%player = %client.player;   
      
   if(isObject(%player) && %player.canChangeLoadout() != 0){
      
      %loadout = %player.isValidLoadout(%player.currentLoadout - 1);
      
      if(%loadout != 0)            
         %player.mountLoadout(%loadout);
      else
         %player.mountLoadout(%player.totalLoadouts);
   }
   
}

//Manual check to see if it's legal to change mount slots
function Player::canChangeLoadout(%player){
   
   if(%player.canChangeImage(%player.iSPrimary) == 0 ||
      %player.canChangeImage(%player.iSSecondary) == 0)
      return false;
      
   return true;
}

//See if a slot contains a valid loadout
function Player::isValidLoadout(%player, %loadout){
   %isValid = %player.loadout[%loadout];
   
   if(%isValid !$= "")   
   return %loadout;
   else
   return false;
}
#6
05/21/2006 (4:11 pm)
Heh I managed to come to these conclusions on my own then I see Paul could have saved me a head ache or two. Thanks Paul.