Jump to content

Forums Announcement

Read-Only Mode for Announcements & Changelogs

Dear Survivors, we'd like to inform you that this forum will transition to read-only mode. From now on, it will serve exclusively as a platform for official announcements and changelogs.

For all community discussions, debates, and engagement, we encourage you to join us on our social media platforms: Discord, Twitter/X, Facebook.

Thank you for being a valued part of our community. We look forward to connecting with you on our other channels!

Stay safe out there,
Your DayZ Team

23p23 41

making item pickable when empty

Recommended Posts

Hi, I am creating few storage items and i encountered problem i can't unfortunatelly solve. Every code i am using i grabbed from P: Drive/scripts. All i want is to being able to pick up this storage item when empty. When full i want it to be stuck on ground 😄 

I have 2 items with attachment slots only without cargo and i am using these lines and everything is working like it should :

override bool CanPutInCargo( EntityAI parent )
    {
        if( !super.CanPutInCargo( parent ) )
        {
            return false;
        }
        
        if( GetInventory().AttachmentCount() == 0 )
        {
            return true;
        }
        return false;
    }
    
    override bool CanPutIntoHands( EntityAI parent )
    {
        if( !super.CanPutIntoHands( parent ) )
        {
            return false;
        }
        
        if( GetInventory().AttachmentCount() == 0 )
        {
            return true;
        }
        return false;
    }    



Then i have item without attachment slot with cargo only but cant get it to work properly. Obviously these lines above won't work for this one but i tried every possible variation... even took an example from barrel_colourbase.c because barrells cant be picked up when item is in but nothing. I use lines listed below :

override bool CanPutInCargo( EntityAI parent )
    {
        if ( !super.CanPutInCargo( parent ))
            return false;

        if ( GetNumberOfItems() == 0 )
            return true;

        return false;
    }
    
    override bool CanPutIntoHands( EntityAI parent )
    {
        if ( !super.CanPutIntoHands( parent ))
            return false;

        if ( GetNumberOfItems() == 0 )
            return true;

        return false;
    }

These lines i edited to fit my item. As i mentioned i picked it from barrels. Only thing it had was   && !IsOpen() )  after line if ( GetNumberOfItems() == 0
My item isnt openable so i thought i get rid of that part...
So idk what kind of code i have to use. Does it have to say something about cargo or where i am making mistake. As i said everything i am taking from P drive but cant find any usefull code for this
Ty for any future help!!!

Edited by 23p23 41

Share this post


Link to post
Share on other sites
4 hours ago, 23p23 41 said:

Hi, I am creating few storage items and i encountered problem i can't unfortunatelly solve. Every code i am using i grabbed from P: Drive/scripts. All i want is to being able to pick up this storage item when empty. When full i want it to be stuck on ground 😄 

I have 2 items with attachment slots only without cargo and i am using these lines and everything is working like it should :

override bool CanPutInCargo( EntityAI parent )
    {
        if( !super.CanPutInCargo( parent ) )
        {
            return false;
        }
        
        if( GetInventory().AttachmentCount() == 0 )
        {
            return true;
        }
        return false;
    }
    
    override bool CanPutIntoHands( EntityAI parent )
    {
        if( !super.CanPutIntoHands( parent ) )
        {
            return false;
        }
        
        if( GetInventory().AttachmentCount() == 0 )
        {
            return true;
        }
        return false;
    }    



Then i have item without attachment slot with cargo only but cant get it to work properly. Obviously these lines above won't work for this one but i tried every possible variation... even took an example from barrel_colourbase.c because barrells cant be picked up when item is in but nothing. I use lines listed below :

override bool CanPutInCargo( EntityAI parent )
    {
        if ( !super.CanPutInCargo( parent ))
            return false;

        if ( GetNumberOfItems() == 0 )
            return true;

        return false;
    }
    
    override bool CanPutIntoHands( EntityAI parent )
    {
        if ( !super.CanPutIntoHands( parent ))
            return false;

        if ( GetNumberOfItems() == 0 )
            return true;

        return false;
    }

These lines i edited to fit my item. As i mentioned i picked it from barrels. Only thing it had was   && !IsOpen() )  after line if ( GetNumberOfItems() == 0
My item isnt openable so i thought i get rid of that part...
So idk what kind of code i have to use. Does it have to say something about cargo or where i am making mistake. As i said everything i am taking from P drive but cant find any usefull code for this
Ty for any future help!!!

First I suggest you to check inventory: super.GetInventory()

2nd if you're using attachments - check attachment slot on does it has item attached or not?

So here the example of items check (you're free to use this code):
 

Spoiler

/***
  Content of this block & code is using GPLv3 license.
  Licence you can find here: https://www.gnu.org/licenses/gpl-3.0.html
***/
override bool CanPutIntoHands(EntityAI parent) {
    if(super.CanPutIntoHands(parent))  {	// If game allow player to pick item, let's check it!
        return ((GetInventory().AttachmentCount() == 0) && (GetInventory().CountInventory() == 0);	// Will return TRUE if there's no attachments on the object AND no anything in inventory
    }
    return false;
}
/*
What's an idea?
super.CanPutIntoHands - will not check attachments it will check probably only the inventory, but we made the override that will check:
1. Do we have any attached item in slot(s) & do we put any item to the Inventory.
So by the test you shall get:
A) 1 att + 1 item => Can't pick
B) 1 att + 0 itms => Can't pick
C) 0 att + 1 itm => Can't pick
D) 0 att + 0 itms => Can pick

That's the solution to your issue. Have fun!
*/

 

 

Edited by Sid Debian
Added description code.
  • Thanks 1

Share this post


Link to post
Share on other sites
On 10/27/2024 at 4:04 PM, Sid Debian said:

First I suggest you to check inventory: super.GetInventory()

2nd if you're using attachments - check attachment slot on does it has item attached or not?

So here the example of items check (you're free to use this code):
 

  Hide contents


/***
  Content of this block & code is using GPLv3 license.
  Licence you can find here: https://www.gnu.org/licenses/gpl-3.0.html
***/
override bool CanPutIntoHands(EntityAI parent) {
    if(super.CanPutIntoHands(parent))  {	// If game allow player to pick item, let's check it!
        return ((GetInventory().AttachmentCount() == 0) && (GetInventory().CountInventory() == 0);	// Will return TRUE if there's no attachments on the object AND no anything in inventory
    }
    return false;
}
/*
What's an idea?
super.CanPutIntoHands - will not check attachments it will check probably only the inventory, but we made the override that will check:
1. Do we have any attached item in slot(s) & do we put any item to the Inventory.
So by the test you shall get:
A) 1 att + 1 item => Can't pick
B) 1 att + 0 itms => Can't pick
C) 0 att + 1 itm => Can't pick
D) 0 att + 0 itms => Can pick

That's the solution to your issue. Have fun!
*/

 

 

Ty for the help. Tried ur way and still didnt work but then i sat down for a while and compared my lines to other ones mainly i use for attachments only items and i think i found out why it wasnt working. At the end i sticked to my lines but i definetely saved ur example if i ever get in problems again. problem was i missed some {} infront and behind return false/true. Put it in and tried it and everything is working 

What i had: 

if ( GetNumberOfItems() == 0 )
            return true;

Corrected version:

if ( GetNumberOfItems() == 0 )
        {    
            return true;
        }


Small mistake but sometimes i guess this kind of mistake can get overlooked. Again ty for help even tho i fixed it myself at the end. Rly appreciate that!!!

 

  • Thanks 1

Share this post


Link to post
Share on other sites

×