Thank you for your code changes txesmi, but I am still not able to arm my player with a sword when I place a sword image in the active weapon slot.

I made the changes to inventory.c as you specified.

Here is the code I currently have after making some changes:

OrcStronghold.c
Code:
#include <acknex.h>
#include <default.c>
#include "inventory.c"

...

#define MAIN_BAG_ID        1
#define ACTIV_WPN_SLOT_ID  0
#define SWORD_ID           2

#define SWORD              0
#define MACE               1
#define SHIELD             2
#define APPLE              3
#define GOLD_COINS         4

...

Item *item_shield;
Item *item_apple;
Item *item_sword;
Item *item_mace;
Item *item_gold;

...

ENTITY *active_weapon = NULL;
ENTITY* mace;

Bag* bag;

...

action attach_weapon() 
{
	set(my,PASSABLE);
	proc_mode = PROC_LATE;
	
	while (you != NULL) 
	{
		vec_for_vertex(temp.x,you,997); //hand palm base: Vector # 987
		vec_for_vertex(temp2.x,you,968); //hand palm tip: Vector # 982
		vec_set(my.x,temp.x);
		vec_diff(temp.x,temp2.x,temp.x);
		vec_to_angle(my.pan,temp.x); // ERROR "'pan' is not a member of 'VECTOR'
		vec_set(my.pan,my.pan);
		wait(1);
	}
}

void addApple()
{
	inv_insert_item_into_bag(bag,item_apple); 
}

void addShield()
{
	inv_insert_item_into_bag(bag,item_shield);
}

void addSword()
{
	inv_insert_item_into_bag(bag,item_sword);
}

void addGold()
{
	inv_insert_item_into_bag(bag,item_gold);
}

...

// USED TO OPEN INVENTORY BAG BY CLICKING "i" KEY
//    switch to toggle inventory:
void toggleInventory()
{	
	// put some comparisons here:
	// f.e. if we are dead, don't allow to toggle inventory:
	if(player.HEALTH <= 0)
	{ 
		return; 
	}
	// toggle var:
	invOpen += 1;
	invOpen %= 2;
	
	// if we've opened the inventory:
	if(invOpen == 1)
	{
		// show the mouse pointer:
		
		change_mouse_mode();
		mouse_mode = 1;
		
		// PUT IN CODE FOR INVENTORY GUI
		
	   inv_open_bag ( bag, 0, 0 );  // OPEN INVENTORY BAG CODE
	}
	else
	{
		
		mouse_mode = 0;
	   inv_close_bag(bag);

   }
}

...

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)
			{
				ent_remove ( active_weapon );
				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)
		{
			switch ( placed_item_id )
			{
				case SWORD:  active_weapon = ent_create ( "sword.mdl", my.x, attach_weapon );  break;
				case MACE:   active_weapon = ent_create ( "mace.mdl", my.x, attach_weapon );    break;
			}
		}
	}   
   }
}

function main()
{
	
   ...

   inv_init(); // <---- ADDED THIS
   wait(1); // <---- ADDED THIS

   item_shield = inv_create_item(SHIELD,0,"shield.pcx","shield.pcx");
   item_apple = inv_create_item(APPLE,0,"apple.pcx","apple.pcx");
   item_sword = inv_create_item(SWORD,1,"steel_sword.pcx","steel_sword.pcx");
   item_mace = inv_create_item(MACE,1,"mace.pcx","mace.pcx");
   item_gold = inv_create_item(GOLD_COINS,0,"gold_coins.pcx","gold_coins.pcx");

   bag = inv_create_bag(MAIN_BAG_ID,"leather_seam.pcx");  // <---- added this line
   
   // START OF INVENTORY BAG
   
   // ACTIVE ITEM SLOT
   
   inv_add_slot_to_bag(bag,0,1,"leather_texture.pcx",9,60); // 3RD VALUE "1", ONLY ITEMS WITH THIS VALUE CAN BE INSERTED INTO THIS SLOT.

   // EACH ROW OF INVENTORY BAG IS SPACED OUT BY 64 HEIGHT
   // FIRST ROW OF INVENTORY BAG

   inv_add_slot_to_bag(bag,1,0,"leather_texture.pcx",9,150);
	 
   inv_add_slot_to_bag(bag,2,0,"leather_texture.pcx",70,150);

   inv_add_slot_to_bag(bag,3,0,"leather_texture.pcx",130,150);
	 
   inv_add_slot_to_bag(bag,4,0,"leather_texture.pcx",190,150);
	
   // SECOND ROW OF INVENTORY BAG
		
   inv_add_slot_to_bag(bag,5,0,"leather_texture.pcx",9,214);

   inv_add_slot_to_bag(bag,6,0,"leather_texture.pcx",70,214);
	
   inv_add_slot_to_bag(bag,7,0,"leather_texture.pcx",130,214);
	
   inv_add_slot_to_bag(bag,8,0,"leather_texture.pcx",190,214);
	
   // THIRD ROW OF INVENTORY BAG
	
   inv_add_slot_to_bag(bag,9,0,"leather_texture.pcx",9,278);
	
   inv_add_slot_to_bag(bag,10,0,"leather_texture.pcx",70,278);
    
  inv_add_slot_to_bag(bag,11,0,"leather_texture.pcx",130,278);
	
  inv_add_slot_to_bag(bag,12,0,"leather_texture.pcx",190,278);

   inv_set_bag_drag_region(bag,5,3,128,18);
   inv_set_bag_close_region(bag,129,0,148,19);
 	
   set_on_click_callback("slot_was_clicked");
 	
   // USED FOR TESTING INVENTORY BAG FUNCTIONALITY
 	
   on_1 = addApple;
   on_2 = addShield;
   on_3 = addSword;
   on_4 = addGold;
 		
   while ( !key_esc )
   {
   	if ( active_weapon != NULL )
   		active_weapon->pan += 5*time_step;
   		
   	mouse_pos.x = mouse_cursor.x;
        mouse_pos.y = mouse_cursor.y;
      
        // if we've enabled the mouse:
        if(mouse_mode > 0)
        {
      	   // move it's position with a cursor:
      	   vec_set(mouse_pos.x, mouse_cursor.x);
        }
   		
   	wait(1);
   }
	
   sys_exit ( NULL );
}



I am still getting the same result with this code, although I am not getting syntax errors when I compile. Am I doing something wrong?

Last edited by Ruben; 01/05/14 01:14.