Author Topic: Is this possible with Inventory items/weapons?  (Read 3583 times)

Alright so I'll try to explain my thought process as best as I can but there's a lot flowing through me right now. I appreciate all the tips on this one as I'm not sure if it's possible but I feel like it is I just don't have a clue how to go about it.
------------------------------------------------------------------------------------------------------------------------------

Q1: Is it possible to require an item in your (default) BL inventory in order to use another? For example, if I had a lock item in my inventory, I wouldn't be able to right-click to open it without first having a key item in my inventory. But I wouldn't select the key, I would only need to have it in my inventory.

    - Then can I delete the key item from my inventory? Or automagically drop it and have it instantly de-spawn or something or another?

Q2: Is it possible to have "durability" or ammo usage for an item in my inventory. For example, if I had a gun item in my inventory as well as an ammo pack item, obviously "using/shooting" (left-click) the gun would use ammo or "durability" on the separate item and then removing the ammo pack item from my inventory and I wouldn't be able to use the gun without then picking up another ammo pack item.

Q3: Is it possible to change a snippet of code or how an item is used by "using" (right-clicking?) a different item in my inventory? For example, if I had a gun item, and also a "gun upgrade" (or something) item, and if I "used" (right-clicked) the upgrade item and it disappeared but then increased my gun firing rate by 1.5x or something and would be a permanent upgrade until I removed the gun item from my inventory.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Just some ideas I had, if any of this is do-able please enlighten me :) Thanks!

all of this is doable. it's mostly just triggers and values stored on the player

all of this is doable. it's mostly just triggers and values stored on the player

eyyyyyy well that's good to hear! I don't really have any experience with "values stored on player" but I'm sure some digging will uncover some useful stuffs. Would like to see some other responses on this as well tho of course.

player.value = 5;

that's what it means. you store stuff like player.durability[itemname] = 10; and then you can access it for that specific item or its id

Yes, yes, and  yes.

The first one is simple. Loop through the player's items and check if they have the other one. Remove it if necessary.

Second one is a little more complicated. There were a set of guns that actually required you to have ammo in your items to use them. Though I'm sure for simplicity's sake you can probably again just loop through the inventory till the thing is found.

Third one is similar to the first one. Make a separate datablock for the upgraded gun. When the upgrade item is used, search the player's inventory for the gun, if it's found, remove the upgrade from the inventory, and replace the gun with the upgraded gun.

player.value = 5;

that's what it means. you store stuff like player.durability[itemname] = 10; and then you can access it for that specific item or its id

Ah alright that makes sense lol. I'll experiment with it, thanks!

Third one is similar to the first one. Make a separate datablock for the upgraded gun. When the upgrade item is used, search the player's inventory for the gun, if it's found, remove the upgrade from the inventory, and replace the gun with the upgraded gun.

And thanks Shift Kitty! Excuse my noobness, but I get confused at "Make a separate datablock..." What exactly does that mean? Am I just thinking about it the wrong way or...? Idk. I haven't slept in about 23 hours (holy shet) so I could be just using too much brain power lol

And thanks Shift Kitty! Excuse my noobness, but I get confused at "Make a separate datablock..." What exactly does that mean? Am I just thinking about it the wrong way or...? Idk. I haven't slept in about 23 hours (holy shet) so I could be just using too much brain power lol
Get some sleep, it helps.

But what I mean by that is make a completely new item and mounted image, copying almost all the values of the old one, and then make it better.

Get some sleep, it helps.
Yeah, I can't continue to get up at noon 'o clock anymore and I know this'll work :\

But what I mean by that is make a completely new item and mounted image, copying almost all the values of the old one, and then make it better.
That's what I thought. Lil more work than I wanted (especially for multiple different items) but I can manage probably. Thanks!

I'm still having some trouble with this -_- I did some looking and found this bit of code:
Code: [Select]
for(%i=0;%i<5;%i++)
    {
        %toolDB = %obj.tool[%i];

        if(%toolDB $= %image.item.getID())
    }
