23p23 41 1 Posted October 27 (edited) 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() == 0My 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 October 27 by 23p23 41 Share this post Link to post Share on other sites
Sid Debian 132 Posted October 27 (edited) 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() == 0My 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 October 27 by Sid Debian Added description code. 1 Share this post Link to post Share on other sites
23p23 41 1 Posted October 29 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!!! 1 Share this post Link to post Share on other sites