doble post blush

Anyway you have to hear about the great benefits of using arrays to allocate your data.

If your item pointers are sorted into an array and you fill the inventory item id with its array index you can avoid all those ugly switch-case blocks.

Code:
Item *myItems[3];
#define SNIPERGUN          0 
#define SHOTGUN            1
#define MACHINEGUN         2

//instead of
Item *itemSnipergun = NULL;
Item *itemShotgun = NULL;
Item *itemMachinegun = NULL;



Since the answer of the inventory.c functions is the id of the item, you can build parallel data structs with the data you need to manage the items from the inventory to the scenery and viceversa.

For example, you need the file name of the entities when you drop them from the inventory. You can build a TEXT struct with all your item file names and use the item id to create the entity.

Code:
Item *myItems[3];
TEXT *txtItemModelNames = { strings = 3; }
#define SNIPERGUN          0 
#define SHOTGUN            1
#define MACHINEGUN         2

// When you create each item you fill the filenames,
myItems[SNIPERGUN] = inv_create_item ( SNIPERGUN,  1, "icon2.pcx", "icon2.pcx" );
inv_insert_item_into_bag ( bag, myItems[SNIPERGUN] );
str_cpy ( (txtItemModelNames.pstring)[SNIPERGUN], "snipergun.mdl" );

// So you can create the proper entity with the item id
ENTITY *ent = ent_create ( (txtItemModelNames.pstring)[item_id], vecPos, NULL );

// instead of
if ( item_id == SNIPERGUN )
   ENTITY *ent = ent_create ( "snipergun.mdl", vecPos, NULL );
if ( item_id == SHOTGUN )
   ENTITY *ent = ent_create ( "shotgun.mdl", vecPos, NULL );
if ( item_id == MACHINEGUN )
   ENTITY *ent = ent_create ( "machinegun.mdl", vecPos, NULL );

// or
switch ( item_id )
{
   case SNIPERGUN:
      ENTITY *ent = ent_create ( "snipergun.mdl", vecPos, NULL );
      break;
   case SHOTGUN:
   ...
}



In order to pick an object from the scenery and add it to the inventory it should have the item id stored somewhere. So when you drop an object you save the item id in the newly created entity and when you pick an object you use its saved item id to add it to the inventory.

Code:
// object dropped
ENTITY *ent = ent_create ( (txtItemModelNames.pstring)[item_id], vecPos, NULL );
ent.skill1 = item_id;

// object picked
inv_insert_item_into_bag ( bag, myItems[mouse_ent.skill1] );



Here the example I gived you above using arrays
Code:
#include <acknex.h>
#include <default.c>
#include "inventory.c"

#define PRAGMA_PATH "%EXE_DIR%\\templates\\sounds"
#define PRAGMA_PATH "%EXE_DIR%\\templates\\images"
#define PRAGMA_PATH "%EXE_DIR%\\templates\\models"
#define PRAGMA_PATH "%EXE_DIR%\\templates\\levels"

#define MAIN_BAG_ID        1
#define ACTIV_WPN_SLOT_ID  0

SOUND *sndReload = "reload.wav";
SOUND *sndDrop = "getready.wav";
SOUND *sndShot = "shot2.wav";

ENTITY *active_weapon = NULL;
Bag *bag = NULL;

Item *myItems[3];
TEXT *txtItemModelNames = { strings = 3; }

#define SNIPERGUN          0 
#define SHOTGUN            1
#define MACHINEGUN         2


action active_weapon_action ()
{
	ENTITY *ent = active_weapon;
	if ( ent )
	{
		ent.x = 70;
		ent.y = -20;
		ent.z = -20;
		while ( ent == active_weapon )
			wait(1);
		ent_remove ( ent );
	}
}

