Author Topic: Onacquireitem: check for three items to add journal entry  (Read 452 times)

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« on: October 24, 2010, 05:40:17 pm »


               Again, sorry if this has all been discussed before but I didn't get any search results using the engine on this website and I couldn't find anything on this with google either.

I want the PC to get a new journal entry "magicalitems" DS 3, when he has gathered three items. I already made a custom onacquireitem script for the module events for another item which triggers a journal entry.
How do I do it for more than one item?

Thanks in advance, you guys are a great help!
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« Reply #1 on: October 24, 2010, 07:21:35 pm »


               Something like this:


void main()
{
object oPC = GetModuleItemAcquiredBy();
object oItem = GetModuleItemAcquired();

if(GetTag(oItem) == "ItemTag3" &&
   GetIsObjectValid(GetItemPossessedBy(oPC, "ItemTag2")) &&
   GetIsObjectValid(GetItemPossessedBy(oPC, "ItemTag1")))
   {
   AddJournalQuestEntry("magicalitems", 3, oPC);
   }
}

-420
               
               

               


                     Modifié par 420, 24 octobre 2010 - 06:22 .
                     
                  


            

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« Reply #2 on: October 25, 2010, 07:39:21 pm »


               Thanks! It works like a charm.

Now I am trying to do a similar thing with a script from conversation. I want a text to appear if either of three items is in posession. I have this script now:


int StartingConditional()
{
object oPC = GetPCSpeaker();

if (GetItemPossessedBy(oPC, "Roseruby") == OBJECT_INVALID) return FALSE;

if (GetItemPossessedBy(oPC, "Fireopal") == OBJECT_INVALID) return FALSE;

if (GetItemPossessedBy(oPC, "Bloodcoral") == OBJECT_INVALID) return FALSE;

return TRUE;
}


But with this script  you have to have all of the items, and not either one of them...
               
               

               


                     Modifié par Eva_hop, 25 octobre 2010 - 06:47 .
                     
                  


            

Legacy_Syrus Greycloak

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« Reply #3 on: October 25, 2010, 09:00:43 pm »


               The problem with your script is that it never gets by a test condition to check the other ones because you are using return statements.  If the first test is true, it returns false, exiting the script without checking the rest.  If the test is false, it falls to the second test, where if that is true, it returns false and exits, and so on.  This is why you need all three items to get to the 'return true' at the bottom.



Your best bet is to flip the options - set all tests to not equal instead of equal, return true instead of false, and then return false at the end if it gets that far.  Then it should do what you want.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« Reply #4 on: October 25, 2010, 09:14:27 pm »


               

int StartingConditional() {
    object oPC = GetPCSpeaker();
    int nCount = 0;
    if (GetIsObjectValid(GetItemPossessedBy(oPC, "Roseruby")))
        nCount++;
    if (GetIsObjectValid(GetItemPossessedBy(oPC, "Fireopal")))
        nCount++;
    if (GetIsObjectValid(GetItemPossessedBy(oPC, "Bloodcoral")))
        nCount++;

    if (nCount > 0 && nCount < 3)
        return TRUE;
    return FALSE;
}

That returns TRUE if any of the 3 items is in the PCs inventory, but FALSE if all of them are - I assume that's what you want since you have a seperate condition for all 3, correct?

Funky
               
               

               


                     Modifié par FunkySwerve, 25 octobre 2010 - 08:16 .
                     
                  


            

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« Reply #5 on: October 25, 2010, 09:27:27 pm »


               Thanks for the info Greycloak!

@ Funky Swerve: No, I want the script to play if either one of the gems is in posession, or two, or all three. So I think I should go for what Greycloak is suggesting. The problem is that the script fires only if all three are in posession.

This is what I have now. How do I set it to 'not equal' instead of 'equal'?

int StartingConditional()
{
object oPC = GetPCSpeaker();

if (GetItemPossessedBy(oPC, "Roseruby") == OBJECT_INVALID) return TRUE;

if (GetItemPossessedBy(oPC, "Fireopal") == OBJECT_INVALID) return TRUE;

if (GetItemPossessedBy(oPC, "Bloodcoral") == OBJECT_INVALID) return TRUE;

return FALSE;
}


               
               

               


                     Modifié par Eva_hop, 25 octobre 2010 - 08:37 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« Reply #6 on: October 25, 2010, 10:12:35 pm »


               int StartingConditional()

{

object oPC = GetPCSpeaker();



if (GetItemPossessedBy(oPC, "Roseruby") != OBJECT_INVALID) return TRUE;



if (GetItemPossessedBy(oPC, "Fireopal") != OBJECT_INVALID) return TRUE;



if (GetItemPossessedBy(oPC, "Bloodcoral") != OBJECT_INVALID) return TRUE;



return FALSE;

}

               
               

               
            

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Onacquireitem: check for three items to add journal entry
« Reply #7 on: October 26, 2010, 11:15:15 am »


               I knew those exclamation marks would have to go somewhere! '<img'> thanks!