So Ive expanded this into a generic Crafting Table - Which almost works :)
Its called from a conversation on crafting bench which lists recipes. When you pick the recipe response the script fires. The void main sets the Vars to the table for the particular recipe, and my attempt at functions then runs the combine as per the last script. It tells me if I dont have enough of the first ingrdient but then goes dead somewhere - Any insights?
#include “nw_i0_plot”
void RemoveNumItems(object oTarget, string sItemTag, int nNumItems);
void CombineComponents (object oPC);
//** MAIN ** //
void CombineComponents (object oPC)
{
object oSelf = OBJECT_SELF; // container
string sComponent1 = GetLocalString (OBJECT_SELF,“component1”); // tag of the 1st thing to make from
string sComponent2 = GetLocalString (OBJECT_SELF,“component2”); // tag of the 2nd thing to make from
string sComponent3 = GetLocalString (OBJECT_SELF,“component3”); // tag of the 3rd thing to make from
string sGive = GetLocalString (OBJECT_SELF, “product”); // resref of the thing to make
int iComponent1 = GetLocalInt (OBJECT_SELF,“component1num”); // how many to make from
int iComponent2 = GetLocalInt (OBJECT_SELF,“component2num”); // how many to make from
int iComponent3 = GetLocalInt (OBJECT_SELF,“component3num”); // how many to make from
int iNumGive = GetLocalInt (OBJECT_SELF,“productnum”); // how many to make
int iCurrent1 = GetNumItems(oPC, sComponent1); // get how many on PC
int iCurrent2 = GetNumItems(oPC, sComponent2); // get how many on PC
int iCurrent3 = GetNumItems(oPC, sComponent3); // get how many on PC
int iDifficulty = GetLocalInt (OBJECT_SELF, “difficulty”); // recipe difficulty
string sTradeskill = GetLocalString (OBJECT_SELF,“tradeskill”); // tradeskill attempting
int iSkill = GetCampaignInt (“trades”,sTradeskill,oPC); //current tradeskill of player
// check they have enough
if (iCurrent1<iComponent1)
FloatingTextStringOnCreature(“You do not have enough “+sComponent1+” to do this.”,oPC,FALSE);
return;
if (iCurrent2<iComponent2)
FloatingTextStringOnCreature(“You do not have enough “+sComponent2+” to do this.”,oPC,FALSE);
return;
if (iCurrent3<iComponent3)
FloatingTextStringOnCreature(“You do not have enough “+sComponent3+” to do this.”,oPC,FALSE);
return;
//OK they have enough
// play animation
// Have the PC perform a sequence of actions.
AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0, 6.0));
//Check Skill passed
int iRan = Random(1000); //roll random1-1000
int iChance = (iSkill+iDifficulty); // base skill plus difficulty
int ibadfailchance = (iChance+iChance);
// process materials for Bad Fail
if (iRan>ibadfailchance)
{
RemoveNumItems(oPC, sComponent1, iComponent1);
RemoveNumItems(oPC, sComponent2, iComponent2);
RemoveNumItems(oPC, sComponent3, iComponent3);
FloatingTextStringOnCreature("You Mangled the Components",oPC,FALSE);
return;
}
// Processmaterials for fail but include skill up chance
if (iRan>iChance)
{
RemoveNumItems(oPC, sComponent1, iComponent1);
RemoveNumItems(oPC, sComponent2, iComponent2);
RemoveNumItems(oPC, sComponent3, iComponent3);
FloatingTextStringOnCreature("You Failed to create anything",oPC,FALSE);
// check for skillup
int iSkillup = Random (100);
if (iSkillup<10)
{
iSkill =(iSkill+1);
string sSkillpoints = IntToString(iSkill);
FloatingTextStringOnCreature("You Managed to raise your skill to "+sSkillpoints,oPC,FALSE);
SetCampaignInt ("trades",sTradeskill,iSkill,oPC);
return;
}
}
// good to go for success
RemoveNumItems(oPC, sComponent1, iComponent1);
RemoveNumItems(oPC, sComponent2, iComponent2);
RemoveNumItems(oPC, sComponent3, iComponent3);
FloatingTextStringOnCreature("You Have Succeeded",oPC,FALSE);
CreateItemOnObject(sGive, oPC, iNumGive);
// check for skillup
int iSkillup = Random (100);
if (iSkillup<20)
{
iSkill =(iSkill+1);
string sSkillpoints = IntToString(iSkill);
FloatingTextStringOnCreature("You Managed to raise your skill to "+sSkillpoints,oPC,FALSE);
SetCampaignInt ("trades",sTradeskill,iSkill,oPC);
return;
}
}
//
void RemoveNumItems(object oTarget, string sItemTag, int nNumItems)
{
int nCount, nStack;
object oItem = GetFirstItemInInventory(oTarget);
while (GetIsObjectValid(oItem) && nCount < nNumItems)
{
if (GetTag(oItem) == sItemTag)
{
nStack = GetItemStackSize(oItem);
if ((nNumItems - nCount) >= nStack)
{
DestroyObject(oItem, 0.2f);
nCount += nStack;
}
else
{
SetItemStackSize(oItem, nStack - nNumItems + nCount);
nCount += nNumItems - nCount;
}
}
oItem = GetNextItemInInventory(oTarget);
}
}
void main()
{
object oPC = GetPCSpeaker(); //change depending on container/conversation etc
SetLocalString (OBJECT_SELF,"component1","SEED_GRAPE2"); // tag of the 1st thing to make from
SetLocalString (OBJECT_SELF,"component2","ITEM_GRAPEFRUIT"); // tag of the 2nd thing to make from
SetLocalString (OBJECT_SELF,"component3",""); // tag of the 3rd thing to make from
SetLocalString (OBJECT_SELF, "product","item_juice_001"); // resref of the thing to make
SetLocalInt (OBJECT_SELF,"component1num",1); // how many to make from
SetLocalInt (OBJECT_SELF,"component2num",1); // how many to make from
SetLocalInt (OBJECT_SELF,"component3num",0); // how many to make from
SetLocalInt (OBJECT_SELF,"productnum",3); // how many to make
SetLocalInt (OBJECT_SELF, "difficulty",500); // recipe difficulty
SetLocalString (OBJECT_SELF,"tradeskill","Brewing"); // tradeskill attempting
CombineComponents (oPC);
}