function slot_was_clicked ( int occurrence, int bag_id, int slot_id, int placed_item_id, int removed_item_id ) 
{
   if ( ( occurrence == INV_ITEM_REMOVED ) || ( occurrence == INV_ITEM_SWAPPED ) )
   {
		if (bag_id == MAIN_BAG_ID)
		{
			if (slot_id == ACTIV_WPN_SLOT_ID)
			{
				active_weapon = NULL;
			}
		}   
   }
	if ( ( occurrence == INV_ITEM_PLACED ) || ( occurrence == INV_ITEM_SWAPPED ) )
	{
		if (bag_id == MAIN_BAG_ID)
		{
			if (slot_id == ACTIV_WPN_SLOT_ID)
			{
				active_weapon = ent_createlayer ( (txtItemModelNames.pstring)[placed_item_id], SHOW, 1 );
				active_weapon_action ();  
				snd_play ( sndReload, 100, 0 );
			}
		}   
	}
}

ENTITY *create_scenery_object ( var type, VECTOR *vecPos )
{
	ENTITY *ent = ent_create ( (txtItemModelNames.pstring)[type], vecPos, NULL ); 
	ent->skill1 = type;
	snd_play ( sndDrop, 100, 0 );
	return ent;
}

void onMouseLeft ()
{
	if ( mouse_panel )
		return;
	
	if ( inv_is_floating() )
	{
		VECTOR vecTemp;
		vec_set ( vecTemp, mouse_dir3d );
		vec_scale ( vecTemp, 1000 );
		vec_add ( vecTemp, camera.x );
		c_trace ( camera.x, vecTemp, IGNORE_PASSABLE );
		if ( HIT_TARGET )
		{
			vec_set ( vecTemp, hit.x );
			vecTemp.z += 10;
			var item_id = inv_get_floating_icon_item ();
			ENTITY *entObject = create_scenery_object ( item_id, hit.x );
		}
	}
	else if ( mouse_ent )
	{
		ENTITY *ent = mouse_ent;
		inv_insert_item_into_bag ( bag, myItems[mouse_ent.skill1] ); 
		wait(1); // ent_remove needs a wait before calling it from a 3dgs event
		ent_remove ( ent );
	}
	else if ( active_weapon )
	{
		snd_play ( sndShot, 100, 0 );
	}
}

void newLevel ()
{
	level_load ( "" );
	ENTITY *entTerrain = ent_create( "water.hmp", nullvector, NULL );
	entTerrain.flags2 |= UNTOUCHABLE;
	camera.x = -200;
	camera.z = 400;
	camera.tilt = -60;
	inv_run_slot_callback ( bag, ACTIV_WPN_SLOT_ID );
}

function main()
{
	mouse_mode = 4;
   inv_init();
	
   bag = inv_create_bag ( MAIN_BAG_ID,"bluebar.pcx");
   inv_add_slot_to_bag ( bag, ACTIV_WPN_SLOT_ID, 1, "flash2.tga", 0, 0 );
   inv_add_slot_to_bag ( bag, 1,0,"flash2.tga",0,120);
   inv_add_slot_to_bag ( bag, 2,0,"flash2.tga",0,180);
   inv_add_slot_to_bag ( bag, 3,0,"flash2.tga",0,240);
   
   myItems[SNIPERGUN] = inv_create_item ( SNIPERGUN,  1, "icon2.pcx", "icon2.pcx" );
   inv_insert_item_into_bag ( bag, myItems[SNIPERGUN] );
   str_cpy ( (txtItemModelNames.pstring)[SNIPERGUN], "snipergun.mdl" );
   
   myItems[SHOTGUN] = inv_create_item ( SHOTGUN,    1, "icon3.pcx", "icon3.pcx" );
   inv_insert_item_into_bag ( bag, myItems[SHOTGUN] );
   str_cpy ( (txtItemModelNames.pstring)[SHOTGUN], "shotgun.mdl" );

   myItems[MACHINEGUN] = inv_create_item ( MACHINEGUN, 1, "icon4.pcx", "icon4.pcx" );
   inv_insert_item_into_bag ( bag, myItems[MACHINEGUN] );
   str_cpy ( (txtItemModelNames.pstring)[MACHINEGUN], "machinegun.mdl" );

   set_on_click_callback ( "slot_was_clicked" );
   on_mouse_left = onMouseLeft;
   on_space = newLevel;
   
   newLevel ();
   inv_open_bag ( bag, 0, 0 );
   
   while ( !key_esc )
		wait(1);
   
   sys_exit ( NULL );
}



Salud!