Jump to content

Home

[K1] Help with item requirement scripts for dialogs.


Zgred_2

Recommended Posts

Hey everybody, can anyone help me how to make a script for the .dlg files that checks if the PC has 2 or more same items and how to check for more than one item through one script? Thanks for the help :)

 

I think you should be able to to it with a script like this. I've added code comments (in green) That tells what the script does.

 

Essentially it uses a custom function, ST_HasItem(), that checks through the inventory of the specified object (or the player's party inventory if no object is specified) for the presence of specified amount of a type of item, set by the item's Tag.

 

In the StartingConditional() main function this function is called for each item type to check for, ANDed together so that all of them will be required for the condition to be fulfilled. This is the only part you should need to modify to check for different items.

 

int ST_HasItem(string sTag, int iCnt=1, object oTarget=OBJECT_INVALID);


[color=PaleGreen]// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Main function - check for the presence of items.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[/color]
int StartingConditional() {
   [color=PaleGreen]// ST: Example - return true and allow dialog node if the player has at least
   //     one [color=red]Medpac[/color] [color=SkyBlue]and[/color] [color=Yellow]two[/color] [color=Pink]Programming Spikes[/color].[/color]
   return ST_HasItem("[color=red]g_i_medeqpmnt01[/color]") [color=SkyBlue]&&[/color] ST_HasItem("[color=Pink]g_i_progspike01[/color]", [color=Yellow]2[/color]);
}


[color=PaleGreen]// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Utility function, check if an object has the specified amount of an item.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[/color]
int ST_HasItem(string sTag, int iCnt=1, object oTarget=OBJECT_INVALID) {
   [color=PaleGreen]// ST: If no target is set, use the player.[/color]
   if ((oTarget == OBJECT_INVALID) || !GetIsObjectValid(oTarget))
       oTarget = GetFirstPC();

   [color=PaleGreen]// ST: If target has no inventory there is no point in proceeding further[/color]
   if (!GetHasInventory(oTarget))
       return FALSE;

   [color=PaleGreen]// ST: Just checking for at least one item...[/color]
   if (iCnt == 1) {
       return GetIsObjectValid(GetItemPossessedBy(oTarget, sTag)); 
   }
   [color=PaleGreen]// ST: Checking for more than one item.[/color]
   else {
       [color=PaleGreen]// ST: Shortcut, check if the first item of this type has enough in its stack.[/color]
       object oItem = GetItemPossessedBy(oTarget, sTag);
       if (GetItemStackSize(oItem) >= iCnt) {
           return TRUE;
       }
       [color=PaleGreen]// ST: If not, do the more complex inventory count check...[/color]
       else {
           int iSlot;
           int iFound = 0;

           [color=PaleGreen]// ST: First look in the equipped item slots.[/color]
           for (iSlot = INVENTORY_SLOT_HEAD; iSlot <= INVENTORY_SLOT_LEFTWEAPON2; iSlot++) {
               oItem = GetItemInSlot(iSlot, oTarget);
               if (GetTag(oItem) == sTag) {
                   iFound += GetItemStackSize(oItem);
               }
           }

           [color=PaleGreen]// ST: Then look in the backpack if we haven't found enough already.[/color]
           if (iFound < iCnt) {
               oItem = GetFirstItemInInventory(oTarget);
               while (GetIsObjectValid(oItem)) {
                   if (GetTag(oItem) == sTag) {
                       iFound += GetItemStackSize(oItem);
                   }
                   oItem = GetNextItemInInventory(oTarget);
               }
           }

           [color=PaleGreen]// ST: Have we found at least the specified amount?[/color]
           return (iFound >= iCnt);
       }
   }
}

Link to comment
Share on other sites

Hey, does anybody know what would I use in order to check if the PC has a certain amount of credits? Is there an sTag for credits or does it require something else? Thanks in advance :)

 

If this is for use in a dialog you can use a script like...

int StartingConditional() {
   return (GetGold(GetFirstPC()) >= [color=Yellow]100[/color]);  
}

...where you replace 100 with the amount of credits to check for.

Link to comment
Share on other sites

Thank you, that helped me out :) Unfortuantely I've encountered a problem with the first script stoffe wrote for me. I changed it slightly, mainly the first few lines to this:

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Main function - check for the presence of items.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int StartingConditional() {
   // ST: Example - return true and allow dialog node if the player has the needed items.
   return ST_HasItem("g_w_sbrcrstl42") && ST_HasItem("g_w_sbrcrstl43") && ST_HasItem("g_w_sbrcrstl18", 5) && ST_HasItem("g_i_gizkapois001");
}

 

The rest of the script is exactly how stoffe wrote it. Now, the problem is that it doesn't return true and the node doesn't fire, but another node for which I made a similiar script by modifying this one (which uses || instead of &&) works. Am I missing something?

 

Zgred_2, we have had to delete two 'bump' posts from you now, please do not bump your topics here. Forum Rules. Sorry. Perhaps use the PM system to ask stoffe about looking at this. Thanks. -RH

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...