// note: I'm treating "itemstack" as an object type that contains the following information:
// quantity = How many items are in the stack type = {"Reagent","Collectable","Weapon", etc}
// itemcode = The game's definition of the specific items, probably an integer.
// Spell is an object type that contains things like the spell level, whether it needs reagents, energy cost, damage, targetting info,
Code:
boolean Spell.GetReagent(int item) // Returns "false" if not found, so calling routine would error out)
{
for bag = 1 to player.maxbagnumber do
for slot = 1 to player.bag[bag].bagslots do
local bagitem = player.bagslot[bag,slot] // player.bagslot is an array of itemstack objects
if bagitem.itemcode == item then // Found the reagent we're looking for
bagitem.quantity = bagitem.quantity - 1;
return(true);
end
end
end
return(false)
}
Now this is probably vastly oversimplified, but I wanted it to be easy to read and follow. What it appears to be doing is looping through the character's bags looking for a specific ITEMCODE rather than a specific ITEM TYPE - The only thing needed would be to do this instead (Assumes the existance of a method GetItemName(itemcode) that returns a string containing the name of an item associated with the itemcode.
Code:
boolean Spell.GetReagent(int item) // Returns "false" if not found, so calling routine would error out)
{
for bag = 1 to player.maxbagnumber do
for slot = 1 to player.bag[bag].bagslots do
local bagitem = player.bagslot[bag,slot] // player.bagslot is an array of itemstack objects
if GetItemName(bagitem.itemcode) == GetItemName(item) then // Found the reagent we're looking for
bagitem.quantity = bagitem.quantity - 1;
return(true);
end
end
end
return(false)
}
And that's it...by comparing the NAMES rather than the CODE, both items with the name "Level 3 Inscription materials" will work, even if they have different item codes.