Prevent deletion of empty magazines

Place to get help with not working mods / modding interface.
Post Reply
Kill3rCat
Burner Inserter
Burner Inserter
Posts: 17
Joined: Wed Aug 10, 2016 12:28 am
Contact:

Prevent deletion of empty magazines

Post 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)?

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Prevent deletion of empty magazines

Post 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.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Kill3rCat
Burner Inserter
Burner Inserter
Posts: 17
Joined: Wed Aug 10, 2016 12:28 am
Contact:

Re: Prevent deletion of empty magazines

Post 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.

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Prevent deletion of empty magazines

Post 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.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Kill3rCat
Burner Inserter
Burner Inserter
Posts: 17
Joined: Wed Aug 10, 2016 12:28 am
Contact:

Re: Prevent deletion of empty magazines

Post 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.

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Prevent deletion of empty magazines

Post by Adil »

Why thank you.
Good luck with the solution and the project of yours.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Post Reply

Return to “Modding help”