Author Topic: Max of a specific item that can be in your inventory at a time  (Read 643 times)




Can't have more than 1 of "item" in your inventory
So you're asking about why you pick up a gun the first time you run over it but you don't get a second one when you run over it a second time

I think he wants to have a weapon that allows you to pick up more than one, but with a limit, so you can't fill your inventory with them

Easy enough, just to see how check pretty much any grenade script and you could add a limit by adding 1 to 2 lines of code to it.

I have compared an item that can be mounted many times compared to an item that can only be mounted once, and honestly could not find it

In Weapon_HEGrenade.cs, turn this
Code: [Select]
package HEGrenadePackage
{
function Armor::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
{
if(%col.dataBlock $= "HEGrenadeItem" && %col.canPickup)
{
for(%i=0;%i<%this.maxTools;%i++)
{
%item = %obj.tool[%i];
if(%item $= 0 || %item $= "")
{
%freeSlot = 1;
break;
}
}

if(%freeSlot)
{
%obj.pickup(%col);
return;
}
}
Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
}
};
activatePackage(HEGrenadePackage);

into this
Code: [Select]
package HEGrenadePackage
{
function Armor::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
{
if(%col.dataBlock $= "HEGrenadeItem" && %col.canPickup)
{
for(%i=0;%i<%this.maxTools;%i++)
{
%item = %obj.tool[%i];
if(%item $= 0 || %item $= "")
{
%freeSlot = 1;
break;
}
}

if(%freeSlot && %obj.maxPick <= 3) //The only two edits are here...
{
%obj.pickup(%col);
%obj.maxPick++; //and here!
return;
}
}
Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
}
};
activatePackage(HEGrenadePackage);
and it should work fine, just to use it for your weapon change the image name to the proper thing, etc etc

edit: forgot to mention, this will allow 3 of the item in the inventory, jsut change the 3 in the first edited line to whatever number you want. ALSO if the item gets used up in whatever way make sure to include something to minus the maxPick variable. You will also need to package serverCmdDropTool to minus the maxPick variable when the item is dropped

Code: [Select]
function serverCmdDropTool(%client, %i)
{
//stuff
        parent::serverCmdDropTool(%client, %i);
}
« Last Edit: September 26, 2012, 08:32:37 PM by HellsHero »

That's pretty stuffty, if someone gets or loses a weapon in any of the other ways possible other than touching it or dropping it, it won't be counted.
Add a check in the for loop to see if the slot being checked is the tool you want, and if it is, increment a variable.
Then, after the for loop, check if that variable is >= the max amount allowed