Page 1 of 1

Prevent deletion of empty magazines

Posted: Sun Aug 14, 2016 2:49 pm
by Kill3rCat
So... I am working on a mod, which adds a couple new weapons and their corresponding ammo types (power cells). Now, I scoured through base and core, and couldn't find the scripts responsible for deleting empty magazines.

Is there any way to prevent the deletion of an empty magazine (or, alternatively, to give the player a new item called 'depleted cell' when a magazine is fully used up)?

Re: Prevent deletion of empty magazines

Posted: Sun Aug 14, 2016 4:19 pm
by Adil
Vanilla functionality of the game is done in C++ and its code is inaccessible to common folks.
You might want to play around with on_player_ammo_inventory_changed event.
If that fails, the only way would be to perform inventory checks each few ticks.

Re: Prevent deletion of empty magazines

Posted: Sun Aug 14, 2016 9:12 pm
by Kill3rCat
I see, thank you. I'll try that. So, I presume, count the number of magazines in the player's inventory whenever the inventory is changed, and then add the appropriate number of cells.

However, when the player manually drops off stuff from his inventory into a container, that would trigger the script would it not? If the player unloads magazines from his inventory, 'depleted' magazines will spawn in his inventory. No? Also, as far as I know, there're no events for a player manually removing items from his inventory which could be used as a failsafe. There would also appear to be no event for the player using, or attempting to use, a weapon.

Re: Prevent deletion of empty magazines

Posted: Mon Aug 15, 2016 3:40 am
by Adil
You're probably right. Though you could maintain a counter of how much ammo player has on him, and check, how much ammo is gone, if more than a single clip - it is unlikely due to shooting, if a single clip is gone, you could check the player's inventory and opened entity, and see if missing clip is there. It is not 100% correct for external inventories, as there's not way to know what was in them before the event, but covers most of the situations.

Or the trigger_created_entity event might be of use to detect player shooting if the weapon you're devising is not too fast shooting. Then you could implement all the counting logic in the lua completely.

Re: Prevent deletion of empty magazines

Posted: Mon Aug 15, 2016 9:06 am
by Kill3rCat
Actually, I think you just gave me the solution. Thanks very much; you've been most helpful.

Also, I have to say - I love your profile picture.

Re: Prevent deletion of empty magazines

Posted: Mon Aug 15, 2016 5:29 pm
by Adil
Why thank you.
Good luck with the solution and the project of yours.