INVENTORY THEORIES  v1-01-2003  Release 1  © RTCM Reaper_Man

/!\ Attention: These FAQ's where written before the development of EDuke, many limits do not apply anymore.

These CON FAQs was written because I believe that there is no one place where CON information can be found - from the simplest ideas to the most complex effects. After the fall of Dukeworld and 3D Portal, a web-edition of the CON FAQ seems to have been lost, and that leaves Duke RTCM as the only other source of CON information. Though they do have information on CONs and how to edit them, I don't believe that this information is easily understood by the newest of newbie's.

The information here is for those newbie's, moderate programmers', and the experts alike. Know one knows everything there is to know about CONs, or any computer programming language for that matter. Everyone has their own style and their own ideas, and that leads to the limitless possibilities.

These FAQs are not a solid piece of work - it is an ever changing, ever evolving compilation of the DukeC programming language - the unofficial name of the CON language. If any new information is brought to my attention, or something that needs to be fixed, I will post updates. You can reach me at http://www.msleeper.com/ as that is my personal site/blog.

Enjoy!

Introduction | Description | How It Works | Final Notes

Introduction

You've probably heard some of the CON "gurus" in the community talk for years about using the player's inventory as a counter for effects, from turning the Freezer into a machine gun, or setting timers and switches in-game. They've all told you about this miraculous concept and how it is so flawless and perfect, but nobody has ever really told the public how to do it, how it works, and why.

But I will.


Description

 
The inventory system in Duke works as simple as this; imagine a cork posting board on a wall with a sticky note that says "0/0" on it. When the player picks up an inventory item, we'll use the Scuba Gear in our example, the sticky note is replaced with one that says "100/6400". As the player uses the Scuba Gear, the note is changed again to "99/6336", then to "98/6272", and so on. When the player picks up the Scuba Gear again, the sticky note is change back to "100/6400".

The numbers involved here are the percentage remaining and the actual value remaining. In the code, we do not have direct control over what the percent remaining is, the game figures that for itself. We do, however, have the ability to control the actual value that is in the player's inventory for a given item. Example:

ifpinventory GET_SCUBA SCUBA_AMOUNT
{
  addinventory GET_SCUBA SCUBA_AMOUNT
  quote 39
  ifspawnedby AIRTANK
    state getcode
  else
    state quikget
}

This is part of the code for the Scuba Gear item actor. What the code does is check to see if the player's inventory amount for GET_SCUBA is less than SCUBA_AMOUNT. I'll explain why it is less than in a moment. If the if statment returns as true, then the code in the brackets is executed; the player is given full Scuba Gear. Let's look at the code again, in pseudo-English:

if the player's inventory item GET_SCUBA is less than SCUBA_AMOUNT
{
  give the player SCUBA_AMOUNT of the inventory item GET_SCUBA
  display quote 39
  if i was spawned by the actor AIRTANK
    state getcode
  else
    state quikget
}


How It Works

 
That is how the inventory system works, but that's not how the inventory system trick. The key is in a tiny little difference between ifpinventory and all of the other if statements. For example, ifcount (value) checks to see if the current tick counter is equal to or greater than (value), ifactioncount (value) checks to see if the current action has played (value) number of frames. But, ifpinventory (item) (value) checks to see if (item) has a value less than, not equal to or greater than, (value). What does this mean? Read:

ifpinventory GET_BOOTS 10
{
  addphealth 100
  addinventory BOOTS 0
}

...

ifpinventory GET_BOOTS 10 { }
else
{
  addphealth 100
  addinventory BOOTS 0
}

Aside from the obvious differences in the code, these two pieces will operate almost inversely. The first bit of code is what is more common in Duke's original programming, while the second works exploiting the "flaws" in the inventory system. The first bit of code will check to see if GET_BOOTS is less than 10, and if it is, then give him 100 health and set GET_BOOTS back to 0. Now, unless the player picks up the Boots, then his inventory for them will always be below 10 (and that's 10 amount, not 10 percent; remember, we cannot directly change the percentage). This will, for all intensive purposes, make the player totally invulnerable.

The second set of code, however, acts almost in an opposite way. It will check to see if GET_BOOTS is less than 10, and if it is, do what is inbetween the first set of brackets, which is nothing. If it is not less than 10(which the engine somehow perceives as "equal to 10"), then do what is in between the second set of brackets, which is give the player 100 health and set the value back to 0. This works almost like an entirely new item, so whenever the player's GET_BOOTS counter is exactly at 10, he will get 100 health. We could write a new actor that, when the player goes up to it and presses the use key, it sets the GET_BOOTS to 10, and thus, gives him 100 health.


Final Notes


If you look back at the Weapons Coding page, then the part that explains how you can turn the Freezer into a machine gun should make a lot more sense now. This is all I can do to explain this effect, and I hope that I have done a good job at doing so. The only way to truly understand how the effect works and how to get it to mold to your specific TC or project is to work with possible ways to do whatever it is you are trying to do.