244 lines
7.0 KiB
Plaintext
244 lines
7.0 KiB
Plaintext
//::///////////////////////////////////////////////
|
|
//:: Item Combination Activation Script Revision 2
|
|
//:: FileName
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Giolon
|
|
//:: Created On: 9/16/02, Last Rev on 10/2/02
|
|
//:://////////////////////////////////////////////
|
|
|
|
#include "array_functions"
|
|
|
|
int GetRecipeNumber(object oChest, int nNumRecipes);
|
|
int CheckRecipe(object oChest, int nRecipeNumber);
|
|
void DeleteAllItems(object oChest);
|
|
void CreateReward(object oChest, int nRecipeNumber);
|
|
int GetNumItemsInInventory(object oChest);
|
|
void DelAllItemChecks(object oChest);
|
|
|
|
/* Checks to see if a valid item combination has been put into the chest,
|
|
if so it creates the resultant item, if not it does whatever you put in
|
|
to tell it to do.
|
|
*/
|
|
void main()
|
|
{
|
|
object oChest = OBJECT_SELF;
|
|
int nNumRecipes = GetLocalInt(oChest, "NUM_RECIPES");
|
|
|
|
int nRecipeNumber = GetRecipeNumber(oChest, nNumRecipes);
|
|
|
|
if (nRecipeNumber == -1) { //This is for if no "key" item could be found.
|
|
/* Insert Bad Stuff to Happen Here */
|
|
DeleteAllItems(oChest); //Optional
|
|
} else if (CheckRecipe(oChest, nRecipeNumber)) { //This is for success.
|
|
DeleteAllItems(oChest);
|
|
CreateReward(oChest, nRecipeNumber);
|
|
} else { // This is if a correct combination could not be found.
|
|
/* Insert Bad Stuff to Happen Here */
|
|
DeleteAllItems(oChest); //Optional
|
|
}
|
|
|
|
}
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: GetRecipeNumber
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
|
|
Retrieves the number ID of the recipe as set up in the chest_spawn file.
|
|
The number ID is determined by the "key" item which is the first item in each
|
|
recipe.
|
|
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Giolon
|
|
//:: Created On: 9/16/02
|
|
//:://////////////////////////////////////////////
|
|
|
|
|
|
int GetRecipeNumber(object oChest, int nNumRecipes) {
|
|
int i;
|
|
|
|
for (i = 1; i <= nNumRecipes; i++) {
|
|
object oItem = GetFirstItemInInventory(oChest);
|
|
object oFirstItem = GetFirstItemInInventory(oChest);
|
|
|
|
|
|
string sRecipeName = GetLocalArrayString(oChest, "RECIPE", i);
|
|
string sTestReagent = GetLocalArrayString(oChest, sRecipeName, 1);
|
|
|
|
while (GetIsObjectValid(oItem) == TRUE) {
|
|
if (GetTag(oItem) == sTestReagent) {
|
|
if (GetLocalInt(oChest, "ENABLE_ONE_TIME_RECIPES")
|
|
&& GetLocalInt(oChest, sRecipeName + "ONE_TIME_RECIPE")) {
|
|
if (GetLocalInt(oChest, sRecipeName + "ALREADY_MADE")) {
|
|
i = -1;
|
|
}
|
|
}
|
|
return i;
|
|
}
|
|
oItem = GetNextItemInInventory(oChest);
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: CheckRecipe
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
|
|
This checks to see if all the right items are present in the recipe. By
|
|
default, this includes checking for extra items.
|
|
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Giolon
|
|
//:: Created On: 9/16/02
|
|
//:://////////////////////////////////////////////
|
|
|
|
|
|
int CheckRecipe(object oChest, int nRecipeNumber) {
|
|
|
|
string sRecipeName = GetLocalArrayString(oChest, "RECIPE", nRecipeNumber);
|
|
int nNumReagents = GetLocalArrayInt(oChest, "NUM_COMPONENTS", nRecipeNumber);
|
|
int bCorrectRecipe = TRUE;
|
|
|
|
string sCurrentReagent;
|
|
int i, j;
|
|
|
|
/* Change the '!=' to '<' if you don't care about extra ingredients. */
|
|
|
|
if (GetNumItemsInInventory(oChest) != nNumReagents) {
|
|
return FALSE;
|
|
}
|
|
|
|
for (i = 1; i <= nNumReagents; i++) {
|
|
object oItem = GetFirstItemInInventory(oChest);
|
|
sCurrentReagent = GetLocalArrayString(oChest, sRecipeName, i);
|
|
|
|
for (j = 1; j <= nNumReagents; j++) {
|
|
|
|
if (GetLocalInt(oItem, "ALREADY_CHECKED") != 1) {
|
|
if (GetTag(oItem) == sCurrentReagent) {
|
|
SetLocalInt(oItem, "ALREADY_CHECKED", 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
oItem = GetNextItemInInventory(oChest);
|
|
}
|
|
if (j > nNumReagents) bCorrectRecipe = FALSE;
|
|
}
|
|
DelAllItemChecks(oChest);
|
|
|
|
return bCorrectRecipe;
|
|
}
|
|
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: DeleteAllItems
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
Deletes all the items in an object's inventory.
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Giolon
|
|
//:: Created On: 9/16/02
|
|
//:://////////////////////////////////////////////
|
|
|
|
|
|
void DeleteAllItems(object oChest) {
|
|
object oItem = GetFirstItemInInventory(oChest);
|
|
|
|
while (GetIsObjectValid(oItem)) {
|
|
DestroyObject(oItem);
|
|
oItem = GetNextItemInInventory(oChest);
|
|
}
|
|
}
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: CreateReward
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
Creates the reward item for the recipe as determined
|
|
by the recipe ID number.
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Giolon
|
|
//:: Created On: 9/16/02
|
|
//:://////////////////////////////////////////////
|
|
|
|
|
|
void CreateReward(object oChest, int nRecipeNumber) {
|
|
string sRecipeName = GetLocalArrayString(oChest, "RECIPE", nRecipeNumber);
|
|
string sRewardResRef = GetLocalString(oChest, sRecipeName + "Reward");
|
|
|
|
if (GetLocalInt(oChest, "ENABLE_ONE_TIME_RECIPES")) {
|
|
SetLocalInt(oChest, sRecipeName + "ALREADY_MADE", 1);
|
|
}
|
|
|
|
CreateItemOnObject(sRewardResRef, oChest);
|
|
}
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: GetNumItemsInInventory
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
|
|
Returns the number of items in the object's inventory.
|
|
This includes items in a stack.
|
|
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Giolon
|
|
//:: Created On: 9/16/02
|
|
//:://////////////////////////////////////////////
|
|
|
|
|
|
int GetNumItemsInInventory(object oChest) {
|
|
int nNumItems = 0;
|
|
object oItem = GetFirstItemInInventory(oChest);
|
|
|
|
while (GetIsObjectValid(oItem)) {
|
|
nNumItems += GetNumStackedItems(oItem);
|
|
oItem = GetNextItemInInventory(oChest);
|
|
}
|
|
|
|
return nNumItems;
|
|
|
|
}
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: DelAllItemChecks
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
|
|
Destroys the checked state of an item for use in matching correct recipes.
|
|
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Giolon
|
|
//:: Created On: 10/2/02
|
|
//:://////////////////////////////////////////////
|
|
|
|
void DelAllItemChecks(object oChest) {
|
|
object oItem = GetFirstItemInInventory(oChest);
|
|
|
|
while (GetIsObjectValid(oItem)) {
|
|
DeleteLocalInt(oItem, "ALREADY_CHECKED");
|
|
oItem = GetNextItemInInventory(oChest);
|
|
}
|
|
}
|
|
|