Author Topic: Removing an item upon use from someones inventory.  (Read 890 times)

I have an item that i'd like to be removed upon it being used, what should I put into the script to do that?

Try this, in the onFire function of the item:

Code: [Select]
function sampleItemImage::onFire(%this, %obj, %slot) {
    %client = %obj.client;
   
    if (isObject(%obj)) {
        %obj.tool[%obj.currTool] = 0;
        %obj.weaponCount--;
   
        messageClient(%client, 'MsgItemPickup', '', %obj.currTool, 0);
        serverCmdUnUseTool(%client);
    }
}

Try this, in the onFire function of the item:

Code: [Select]
function sampleItemImage::onFire(%this, %obj, %slot) {
    %client = %obj.client;
   
    if (isObject(%obj)) {
        %obj.tool[%obj.currTool] = 0;
        %obj.weaponCount--;
   
        messageClient(%client, 'MsgItemPickup', '', %obj.currTool, 0);
        serverCmdUnUseTool(%client);
    }
}
Doesn't seem to be working, the item stays in the players inventory.

Doesn't seem to be working, the item stays in the players inventory.

I forgot to mention that you have to change sampleItemImage to whatever the item's image is actually called. If the item you have already has an onFire function, can you post it here?

I forgot to mention that you have to change sampleItemImage to whatever the item's image is actually called. If the item you have already has an onFire function, can you post it here?
Woops, just realized I only changed the sample part, and not Item. It works now, my bad.
However, it seems to get removed before it actually fires. Is there a way to delay the removal?

Woops, just realized I only changed the sample part, and not Item. It works now, my bad.
However, it seems to get removed before it actually fires. Is there a way to delay the removal?

I guess you could try packaging it, try (replace with) this:

Code: [Select]
function sampleImage::onFire(%this, %obj, %slot) { // change sampleImage to the actual item image
Parent::onFire(%this, %obj, %slot);

%client = %obj.client;

if (isObject(%obj)) {
%obj.tool[%obj.currTool] = 0;
%obj.weaponCount--;

messageClient(%client, 'MsgItemPickup', '', %obj.currTool, 0);
serverCmdUnUseTool(%client);
}
}
« Last Edit: July 31, 2016, 06:08:44 PM by Paperwork »

I guess you could try packaging it, try (replace with) this:

Code: [Select]
if (isPackage(itemDelayRemoval))
deactivatePackage(itemDelayRemoval);

package itemDelayRemoval {

function sampleImage::onFire(%this, %obj, %slot) { // change sampleImage to the actual item image
Parent::onFire(%this, %obj, %slot);

%client = %obj.client;

if (isObject(%obj)) {
%obj.tool[%obj.currTool] = 0;
%obj.weaponCount--;

messageClient(%client, 'MsgItemPickup', '', %obj.currTool, 0);
serverCmdUnUseTool(%client);
}
}

};

activatePackage(itemDelayRemoval); // not the best package name I could come up with
It works, thank you!

Woops, just realized I only changed the sample part, and not Item. It works now, my bad.
However, it seems to get removed before it actually fires. Is there a way to delay the removal?
did you leave out the parent::onfire?
cause im pretty sure the package is not needed.

did you leave out the parent::onfire?
cause im pretty sure the package is not needed.

Code amended, I left it out originally because I believed you could only parent inside packages - but on second thought that doesn't actually make sense.