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.

Check for an item?

Page: 1 of 1
 Hangout Hermit
02-04-2007, 1:04 PM
#1
Hello! :waive1:

I was wondering if there are any script functions that could check if i have a certan number of an item and if i have that number then fire a dlg file. I have tried the GetItemStackSize function but it dosen't seem to be able to pick up the item template and/or the number. Here is the script i have made so far:


void main(){

GetItemStackSize( GetFirstPC(),"hh_egg");

if (GetItemStackSize = 51){
ActionStartConversation(GetFirstPC(),"finnish");
}
else{
ActionStartConversation(GetFirstPC(),"fail");
}
}


I know that it is incorrect, but i can't find the correct function.

Thanks!
 Master Zionosis
02-04-2007, 1:17 PM
#2
Now i know there is a command for this, but as i am a beginner scripter i cant remember what the command would be, i think it was something like check for item in inventory, or something like that, but i know stoffe will know the command as she is like the scripting master.
 stoffe
02-04-2007, 1:24 PM
#3
Hello! :waive1:

I was wondering if there are any script functions that could check if i have a certan number of an item and if i have that number then fire a dlg file. I have tried the GetItemStackSize function but it dosen't seem to be able to pick up the item template and/or the number.

I don't think the scripting language has a function built in that does this, but you can do that easily by making a re-usable function of your own that checks if the player has an item and have the desired amount of it in their inventory. It may look something like this:



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: Custom function to check if oOwner has the specified
// amount of an item in their inventory. If oOwner is set to
// GetFirstPC() it will check in the party inventory.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int ST_HasItemCount(object oOwner, string sTag, int iCount) {
object oItem = GetItemPossessedBy(oOwner, sTag);

// ST: Check if oOwner have any items with this tag.
if (GetIsObjectValid(oItem)) {
// ST: An item was found, and the stack was large enough.
if (GetItemStackSize(oItem) >= iCount) {
return TRUE;
}
// ST: An item was found, but the stack was not large enough.
// Check if oOwner have any other stacks with this item
// in their inventory and count the total in all stacks.
else {
oItem = GetFirstItemInInventory(oOwner);
int iCnt = 0;
while (GetIsObjectValid(oItem)) {
if ((GetTag(oItem) == sTag)) {
iCnt += GetItemStackSize(oItem);
}

// ST: Enough items have been found.
if (iCnt >= iCount) {
return TRUE;
}

oItem = GetNextItemInInventory(oOwner);
}
}
}

return FALSE;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: The main function
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void main() {
// ST: Check if there are at least 51 "hh_egg" objects in
// the player inventory.
if (ST_HasItemCount(GetFirstPC(), "hh_egg", 51)) {
ActionStartConversation(GetFirstPC(),"finnish");
}
else {
ActionStartConversation(GetFirstPC(),"fail");
}
}
 Hangout Hermit
02-04-2007, 1:28 PM
#4
As far as i know there isn't a Check for item in inventory, but there is a GetItemInSlot, GetFirstItemInInventory and GetNextItemInInventory. The GetItemInSlot will check for an item in a slot but the item that i'm using is unequipable. The GetFirstItemInInventory will get the first item in the inventory. The GetNextItemInInventory will get the next item in the inventory. But thanks for your time.

Thanks for the scirpt STOFFE :D
Page: 1 of 1