(SOLVED) Different action depending on given amount?

Started by BlueAngel, Wed 23/02/2011 10:19:08

Previous topic - Next topic

BlueAngel

Hi
I would like an npg to go to another room and perform a different action depended on the amount the player give him of a inventory item in the first room.
Any ideas how to do this?

Can I create an inventory for the npg and check InventoryQuantity? I don’t really need to see the inventory.

Or maybe I should use an int instead?

Something like if player has given 1 banana, int Banana count = 1 (check in room2) cApe change view(1). Else if int bananacount =2 , cApe change view (2)?

Unai

You can use a Global Variable to keep an account of bananas given to the Ape
I am a deeply superficial person

BlueAngel

Yeah, It's probably the best way.
Thanks for helping. Sometimes I do complicate things unnecessarily.
::)

Khris

While doing this with global variables is the standard way, using the NPC's inventory isn't such a bad idea here.
It doesn't really matter whether you change/read banana_count or cApe.InventoryQuantity[iBanana.ID].

The latter is longer but it's there already and much closer to what's actually happening in the game, which is always a good thing.

BlueAngel

Interesting Kris, I will try both ways when I come home then.
Probably it will be a global variables as I not very good at scripting but I will try the other way too just to see if I can work it out.
Thanks!

monkey0506

When you asked about creating an inventory for the character, I want to clarify something for you. You do not have to display a character's inventory in an InvWindow in order for the character to have access to the inventory functions. Every character is capable of holding inventory.

Along the lines of what Khris said, the additional benefit I see of using the NPC's inventory is that the character's InventoryQuantity exists whether it is ever used or not. If you create another variable just for tracking this, then you're basically wasting the memory that was already reserved for this purpose. Further, if you ever needed to check other items, it would prevent you having to create even more variables for each item.

So in short, you can use a separate global variable, but it would simply be more efficient to use the character's InventoryQuantity.

Edit: You posted while I was typing this. Using the character's InventoryQuantity would not be any more or less difficult than using a separate global variable. For example:

Code: ags
// give banana(s) to cApe
player.InventoryQuantity[iBanana.ID] -= amount;
cApe.InventoryQuantity[iBanana.ID] += amount;
UpdateInventory(); // just in case you have an InvWindow showing at the time, update it

// check how many bananas that cApe has
if ((cApe.InventoryQuantity[iBanana.ID] > 0) && (cApe.InventoryQuantity[iBanana.ID] <= 5))
{
  // player gave at least 1, but no more than 5 bananas in total to cApe
}
else if ((cApe.InventoryQuantity[iBanana.ID] > 5) && (cApe.InventoryQuantity[iBanana.ID] < 10))
{
  // player has given between 6 and 9 bananas in total..
}
else if (cApe.InventoryQuantity[iBanana.ID] == 10)
{
  // player has given 10 bananas to cApe
}


The code would really be nearly identical if you were using a global variable.

BlueAngel

#6
Ok, thanks Monkey. I thought I needed to make an inventory for the ape.
I think I understand it now.  Can’t wait to get home and try it out.
:D

Edit: Thanks for all help, worked wonderfully.

monkey0506

Every Character has an inventory, regardless of whether it's ever used. Most single-player games will only have need of the player character's inventory, but the same functionality is still reserved for every character. ;)

SMF spam blocked by CleanTalk