How you let a character use another character's inventory screen?

Started by Nero_Ace, Tue 16/04/2013 12:15:25

Previous topic - Next topic

Nero_Ace

I have another query regarding the inventory system. I had asked earlier how to implement an always present Inventory Screen and I figured it out thanks to your help.
(Source: http://www.adventuregamestudio.co.uk/forums/index.php?topic=48040)

In my game, there is a second character who always walks with the first one and as you pick up items, some go to your inventory while some go to hers. There are some situations in which you have to use her items.
However, in AGS, when I try doing that, it tells me that it's not my main character's items and crashes.

Is there a work around for this?

P.S. this isn't related to the main problem at all but I'm also having some problems with the mouse cursors. I have a puzzle in which you have to takes items from the inventory and put them in very specific places on the room. For that, the cursor needs to change to an image of the item so you know exactly where to put it.
For this, I made a mouse cursor and gave it the same image as the inventory item. Here's the script I used in global.asc -

function iP1_Interact()
{
  mouse.UseModeGraphic(eModeP1);
}

Now the cursor works fine on it's own. I put it's StandardMode to True and was able to switch to and fro but it doesn't function properly like it's supposed to by the script. Any suggestions as to what I might be doing wrong?

Khris

Regarding the second issue, AGS does this by default. It uses the inventory item graphic as cursor, but you can also specify a different sprite in the item's properties.
Imagine you had to create a separate mouse mode for each item... It's pretty safe to say that you never have to do something like that (implement a UI feature on a per-item or per-object basis).

As for your main issue, that's indeed a drawback of how AGS handles this. You can either store the selected item yourself (in a variable/pointer), use a custom cursor mode and change its sprite to the item's, or temporarily add the inventory item to the player's inventory before setting it as active. The former method is problematic in that you can't use if (player.ActiveInventory == x) anymore in the hotspot's Useinv function.

It would help to know what kind of interface you're using, since it doesn't seem to be the default one. Are you handling inventory clicks yourself using eMouseLeft/RightInv?

Nero_Ace

Okay yeah, the second issue's resolved now. Thanks.

As for the first one, I am making new interfaces for everything but have only gotten to the graphical aspect of them so far. Most of the code in the global.asc is from the default game that AGS creates. However, I think I'll remove the code for all the cursors save for one as what I want is for the cursor to automatically change depending on the situation.
There won't be the need to scroll between Walk, Talk, Interact, etc. Ex. when you hover over a walkable area, the cursor automatically changes to the walk one and when you hover over interactive ones, it changes to the hand icon.

How would you recommend using the one in which you temporarily transfer it to the player's inventory before setting it active?

Khris

Something like this:

Code: ags
// top of global script
InventoryItem* tempActiveInv;

// in on_mouse_click, before inv item is set as active
  InventoryItem* ia = inventory[game.inv_activated];
  if (!player.HasInventory(ia)) {
    player.AddInventory(ia);
    tempActiveInv = ia;
  }
  player.ActiveInventory = ia;

// when player deselects item
  if (tempActiveInv != null) {
    player.LoseInventory(tempActiveInv);
    tempActiveInv = null;
  }


Edit:
typo corrected

Nero_Ace

It's still giving me the error. Maybe I didn't do it properly. I put it at the top of the code before any function and it gave me the following error -

GlobalScript.asc(5): Error (line 5): cannot assign initial value to global pointer

And when I put it right after the game_start function, I still get an error. Even after removing the "==" with a single one, the game runs okay but if I try using her item, it crashes again.

I've limited her to carrying just 2 items now. So will the other method work better or was i just messing up with the code?

Khris

You're not supposed to put the entire piece of code at the top of the global script, just line 2.

The other two parts go into the respective functions, as described in the comments.

You were posting this:
Code: ags
function iP1_Interact()

Since afaik, you cannot interact with inventory items in a default game, I assumed you were using a custom interface and appropriate handling code.

Are you still using the default on_mouse_click function?

Nero_Ace

Yeah, still using the default mouse click code.

Also, I tried putting line 2 at the top and the rest with the interact command and it still gives me an error. Should I try using List Boxes? She only has 2 fixed items so maybe I can fake them as part of the UI when she gets them?

SMF spam blocked by CleanTalk