Jump to content

Home

Check for an item?


Hangout Hermit

Recommended Posts

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!

Link to comment
Share on other sites

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:

 


[color=PaleGreen]// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// 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.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[/color]
int ST_HasItemCount(object oOwner, string sTag, int iCount) {
   object oItem = GetItemPossessedBy(oOwner, sTag);

   [color=PaleGreen]// ST: Check if oOwner have any items with this tag.[/color]
   if (GetIsObjectValid(oItem)) {
   	[color=PaleGreen]// ST: An item was found, and the stack was large enough.[/color]
       if (GetItemStackSize(oItem) >= iCount) {   
           return TRUE;
       }
       [color=PaleGreen]// 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.[/color]
       else {
           oItem = GetFirstItemInInventory(oOwner);
           int iCnt = 0;
           while (GetIsObjectValid(oItem)) {
               if ((GetTag(oItem) == sTag)) {
                    iCnt += GetItemStackSize(oItem);
               }

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

               oItem = GetNextItemInInventory(oOwner);
           }
       }       
   }    

   return FALSE;
}


[color=PaleGreen]// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: The main function
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[/color]
void main()  {      
[color=PaleGreen]// ST: Check if there are at least 51 "hh_egg" objects in
//     the player inventory.[/color]
   if (ST_HasItemCount(GetFirstPC(), "hh_egg", 51)) {
       ActionStartConversation(GetFirstPC(),"finnish");
   }
   else {
       ActionStartConversation(GetFirstPC(),"fail");
   }
}


Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...