Let's continue with highlighting the inventory system.
As I mentioned before the player can sell, trade, buy, use or drop an inventory item. Let's look at trading inventory items.
There are three possible ways you can have the player trade items. Let’s look at them from a player’s perspective.
The first method. Say you have two items that can possibly be collected. A key and a map. You have the map but you really need the key. So, you check to see if the key can be gotten through a trade. You bring up the inventory list in the category where the key is and right click on the key you need. You are presented with information for this item. Looking down through this information you see that “Yes” is indicated for “You can trade item:” You press <ENTER> to return to the list of keys. Now you click the left mouse button which presents you with a numbered selection menu at the bottom of the screen. “Trade” will be one of the menu items. Press the number on the keyboard that is associated with “Trade.” This will bring up a list of possible inventory items that you already have. Since you have only one item, the map, in this example, it will be the only item displayed. However, if you have more items in your inventory, then they would be displayed as well. Point to the inventory item you desire to trade for the key (in this case the map) and press the right mouse button. The selection will disappear and you now have the key in your inventory but you do not have the map. Hopefully
you will not need the map later.
The second method is dropping an entity onto the map that will allow a trade. The entity must be dynamic and it can be anything. Of course, you would want it to seem plausible. You will need to name the entity the same name of the inventory item you want the player to take in trade. In this example the inventory item name is Key #1. You will need to give the entity placed on the map this name as well. Here’s how it works from the player’s perspective. Again, he has the map but needs the key. He is traversing the universe and comes upon a set of keys. When he approaches the keys, a list of inventory items will pop up on the screen. These items are those items he currently has. Of course, in this scenario, the only item will be the map. He would choose the map by clicking on that item using the right mouse button. The selection will disappear and you now have the key in your inventory and the map inventory will be decreased by one.
You will need to set rpg_setplayercantradeitem to one (1) for both the key and the map. DO NOT set rpg_setitemcanbetraded to one. If the command is use in connection with the items then be sure and set it to zero (0) for this scenario. Place the following script into the main AI of the entity Key #1:
:state=0,plrdistwithin=50:rpg_playertrade,state=1
:state=1,rpg_playercantakeitem:playertake
:state=1,plrdistfurther=50:state=0
The third and last method is trading with a character in the game. The trade will take place through scripting. Once the trade is completed then you would use the action command rpg_characterplayertrade with the two parameters that were placed into two two variables.
&myvar1 = a variable that contains the item player gives to character (map)
&myvar2 = a variable that contains the item player gets from character (key)
:state=0,plrdistwithin=50,rpg_hasinvitem=&myvar1:rpg_characterplayertrade=&myvar1 &myvar2,state=1
:state=0,plrdistwithin=50:state=1
:state=1,plrdistfurther=50:state=0
Notice the command rpg_hasinvitem=&myvar1. It checks to see if the player has the inventory item that is contained in the variable named myvar1 (map). You must have at least one item in inventory. This script will not hold a conversation with the character. It will simply trade items. Decreasing the player’s map item and increasing the player’s key item by one (1).