Jump to content

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
  On 10/27/2024 at 10:48 AM, 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):
 

  Reveal hidden contents

 

Edited by Sid Debian
Added description code.
  • Thanks 1

Share this post


Link to post
Share on other sites
  On 10/27/2024 at 3: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):
 

  Reveal hidden contents

 

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×