Gun Equipment


Mode add automatic guns applyable to equipment grid.

Content
4 days ago
1.0 - 2.0
40.5K
Combat Armor

i [Done] Train Grid

a month ago

The mod description mentions that the gun equipment can be added to vehicle grids, but this does not appear to work with trains. I was able to successfully force them to work with the car and tank, but received an error after placing it into a cargo wagon vehicle grid. Specifically, getting inside the cargo wagon, after having placed a gun equipment into its grid. It didn't seem to take the ammo I had placed into the cargo wagon inventory.

I have a version of my vehicle grid mod with the functionality enabled on Google Drive here, so you can test it.

a month ago

The issue of Train is missing inventory for looking for magazines, in case the grid mod also implements addition of ammo inventory (enough is storage), then it will start work.

a month ago

So wait, are you saying that the gun equipment relies on vehicles having a weapon slot for firearm magazines, in order to work properly? Like the tank and train with their built-in machine gun/assault rifles? Does this mean that the gun equipment would also not work if forced into a spidertron equipment grid? Since they only have rocket launchers as weaponry?

a month ago
(updated a month ago)

OH, I got it working! I had to change a few things in the AutoGun control.lua, though not sure if every change was necessary. Under the VehicleTypes (line 14), the "tank" is technically a "car", so that doesn't need to be included, and for me, "train" was not a valid type either.

The different train entities all have their own prototypes, like "locomotive" (for the part with the engine), and "cargo-wagon" (the part with the inventory). I removed "tank" and "train" and added "cargo-wagon" to that list instead

Then under AutoGun.OnTick(player), I changed line 256, beginning with "local main_inventory =..." and added "or vehicle.get_inventory(defines.inventory.cargo_wagon)" to the end of it.

So if the vehicle is a car, then the "car_trunk" will be detected and used for the AutoGun_Reload function, but cargo-wagons don't have "car_trunk", so that part is ignored, and move to the "cargo_wagon" check instead, using that for the AutoGun_Reload function. See my version of AutoGun/control.lua here and see below for proof that it works:

a month ago

This is partial solution, for this functionality must be added "data-final-fix.lua" that will collect all shootable vehicles.
Adding only this it may cause performance issues for players, who do not use mod with grid for vagons.

a month ago
(updated a month ago)

I don't believe this would add.. any performance hit at all, actually? Your on_tick function only checks vehicles that have been added to the list from AutoGun.vehicles, which only adds vehicles which are listed under the VehicleTypes ("car" and "spider-vehicle" being the only valid types anyways).

Both "car" and "spider-vehicle" entities appear to use "defines.inventory.car_trunk" as their inventory, so the check for "defines.inventory.cargo_wagon" would simply never occur (because that's how lua works, only the first valid parameter of an or statement is checked). The only time "defines.inventory.cargo_wagon" would ever be checked, is if a vehicle in the list does not have a "defines.inventory.car_trunk", which would only ever happen if the vehicle is a cargo-wagon.

Therefore, zero performance hit on_tick

I don't understand what you mean by the "data-final-fixes" part, since your mod doesn't have one of those, and you don't need to add one to make this work. If you wanted to avoid adding unnecessary types to the list of AutoGun.vehicles, then you could add a simple check for my mod (and its train grid setting), and only if true, add "cargo-wagon" to the list of VehicleTypes. Not to sound presumptuous, but there are no other vehicle equipment mods on the mod portal (yet), so no other checks should be necessary.

Either way, I would like to request for this functionality to be included. You can test it for performance if you want, but I don't believe there should be any performance hit.

a month ago

I underline Kryzeth's contribution. I had a fix in place for this exact thing and his is much better. I've been using it without any performance hits and it's honestly amazing to have gun trains. I hope this gets implemented.

a month ago
(updated a month ago)

Hi there,
I did implement the changes more generic, but I'm still not able to reach the configurability (I do not know how to share data between the Prototypes and Runtime stage).
At Least you can test it.

a month ago
(updated a month ago)

I did realize this later, that startup settings aren't visible during runtime (which is rather annoying..) Though I see the changes you made, and that was a pretty genius way to do it! Ensuring that vehicles without both a grid and an inventory don't get added/checked unnecessarily.

Though for some reason, GunEquipment placed in cargo-wagons don't work unless the player is inside the vehicle. I'm not entirely sure why, but they don't even take a bullet unless the player enters the vehicle. But even then, they won't fire unless the player is in the cargo wagon. I get the feeling there might be a check somewhere that is failing on cargo wagons, but not sure which one just yet.

EDIT: Ohhh, I figured it out; it's just a simple typo in the list of VehicleTypes, all of the wagons are spelled as "vagon" instead of "wagon"; everything works perfectly after fixing that!

a month ago

EDIT: Ohhh, I figured it out; it's just a simple typo in the list of VehicleTypes, all of the wagons are spelled as "vagon" instead of "wagon"; everything works perfectly after fixing that!

The vagons/wagons are in the API a bit confusing. So the wagons now works, or must be changed?

a month ago

Please let me know, if it did work.

a month ago
(updated a month ago)

Yes, it works perfectly now with v0.0.21, many thanks!

a month ago

Yes, it works perfectly now with v0.0.21, many thanks!

I'm glad I could help :-)

This thread has been locked.