Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

[K1] Help with item requirement scripts for dialogs.

Page: 1 of 1
 Zgred_2
11-05-2007, 12:35 PM
#1
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 :)
 stoffe
11-06-2007, 7:23 AM
#2
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);


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


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

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

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

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

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

// ST: Have we found at least the specified amount?
return (iFound >= iCnt);
}
}
}
 Zgred_2
11-06-2007, 4:19 PM
#3
Thank you! Stoffe, once again you prove that you are god :) Thanks, I'm off to try this, if I have any problems I'll reply to this thread.
 Zgred_2
11-08-2007, 12:14 PM
#4
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 :)
 stoffe
11-08-2007, 4:40 PM
#5
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()) >= 100);
}

...where you replace 100 with the amount of credits to check for.
 Zgred_2
11-10-2007, 8:24 AM
#6
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 (http://www.lucasforums.com/showthread.php?t=169078). Sorry. Perhaps use the PM system to ask stoffe about looking at this. Thanks. -RH
Page: 1 of 1