I'll do my best to answer this since no one has yet. This definitely works, but... Others would likely do this much more efficiently than I so... maybe wait for their response? Anyway, here's how I would do it in my hacky, poor-coding sort of way:
- Create an object called "ammunition". Make sure it is in the players inventory AND make sure the box next to 'can be dropped' (on the inventory tab) is NOT ticked. If the player doesn't start the game with ammo or a weapon, you can also tick it as invisible to start the game and run a script to make it visible once weapon and ammo are found.
- Click on the attributes tab of the ammunition object.
- Click 'Add' next to 'Attributes'. Name it something like 'AmmoCount'
- Select integer attribute and set it to 0 (zero).
- Create ammo objects. In my sample, I made a 'twenty pack ammo' and a 'fifty pack ammo'.
- On the inventory tab for those objects, I clicked 'run a script' under the take section.
- Select 'Set variable or attribute' from the options.
- In the first box, type 'ammunition.AmmoCount' and in the second box, type 'ammunition.AmmoCount + 20'. The plus 20 is for the twenty pack. For the fifty pack, I changed it to 50. If you are doing one ammo per pick up, it would be + 1.
- For ME, I also added a script here to remove an object. I removed the ammo pack that I picked up because it prevents the player from dropping it and picking it up over and over again, racking up their ammo count.
- Make a gun object.
- Click on verbs tab for the gun object. Type in 'fire'.
- Choose Run a script.
- Select an 'If' script.
- Click on the 'expression' box and select 'object attribute equals'.
- In the object box, select object. In the box just to the right of that, type 'ammunition' and in the attribute box type 'AmmoCount'. In the box to the right of the equal sign (=), type in '0'
- In the Then part of this If script, run a print message script and type a message like "You pull the trigger, but nothing happens! You're empty!"
- In the else part of this If script, add a print message script and type a message like "You fire the gun." Also add a Set a variable or attribute script and, in the first box, type in 'ammunition.AmmoCount'. In the second box, select expression, and in the third box, type in 'ammunition.AmmoCount - 1'
- Go back to your ammunition object and choose to run a script under the "look at" section under the Set Up tab.
- Select the print a message script and make sure 'expression' is in the first box.
- In the second box next to expression, type the following
"You have " + ammunition.AmmoCount + " ammo remaining."
exactly as is. Or, change the "You have " or the " ammo remaining." parts to whatever you want.
Bingo. Done. You can do the same thing for your food items.
I don't think I missed any steps.
If you use this method and need help, please ask.
EDIT: If you fire the gun at certain things, like you would likely do, you can copy paste the code for the fire verb, on the thing you want it fired at. For example... if there is a zombie you want to shoot, maybe add a 'shoot' verb on the zombie and run scripts for killing or wounding the zombie IF the player is carrying the gun/weapon.