How would I use this? I suppose I just don't know how to use ID's or how I would have it recognize an item. I also found this:
Code: [Select]
if(isObject(%client = %obj.client))
    {
        %currSlot = %obj.currTool; //Object's current slot
        %item = %obj.tool[%currSlot]; //The item (usually it's an ID)
        %image = %obj.tool[%currSlot].image; //Get the image of the current tool the guy is holding
        if(isObject(%item) && isObject(%image)) //Make sure they both exist
            if(%image == %this) //%this = the current image the object is holding, usually it's an ID, you could also do -> if(nameToID(%image) == nameToID(%this))
            {
                %obj.tool[%currSlot] = 0;
                %obj.weaponCount--;
                messageClient(%client, 'MsgItemPickup', '', %currSlot, 0);
                serverCmdUnUseTool(%client);
            }
    }
This bit of code makes more sense as to how I would "use" two items by requiring one by the other.

Otherwise all I see is that I'm trying to match two different datablocks or whatever to then use code on the item I activated in the first place and I can't make sense of it. Can someone put some light on the subject?

The first code block checks to see if you have a specific item in your inventory, like the key for your lock example
Do note that it's hard coded for 5 item slots, so will not detected extended player slots and may throw errors in the console for less item slots
Also, to see the IDs, you can use echo to print to the console

The second looks like it would be used to remove an item from the inventory



Here's an excerpt from Weapon_SatchelCharge (found here) which looks for a specific item in the player's inventory

Code: [Select]
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

Code: [Select]
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

Code: [Select]
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.

Code: [Select]
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"));
}
}
}

I've tried this, and it's working to some extent. It removes/adds what is needed but it always removes my Hammer tool in the very first slot and I'm not sure why. I've tried dinking with it. I've looked at the Satchel weapon and it seemed like that was simpler code but I couldn't get it to work at all after trying a few different "versions" :P

I forgeted up here
Code: [Select]
%player.currTool = 0;
%player.weaponCount--;
messageClient(%client, 'MsgItemPickup', '', %player.currTool, 0);

I think the correct code is
Code: [Select]
%player.tool[%player.currTool] = 0;
%player.weaponCount--;
messageClient(%client, 'MsgItemPickup', '', %player.currTool, 0);

Thank you Rally you've been a lot of help, and that change of code did help, however I'm still pretty stuck :P
Here's my code so far (it will probably be a bit messed up from it's prior almost-complete status due to me trying to fix this issue with changes):
Code: [Select]
function LockedBoxImageEquip::onFire(%this, %obj, %slot)
{
%client = %obj.client;
%player = %obj;

for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
{
%item = %player.tool[%i];
if(%item == nameToID("KeyItem"))
{
%player.tool[%player.currTool] = 0;
%player.weaponCount--;
messageClient(%client, 'MsgItemPickup', '', %player.currTool, 0);

%player.tool[%i] = nameToID("KeyItem");
messageClient(%client, 'MsgItemPickup', '', %i, nameToID("KeyItem"));

if(%currTool == nameToID("LockedBoxItem"))
{
%player.tool[%currTool] = 0;
%player.weaponCount--;
messageClient(%client, 'MsgItemPickup', '', %player.currTool, 0);

%player.tool[%currTool] = nameToID("UnlockedBoxItem");
messageClient(%client, 'MsgItemPickup', '', %i, nameToID("UnlockedBoxItem"));
}
}
}
}
What this does is keep my KeyItem in my inventory, which is what I want. However it removes my LockedBoxItem without replacing it with the UnlockedBoxItem, it's just an empty inventory slot BUT I still have the LockedBoxItem in my hand visually. Strange.

What I want it to do is when I left-click the LockedBoxItem, with the KeyItem in my inventory, it will replace (or remove and then add) it with the UnlockedBoxItem as well as keep the KeyItem in my inventory.

Code: [Select]
function LockedBoxImageEquip::onFire(%this, %obj, %slot)
{
%client = %obj.client;
%player = %obj;

//check the player has the key
%hasKey = false;
for(%i = 0; %i < %player.getDatablock().maxTools && !%hasKey; %i++)
%hasKey = %player.tool[%i] == nameToID("KeyItem");

if(%hasKey) //player has key, swap out the current item with the unlocked version
{
%item = nameToID("UnlockedBoxItem");
%player.tool[%player.currTool] = %item;
messageClient(%client, 'MsgItemPickup', '', %player.currTool, %item);
}
//else //player doesn't have key
//play beep denied or something if you want
}