Jump to content

Home

Checking to see if player has certain items


Recommended Posts

I'm working on an update to a mod I released a while back, and I need some help with making the scripts, as my knowledge of scripting couldn't fill a thimble.

 

I need a conditional script that checks the player's inventory to make sure they have certain items. Now, the individual items I know how to check for (using c_have_item as a source), but I don't know how to make it so that the script will return false only if the player has all of the items.

 

And is there any way to make a script that will return true if the player has a certain item in their inventory, but false if that item is equipped?

 

Any help would be most appreciated, and you'd receive full credit of course. :)

Link to comment
Share on other sites

And is there any way to make a script that will return true if the player has a certain item in their inventory, but false if that item is equipped?

 

Something like this would probably work:

int ST_HasUnequipped(string sTag, object oTarget=OBJECT_INVALID);

int StartingConditional() {
   return ST_HasUnequipped("[color=Yellow]SomeItemTag[/color]");
}


int ST_HasUnequipped(string sTag, object oTarget=OBJECT_INVALID) {
   [color=PaleGreen]// ST: No object specified to check: default to main character.[/color]
   if (!GetIsObjectValid(oTarget)) 
       oTarget = GetFirstPC();

   object oItem = GetItemPossessedBy(oTarget, sTag);

   [color=PaleGreen]// ST: Does not have item at all, condition not fulfilled.[/color]
   if (!GetIsObjectValid(oItem))
       return FALSE;

   [color=PaleGreen]// ST: Check if the item is equipped[/color]
   int iSlot;
   for (iSlot = INVENTORY_SLOT_HEAD; iSlot <= INVENTORY_SLOT_LEFTWEAPON2; iSlot++) {
       [color=PaleGreen]// ST: Item is equipped, condition not fulfilled.[/color]
       if (GetItemInSlot(iSlot, oTarget) == oItem)
           return FALSE;
   }

   [color=PaleGreen]// ST: Item was not equipped, condition fulfilled.[/color]
   return TRUE;
}

 

Replace SomeItemTag with the tag of the item to check for.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...