GUI Help

Started by ktalebian, Wed 20/12/2006 06:15:46

Previous topic - Next topic

ktalebian

Hi, I am making two inventories. One is the main one, where the objects go when you pick them. For the other one, I want the user to be able to put the objects the he has in it.
What I dont know how to do, are
a) How do I get the ID of the item? I mean, how to I get the id of the ActiveInventory, so that I can take it off the main inventory.
b) How do I add it to an inventory? Because right now when I pick up an object, it goes into both inventories!
Thank You

SSH

I'm not entirely sure what you want here. What do you mean by "I want the user to be able to put the objects the he has in it. " Is it some kind of backpack or soemthing where you can store extra items but have to transfer them back and forth? If so, that's actually a really irritating piece of gameplay, but anyway, you're maybe best to use a dummy character's inventory for that, rather than the "real" inventory of the player.

so instead of player.AddInventory(ITEM) do cDummy.AddInventory(ITEM). You can set in an inventory window gui control which character it refers to.

and the ActiveInventory's ID is found by player.ActiveInventory.ID! But you don't need that to remove it: use player.LoseInventory(player.ActiveInventory).

so to transfer something from player inv to the other:

Code: ags

cDummy.AddInventory(player.ActiveInventory);
player.LoseInventory(player.ActiveInventory);
player.ActiveInventory=null;


12

Khris

a) player.ActiveInventory.ID
However, you won't need that because you can use player.LoseInventory(iItem);

b) Each character has its own inventory so just tell the InvWindow to display the contents of another character's inventory.
In the GUI Editor, change the Character ID property of the second InvWindow to the ID of a blank character, then use character[X].AddInventory(iItem); to add an item (with X being the ID of the blank char, of course).
You can use InvWindow.CharacterToUse=cDummy;, too.

EDIT: SSH beat me.

ktalebian

Hi! Thx for the replay! So that worked! Now the problem is that when  want to do the reverse, I mean when I want to take the thing from the second inventory and put it back to the original inventory, it gives me an error. It says that the player does not have that item! It's because the item is now in the other person's inventory! How can I solve that problem?

Ashen

It should just be a case of swapping the character names around, e.g.:
Code: ags

// To take item FROM player TO npc
player.LoseInventory(iKey);
cNpc.AddInventory(iKey);

// To take item FROM npc TO palyer
cNpc.LoseInventory(iKey);
player.AddInventory(iKey);


But it depends on exactly what code you're using.
I know what you're thinking ... Don't think that.

Khris

To get the InventoryItem the player has clicked on, use
Code: ags
InventoryItem*Actinv=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

Now you can add/remove the item with
Code: ags
cDummy.LoseInventory(Actinv);
player.AddInventory(Actinv);

ktalebian

Thanks for the replay. I'm still getting the same error. here is my code

function btnInvBack_Click(GUIControl *control, MouseButton button) {
  InventoryItem*Actinv=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
   if (Actinv != null){  // To see if the character wants to move an object or to just change screen
     cDummy.LoseInventory(Actinv);
     player.AddInventory(Actinv);   
     mouse.Mode = eModeInteract;    
   }
   else {
     gChest.Visible = false;
     gInventoryfloat.Visible = true;
  } 
}

Ashen

That code probably won't do anything except close gChest. (Since it's a Button interaction, there'll NEVER be an Item under the mouse when it runs.)

What's the sequence of events that should happen here? I'd guess at:
- Player clicks an item in cDummy's inventory.
- That item becomes 'active'. (This will cause errors, because it's NOT in the player's inventory).
- Player clicks btnInvBack, item is transfered over if needed.

If so, you need to find a way to make the Item 'active' without causing the error. I'd suggest using an unused Cursor mode, and setting it's graphic to the item graphic, e,g,:
Code: ags

// When click on item in cDummy's Inventory
mouse.ChangeModeGraphic(eModeUsermode1, inventory[game.inv_activated ].Graphic);
mouse.Mode = eModeUsermode1;


Then check if mouse.Mode == eModeUsermode1 in the btnInvBack function. (You might also need a Pointer to store which item was click - for use in btnInvBack_Click - or you might be able to use inventory[game.inv_activated ] again.)

An easier way add another button to the GUI for 'Give item back to player' that sets the cursor mode, and have that mode's interaction move the Item.
I know what you're thinking ... Don't think that.

ktalebian

sorry for all the trouble, but it still did not work. here is my code so far

#sectionstart btnInvChest 
function btnInvChest_Click(GUIControl *control, MouseButton button) {
   if (player.ActiveInventory != null){
     cDummy.AddInventory(player.ActiveInventory);
     player.LoseInventory(player.ActiveInventory);   
      mouse.Mode = eModeInteract;    
      player.ActiveInventory = null;
   }
   else {
      gInventoryfloat.Visible = false;
      mouse.ChangeModeGraphic(eModeUsermode2, inventory[game.inv_activated].Graphic);
    mouse.UseModeGraphic(eModeUsermode2);
      gChest.Visible = true;
  } 
}

#sectionend btnInvChest 

#sectionstart btnInvBack 
function btnInvBack_Click(GUIControl *control, MouseButton button) {
  InventoryItem*Actinv=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
   if (Actinv != null){
     cDummy.LoseInventory(Actinv);
     player.AddInventory(Actinv);   
      mouse.Mode = eModeInteract;    
   }
   else {
      gChest.Visible = false;
      gInventoryfloat.Visible = true;
  } 
}


the first part one is for putting the object in the chest, and second one is for returning.

SMF spam blocked by CleanTalk