Frustrated attempt at counting items in a placable's inventory.
#1
Posté 28 février 2012 - 03:03
I've been trying to get this working for days but it seems no matter how I change things it -refuses- to give me what I need.
What I need it to do is to check the inventroy and look for objects tagged as cooking ingredients (hence "mzs_cooking_") Then I need to know if those items are in excess of what the container can hold (defined by the iCapacity variable) and we can go from there. However it's just -not- printing anything out when I try to load it. I've placed this script on a placables 'on close' for reference. Any help would be -hugely- appriciated. It's driving me quite litterally mad. >.>
int GetCookingItems(object oTarget)
{
int nNumItems = 0;
object oItem = GetFirstItemInInventory(oTarget);
string sObjects = GetTag(oItem);
string sIngredientL = GetStringLeft(sObjects, 12);
while (GetIsObjectValid(oItem) == TRUE)
{
if (sIngredientL == "mzs_cooking_")
{
nNumItems +1;
}
oItem = GetNextItemInInventory(oTarget);
}
return nNumItems;
}
void main()
{
object oPC = GetLastClosedBy();
object oCooker = OBJECT_SELF;
object oContents = GetFirstItemInInventory(OBJECT_SELF);
string sObjects = GetTag(oContents);
string sIngredientL = GetStringLeft(sObjects, 12);
int nNumItems;
int iCount;
int nMarkCount = 1;
string sCount = IntToString (nNumItems);
if(GetCookingItems(oCooker) >= nMarkCount)
{
SendMessageToPC (oPC, "Too much " +sCount+ " ");
}
}
#2
Posté 28 février 2012 - 03:20
void main()
{
object oTest = GetFirstItemInInventory(OBJECT_SELF);
int iCount = 0;
while(GetIsObjectValid(oTest))
{
if(GetStringLeft(GetTag(oTest), 12) == "mzs_cooking_")
{
iCount++;
}
oTest = GetNextItemInInventory(OBJECT_SELF);
}
SendMessageToPC (GetLastClosedBy(), "Cooking item count " +IntToString(iCount)+ " ");
}
*I haven't compiled/tested this script. It's just an example.
Modifié par Alex Warren, 28 février 2012 - 03:22 .
#3
Posté 28 février 2012 - 03:33
Thanks a lot, Alex. I'll have to keep this in mind in the future. Much obliged!
#4
Posté 29 février 2012 - 04:13
Sorry to sound like a pain but uh. . . Well, here goes. What I need to do is get variables (ints in this case) from the loop so I know what ingredients we're trying to cook. I've tried several different things but nothing seems to return a useful/usable thing. Can anyone toss some ideas my way that might help? I've been poking around on the internet but all I'm finding are tutorials or -very- complex (primarily forge) scripts on the Vault that're just way, way out of my leauge tat this moment. Heh Any help would be greatly appriciated!
while(GetIsObjectValid(oTest))
{
if(GetStringLeft(GetTag(oTest), 12) != "mzs_cooking_")
{
SendMessageToPC (GetLastClosedBy(), "You can't cook this.");
return;
}
if(GetTag(oTest) == "mzs_cooking_base")
{
iBaseCount ++;
}
if(GetStringLeft(GetTag(oTest), 12) == "mzs_cooking_" && GetStringRight (GetTag(oTest), 5) != "_base")
{
//Trying to get ints from individual items, in any order, hasn't worked here.
iCount ++;
}
oTest = GetNextItemInInventory(OBJECT_SELF);
}
if (iBaseCount == 0)
{
SendMessageToPC (GetLastClosedBy(), "You need something to cook in.");
}
else if (iBaseCount > 1)
{
SendMessageToPC (GetLastClosedBy(), "You can't have more than one cooking appliance on the stove at a time.");
}
else if (iBaseCount = 1)
{
if(iCount > iCapacity)
{
SendMessageToPC (GetLastClosedBy(), "There's too much stuff to cook properly.");
return;
}
else if (iCount <= iCapacity)
{
SetLocalString (OBJECT_SELF, "Cooking", sBaseType);
string sIng1 = GetTag(oTest);
SetLocalString (OBJECT_SELF, "Ingredient1", "" +sIng1+ "");
//Nor here.
SendMessageToPC (GetLastClosedBy(), "DEBUG: Base Type: " +sBaseType+ "");
SendMessageToPC (GetLastClosedBy(), "DEBUG: Capacity is: " +IntToString(iCapacity)+ ", Item count is: " +IntToString(iCount)+ " ");
}
}
}
#5
Posté 29 février 2012 - 04:50
Edit: Ok just reread above and cleaned the script up a bit more. Hopefully it gets you closer.
void main()
{
object oPC = GetLastClosedBy();
object oPot = OBJECT_SELF;
int iCount = 0;//?
int iBaseCount = 0;//?
int iCapacity = 0;//?
string sBaseType = "";//?
object oTest = GetFirstItemInInventory(oPot);
while(GetIsObjectValid(oTest))
{
if(GetStringLeft(GetTag(oTest), 12) != "mzs_cooking_")
{
SendMessageToPC (oPC, "You can't cook this.");
return;
}
if(GetTag(oTest) == "mzs_cooking_base")
{
iBaseCount ++;
}
if (GetStringLeft(GetTag(oTest), 12) == "mzs_cooking_" &&
GetStringRight (GetTag(oTest), 5) != "_base")
{
//Trying to get ints from individual items, in any order, hasn't worked here.
iCount ++;
}
oTest = GetNextItemInInventory(oPot);
}
if (iBaseCount == 0)
{
SendMessageToPC (oPC, "You need something to cook in.");
}
else if (iBaseCount > 1)
{
SendMessageToPC (oPC, "You can't have more than one cooking appliance on the stove at a time.");
}
else if (iBaseCount == 1)
{
if(iCount > iCapacity)
{
SendMessageToPC (oPC, "There's too much stuff to cook properly.");
return;
}
else if (iCount <= iCapacity)
{
SetLocalString (OBJECT_SELF, "Cooking", sBaseType);
string sIng1 = GetTag(oTest);
SetLocalString (OBJECT_SELF, "Ingredient1", "" +sIng1+ "");
//Nor here.
SendMessageToPC (oPC, "DEBUG: Base Type: " +sBaseType+ "");
SendMessageToPC (oPC, "DEBUG: Capacity is: " + IntToString(iCapacity)+
", Item count is: " + IntToString(iCount)+ " ");
}
}
}
Modifié par GhostOfGod, 29 février 2012 - 06:16 .
#6
Posté 29 février 2012 - 02:08
There's a missing =GhostOfGod wrote......
else if (iBaseCount = 1)
else if (iBaseCount == 1)
#7
Posté 29 février 2012 - 06:14
Failed.Bard wrote...
There's a missing =GhostOfGod wrote......
else if (iBaseCount = 1)
else if (iBaseCount == 1)
Oh I missed that one. Good caatch. Fixed.
Modifié par GhostOfGod, 29 février 2012 - 06:15 .
#8
Posté 01 mars 2012 - 01:03
What I'm trying to do is set it up so that the loop goes through the inventory of the script caller and finds out which ingredients are inside. After that it writes the ingredient list to the cooker itself so they can be retrieved later. However I'm not entirely sure how to do that. . . Would I require another loop or something else? So far all I've been able to get out of it is the first item it finds. Is there any way to retrieve -all- the items within the inventory?
Something maybe akin to
while (GetIsObjectValid (oInv))
{
sItemTag = GetTag(oInv);
sItemName = GetName(oInv, FALSE);
SetLocalString ("Ingredient 1", sItemName);
// Debug Line
SpeakString ("" + sItemTag + ":" + sItemName + "");
oInv = GetNextItemInInventory(oCooker);
}
I've tried this one and variations on it but I never seem to get it to write the list of all inventory items within the caller. It needs to specifically ignore any 'base' items (tagged mzs_cooking_base) but retain all the ingredient items. (usually tagged mzs_cooking_ingredient) there are variables on the Ingredient items themselves that identify them as what they are. That'll be passed to the oven placable and then handled by another script later on in the process.
Sorry if this is a bit confusing, I haven't had my morning coffee.
#9
Posté 01 mars 2012 - 08:23
void main()
{
int nCount = 0;
while (GetIsObjectValid (oInv))
{
nCount++;
sItemTag = GetTag(oInv);
sItemName = GetName(oInv, FALSE);
SetLocalString (OBJECT_SELF, "Ingredient " + IntToString(nCount), sItemName);
// Debug Line
SpeakString ("" + sItemTag + ":" + sItemName + "");
oInv = GetNextItemInInventory(oCooker);
}
if(nCount) SetLocalInt(OBJECT_SELF, "Total Ingredients", nCount);
}
#10
Posté 02 mars 2012 - 01:42
WhiZard wrote...
Below fixes your system so that it will record all ingredients and have an identifier telling how many ingredients to look for.
void main()
{
int nCount = 0;
object oInv = GetFirstItemInInventory(oCooker);
while (GetIsObjectValid (oInv))
{
nCount++;
sItemTag = GetTag(oInv);
sItemName = GetName(oInv, FALSE);
SetLocalString (OBJECT_SELF, "Ingredient " + IntToString(nCount), sItemName);
// Debug Line
SpeakString ("" + sItemTag + ":" + sItemName + "");
oInv = GetNextItemInInventory(oCooker);
}
if(nCount) SetLocalInt(OBJECT_SELF, "Total Ingredients", nCount);
}
Modifié par Lightfoot8, 02 mars 2012 - 01:43 .
#11
Posté 02 mars 2012 - 08:01
Er, where is oCooker defined?
<...until he can't wait no more>
#12
Posté 02 mars 2012 - 10:35
Rolo Kipp wrote...
<waiting...>
Er, where is oCooker defined?
<...until he can't wait no more>
It isn't declared, nor are sItemTag or sItemName declared as strings. I am assuming what was posted was a short snippet from a longer script
#13
Posté 03 mars 2012 - 03:33
Well, thanks a lot for the help! I'll see if I can't get something workable and then I'll post it up here incase someone needs it in the future. Thanks a lot for your time!





Retour en haut






