Thank you xbox. I think you are on the right track.

I am trying to use structs now in my situation. However, for some reason I am still not able to attach a sword to my player's hand when I drag a sword image toward the active weapon slot in the player's inventory bag.

So far, this is what I have done in my code:

OrcStronghold.c
Code:
// OrcStronghold.c

#include "Player.c"

...

Item* inv_slots[13];
inv_slots = new(Item);

...

function main()
{
   ...

   // Creating equipment items to be used in inventory bag (.pcx images to click
   //    and drag among slots in inventory bag)

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

   bag = inv_create_bag(1,"leather_seam.pcx");  // <---- added this line

   // START OF INVENTORY BAG
   
   // ACTIVE ITEM SLOT
   
   inv_slots[0] = inv_add_slot_to_bag(bag,0,1,"leather_texture.pcx",9,60); 
      // Active Weapon slot

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

   inv_slots[1] = inv_add_slot_to_bag(bag,1,0,"leather_texture.pcx",9,150);
   inv_slots[2] = inv_add_slot_to_bag(bag,2,0,"leather_texture.pcx",70,150);
   inv_slots[3] = inv_add_slot_to_bag(bag,3,0,"leather_texture.pcx",130,150);
   inv_slots[4] = inv_add_slot_to_bag(bag,4,0,"leather_texture.pcx",190,150);
	
   // SECOND ROW OF INVENTORY BAG
	
   inv_slots[5] = inv_add_slot_to_bag(bag,5,0,"leather_texture.pcx",9,214);
   inv_slots[6] = inv_add_slot_to_bag(bag,6,0,"leather_texture.pcx",70,214);
   inv_slots[7] = inv_add_slot_to_bag(bag,7,0,"leather_texture.pcx",130,214);
   inv_slots[8] = inv_add_slot_to_bag(bag,8,0,"leather_texture.pcx",190,214);
	
   // THIRD ROW OF INVENTORY BAG
	
   inv_slots[9] = inv_add_slot_to_bag(bag,9,0,"leather_texture.pcx",9,278);
   inv_slots[10] = inv_add_slot_to_bag(bag,10,0,"leather_texture.pcx",70,278);
   inv_slots[11] = inv_add_slot_to_bag(bag,11,0,"leather_texture.pcx",130,278);
   inv_slots[12] = inv_add_slot_to_bag(bag,12,0,"leather_texture.pcx",190,278);

   if(str_cmp(inv_slots[0].floating_icon, "steel_sword.pcx")) 
   {
        active_sword = ent_create ("sword.mdl", my.x, attach_weapon);
   }
   else
   {
        ent_remove(active_sword);
   }

   ...
}


Code:
// Player.c

#include "inventory.c"

...

// Attaches a weapon to player's hand

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);
   }
}

...


Code:
// inventory.c

...

typedef struct
{
   int id;
   int group_id;
   STRING* floating_icon;
   STRING* inventory_icon;
} Item;


// === Slot ===

typedef struct
{
   PANEL* slot_panel;
	
   int id;
   int group_id;
   int rel_x_pos;
   int rel_y_pos;
   int width;
   int height;
	
   STRING* background_image;
	
   Item *item;
   
   int bag_id;
   
} Slot;

// === Bag ===

typedef struct
{
   int id;
   int is_open;
	
   int drag_region_top_left_x;
   int drag_region_top_left_y;
   int drag_region_bottom_right_x;
   int drag_region_bottom_right_y;

   int close_region_top_left_x;
   int close_region_top_left_y;
   int close_region_bottom_right_x;
   int close_region_bottom_right_y;
	
   PANEL* bag_panel;
   Slot* slots[16];
   int _slot_count;
   STRING* image_name;     
} Bag;

...

function inv_create_item(item_id, group_id, STRING* floating_icon, STRING* inventory_icon)
{
   // Create item and assign images
	
   Item* item = new(Item);
   item->floating_icon = floating_icon;		
   item->inventory_icon = inventory_icon;
   item->id = item_id;
   item->group_id = group_id;
	
   // Add item to global array for cleanup purposes

   inv_items_array[inv_item_count] = item;
   inv_item_count++;
	
   return item;		
}

...

function inv_create_bag(int bag_id, STRING* image_name)
{
   Bag* bag;
   bag = new(Bag);
	
   bag->image_name = image_name;
   bag->id = bag_id;
	
   // Initialize slot_count to 0
   bag->_slot_count = 0;
   bag->is_open = 0;
	
   // Add bag to global array for cleanup purposes

   inv_bags_array[inv_bag_count] = bag;
   inv_bag_count++;
	
   return bag;
}

...

function inv_add_slot_to_bag(Bag* bag, int slot_id, int group_id, STRING* default_image, int rel_x_pos, int rel_y_pos)
{
   Slot* new_slot;
   new_slot = new(Slot);

   // Set the position for the new slot
	
   new_slot->rel_x_pos = rel_x_pos;
   new_slot->rel_y_pos = rel_y_pos;	
   new_slot->background_image = default_image;
   new_slot->item = NULL;
   new_slot->id = slot_id;
   new_slot->group_id = group_id;
   new_slot->bag_id = bag->id;	
		
   bag->slots[bag->_slot_count] = new_slot;
	
   bag->_slot_count += 1;	
}

...



When I compile OrcStronghold.c , it does not produce any syntax errors, but when I access my inventory bag and drag a sword image ("steel_sword.pcx") over to the active weapon slot, and get out of the inventory bag, my player is not being armed with the sword.

Does anyone know what I may be doing wrong in trying to make this happen?

Last edited by Ruben; 01/01/14 20:34.