How can I specify which Inv object to use for the "_UseInv" function?

Started by MRollins, Fri 01/02/2008 23:54:07

Previous topic - Next topic

MRollins

I am trying to figure out how to limit the below function to only work when I use a specific inv item on a character. Currently, this function is starting when I use ANY inventory item on the character. I've looked all over the manual so any help would be appreciated.

Code: ags
function cTraderwick_UseInv()
{
cEgo.Walk(77, 125, eBlock);
dialog[1].Start();
player.LoseInventory(iEgg);
player.AddInventory(iHabGrant);
} 

monkey0506

You could use the player's active inventory item for this:

Code: ags
function cTraderwick_UseInv()
{
  if (player.ActiveInventory == iEgg) // player used iEgg on cTraderwick
  {
    cEgo.Walk(77, 125, eBlock);
    // is cEgo the player? if so, it is recommended to replace "cEgo" with "player" in case you change the player character later ;)
    dialog[1].Start();
    player.LoseInventory(iEgg);
    player.AddInventory(iHabGrant);
  }
}


As I denoted by the comment, if cEgo is your player character, you may want to use the player keyword instead of using cEgo directly. That way in case you change your player character later you won't have any strange problems. ;)

BTW, this is the exact same issue as the one posted here today. Just for future reference, the forum has a search function so you can check for related issues. This serves two purposes: 1) it can help you find your answer yourself! and 2) it will save you the stress of dealing with angry moderators telling you to read the rules! ;D

MRollins

Wow, I even tried to search the forums for it and I still didn't see it.  >:(

Thanks for the help!

SMF spam blocked by CleanTalk