Author Topic: TAW script needs fixing  (Read 350 times)

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
TAW script needs fixing
« on: June 07, 2012, 01:27:03 am »


               Okay, I am not a scripter so I make heavy use of LilacSoul's Script Generator (before anyone complains about me not learning scripting...cut me some slack, please...I work and go to school fullt time, plus I am married and have a 2 year old, and have a social life).

I cannot, for the life of me figure out why the below script won't work. It is supposed to check and see if the PC has any of the items in his inventory and if he/she does, make a conversation node appear. The node is a PC node, not an NPC one.

Here's the script (apologies, I don't recall how to post in a window):

int GetNumItems(object oTarget,string sItem)
{
int nNumItems = 0;
object oItem = GetFirstItemInInventory(oTarget);
while (GetIsObjectValid(oItem) == TRUE)
{
if (GetTag(oItem) == sItem)
{
nNumItems = nNumItems + GetNumStackedItems(oItem);
}
oItem = GetNextItemInInventory(oTarget);
}
return nNumItems;
}

/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.c...=4683&id=625    */

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

if (GetNumItems(oPC, "NW_IT_TRAP033") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP013") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP021") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP017") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP029") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP025") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP001") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP009") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP034") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP014") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP022") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP018") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP030") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP026") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP002") < 1) return FALSE;

if (GetNumItems(oPC, "NW_IT_TRAP010") < 1) return FALSE;

return TRUE;
}


Thanks for any help you can provide!
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
TAW script needs fixing
« Reply #1 on: June 07, 2012, 01:54:39 am »


               The posted code will return true only if oPC has at least 1 of each specified item.

int StartingConditional()
{
   object oPC = GetPCSpeaker();
   object oItem = GetFirstItemInInventory(oPC);
   while(oItem != OBJECT_INVALID)
   {
      string sTag = GetTag(oItem);
      if(sTag == "NW_IT_TRAP033" || sTag == "NW_IT_TRAP013" ||
      sTag == "NW_IT_TRAP021" || sTag == "NW_IT_TRAP017" ||
      sTag == "NW_IT_TRAP029" || sTag == "NW_IT_TRAP025" ||
      sTag == "NW_IT_TRAP001" || sTag == "NW_IT_TRAP009" ||
      sTag == "NW_IT_TRAP034" || sTag == "NW_IT_TRAP014" ||
      sTag == "NW_IT_TRAP022" || sTag == "NW_IT_TRAP018" ||
      sTag == "NW_IT_TRAP030" || sTag == "NW_IT_TRAP026" ||
      sTag == "NW_IT_TRAP002" || sTag == "NW_IT_TRAP010")
      return TRUE;
      oItem = GetNextItemInInventory(oPC);
   }
   return FALSE;
}


This should do it, in the "Text appears when" tab. '<img'>

EDIT: The solution proposed by Lightfoot8 is faster and more efficient. I proposed this one in a hurry because speed does not usually matter much in a convo script.


Kato
               
               

               


                     Modifié par Kato_Yang, 07 juin 2012 - 01:19 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
TAW script needs fixing
« Reply #2 on: June 07, 2012, 01:56:03 am »


               The reason is that once it get to any one of the items listed that you have non of the items It returns FALSE and the script stops running.  

Change all of the if (GetNumItems(oPC, "NW_IT_TRAP010") < 1) return FALSE; lines to

If (GetItemPossesedBy( oPC, "NW_IT_TRAP033")  != OBJECT_INVALID) return TRUE;  


Had to run back to work so  excuse any minor errors in that line.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
TAW script needs fixing
« Reply #3 on: June 07, 2012, 03:36:57 pm »


               

UnrealJedi wrote...
, plus I am married and have a 2 year old, and have a social life.

I believe the majority of the nwn community is in the same boat.':wizard:'