Here's an excerpt from Weapon_SatchelCharge (
found here) which looks for a specific item in the player's inventory
for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
{
%item = %player.tool[%i];
if(%item == nameToID("satchelDetonatorItem"))
{
%foundDetonator = true;
}
}
You can replace the if statement code block with whatever you need it to do. For example, to remove the
satchelDetonatorItem, I'd do this
for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
{
%item = %player.tool[%i];
if(%item == nameToID("satchelDetonatorItem"))
{
%player.tool[%i] = 0;
%player.weaponCount--;
messageClient(%client, 'MsgItemPickup', '', %currTool, 0);
}
}
Now, I'm probably not interpreting your post correctly, but I'm assuming what's happening is you have some sort of locked box in your inventory, and in order to open you have to use the key, which will then remove the key and replace the locked box with an unlocked box. So I'd do something like this probably
function yourKeyImage::onFire(%this, %obj, %slot)
{
%client = %obj.client;
%player = %obj;
for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
{
%item = %player.tool[%i];
if(%item == nameToID("lockedBoxItem"))
{
%player.currTool = 0;
%player.weaponCount--;
messageClient(%client, 'MsgItemPickup', '', %player.currTool, 0);
%player.tool[%i] = nameToID("unlockedBoxItem");
messageClient(%client, 'MsgItemPickup', '', %i, nameToID("unlockedBoxItem"));
}
}
}
And what that function will do is, when you "fire" the key, it will look through the player's inventory, and for each inventory space, if there is a locked box, it will switch that locked box to an unlocked box, and remove the item the player is currently holding, which is most likely the key. If you only want it to unlock one box, you'd put
break; after
messageClient(%client, 'MsgItemPickup', '', %i, nameToID("unlockedBoxItem"));. I think. I haven't tested this.