At the very least, if any others are interested in something like this, might help to have the community's input, so it's worth putting this post up anyways.
Ammo range modification
Ammo range modification
I'm not sure if this has ever been discussed, nor if this was intentional or just oversight, but I've noticed there's no way to change an individual ammo item's set range, despite the fact that other ranges throughout the game can be configured with mods. Enabling ammo ranges to be tweaked alongside other ranges (turrets, guns, etc.), via mod config settings, technology upgrades, etc. might not be a common-use situation but it is something I'm running into as a definite need for a personal project, and I'm sure the Factorio modding community would find some special use for such an opening as well.
At the very least, if any others are interested in something like this, might help to have the community's input, so it's worth putting this post up anyways.
Especially with the expansion coming up and the threats posed to space platforms by asteroid chunks, it could be interesting to allow modders to play around with tech upgrades to make turret defenses on said platforms more effective at longer and longer ranges, on top of the bullet speed and damage tech upgrades either native to base game and/or added by mods.
But ultimately, it's up to the devs whether or not they wish to consider such a change in the codebase. I'd call it trivial if I hadn't taken a look at the data files for ammo for myself, and I can tell it might break some things to add an otherwise small feature, so even with the positives I don't necessarily anticipate this request will be approved, quite the contrary in fact...At the very least, if any others are interested in something like this, might help to have the community's input, so it's worth putting this post up anyways.
Hi hungry, I'm dad!
Re: Ammo range modification
You want to change the range during the control stage -- is that correct? A short search for "range" in the LuaApi description doesn't show any results for LuaEntity. Properties like "turret_range" or "radar_range" belong to LuaEntityPrototype and are read-only. You can modify these, but only on starting the game (during data stage).spiro9 wrote: ↑Mon Jan 15, 2024 11:30 am … I've noticed there's no way to change an individual ammo item's set range, despite the fact that other ranges throughout the game can be configured with mods. Enabling ammo ranges to be tweaked alongside other ranges (turrets, guns, etc.), via mod config settings, technology upgrades, etc. …
In the data stage, you can modify the range of a gun or turret prototype by changing the value of its attack_parameters.range (this is a property of the BaseAttackParameters that all attack_parameters inherit). The AmmoItemPrototype doesn't allow for setting a fixed range, but you can set its ammo_type.range_modifier.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Ammo range modification
Nope. I'm doing all of my changes in data-final-fixes specifically because I know I need to mess with the prototypes. The problem is that turret range settings only affect where the turret targets and fires on enemies, not how far the projectiles fire, and it's that latter point where my issue lay.
I'd like to be able to configure ammo ranges, because if you open up debug info and check the "effects" info in-game, you can see on firearm mags and cannon shells that the projectile ranges are limited, and no amount of messing with the max_range settings in ammo item declarations seems to have any effect whatsoever; they appear to be strictly limited to 30-35 on average. Having some way to override this seemingly hard-coded limitation would be a boon.
Hi hungry, I'm dad!
- BraveCaperCat
- Filter Inserter
- Posts: 273
- Joined: Mon Jan 15, 2024 10:10 pm
- Contact:
Re: Ammo range modification
Use ammo_type.range_modifier, as said by the first reply to your post.
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
Re: Ammo range modification
This does not fix the issue.BraveCaperCat wrote: ↑Mon Jan 15, 2024 10:59 pm Use ammo_type.range_modifier, as said by the first reply to your post.
Hi hungry, I'm dad!
Re: Ammo range modification
You can set the max range for the projectiles under action delivery.
https://lua-api.factorio.com/latest/typ ... ivery.html
https://lua-api.factorio.com/latest/typ ... ivery.html
Code: Select all
attack_parameters = {
ammo_type = {
category = "laser",
target_type = "entity",
action = {
type = "direct",
action_delivery = {
type = "projectile",
projectile = "projectile-name',
starting_speed = 0.35,
max_range = attack_range * 1.5 <<<< This will set the max range of the projectile.
}
}
},
}
Re: Ammo range modification
I'm already doing this:heyqule wrote: ↑Tue Jan 16, 2024 3:23 am You can set the max range for the projectiles under action delivery.
https://lua-api.factorio.com/latest/typ ... ivery.html
Code: Select all
attack_parameters = { ammo_type = { category = "laser", target_type = "entity", action = { type = "direct", action_delivery = { type = "projectile", projectile = "projectile-name', starting_speed = 0.35, max_range = attack_range * 1.5 <<<< This will set the max range of the projectile. } } }, }
Code: Select all
-- This mod overwhelms the game's handling of default & modded ammo types, which appear to be strictly range-limited to around a maximum of 30-50
-- However, there is no indication that this range-limit is hardcoded so much as a softcoded "suggestion" from which to build
-- Iterating over each and setting its range to something absurd should help in correcting this issue
-- Rather, in simpler terms, look through every single ammo item and check for a maximum range, then if one is found, set it to something like 1000 so ammo can fly forever >:D
for _, a in pairs(data.raw["ammo"]) do
local t = a.ammo_type
if t.action then
for _, q in ipairs(t.action) do
if q.action_delivery then
if q.action_delivery.max_range then
log("Before: " .. tostring(q.action_delivery.max_range))
local c = q.action_delivery.max_range
q.action_delivery.max_range = 1000
log("After: " .. tostring(q.action_delivery.max_range))
if c == q.action_delivery.max_range then
log("Uh-oh! These are the same!")
end
end
end
end
end
end
Amendment: it does appear to affect shotgun shells, but all other ammunition types are unaffected
Last edited by spiro9 on Tue Jan 16, 2024 8:45 am, edited 1 time in total.
Hi hungry, I'm dad!
Re: Ammo range modification
BraveCaperCat wrote: ↑Tue Jan 16, 2024 8:43 amspiro9 wrote: ↑Tue Jan 16, 2024 8:37 amCan you post your log?heyqule wrote: ↑Tue Jan 16, 2024 3:23 am You can set the max range for the projectiles under action delivery.
https://lua-api.factorio.com/latest/typ ... ivery.html
Code: Select all
attack_parameters = { ammo_type = { category = "laser", target_type = "entity", action = { type = "direct", action_delivery = { type = "projectile", projectile = "projectile-name', starting_speed = 0.35, max_range = attack_range * 1.5 <<<< This will set the max range of the projectile. } } }, }
I'm already doing this:This code however has no effect despite logs confirming the change is being made in the data-final-fixes substage.Code: Select all
-- This mod overwhelms the game's handling of default & modded ammo types, which appear to be strictly range-limited to around a maximum of 30-50 -- However, there is no indication that this range-limit is hardcoded so much as a softcoded "suggestion" from which to build -- Iterating over each and setting its range to something absurd should help in correcting this issue -- Rather, in simpler terms, look through every single ammo item and check for a maximum range, then if one is found, set it to something like 1000 so ammo can fly forever >:D for _, a in pairs(data.raw["ammo"]) do local t = a.ammo_type if t.action then for _, q in ipairs(t.action) do if q.action_delivery then if q.action_delivery.max_range then log("Before: " .. tostring(q.action_delivery.max_range)) local c = q.action_delivery.max_range q.action_delivery.max_range = 1000 log("After: " .. tostring(q.action_delivery.max_range)) if c == q.action_delivery.max_range then log("Uh-oh! These are the same!") end end end end end end
Hi hungry, I'm dad!
- BraveCaperCat
- Filter Inserter
- Posts: 273
- Joined: Mon Jan 15, 2024 10:10 pm
- Contact:
Re: Ammo range modification
Can you try this with just your mod and it's dependencies? then post that log if it still doesn't work. (there are a lot of different mods which don't seem to have any connection to your mod, some of them may be overwriting your changes)spiro9 wrote: ↑Tue Jan 16, 2024 8:47 amLog file.BraveCaperCat wrote: ↑Tue Jan 16, 2024 8:43 amspiro9 wrote: ↑Tue Jan 16, 2024 8:37 amCan you post your log?heyqule wrote: ↑Tue Jan 16, 2024 3:23 am You can set the max range for the projectiles under action delivery.
https://lua-api.factorio.com/latest/typ ... ivery.html
Code: Select all
attack_parameters = { ammo_type = { category = "laser", target_type = "entity", action = { type = "direct", action_delivery = { type = "projectile", projectile = "projectile-name', starting_speed = 0.35, max_range = attack_range * 1.5 <<<< This will set the max range of the projectile. } } }, }
I'm already doing this:This code however has no effect despite logs confirming the change is being made in the data-final-fixes substage.Code: Select all
-- This mod overwhelms the game's handling of default & modded ammo types, which appear to be strictly range-limited to around a maximum of 30-50 -- However, there is no indication that this range-limit is hardcoded so much as a softcoded "suggestion" from which to build -- Iterating over each and setting its range to something absurd should help in correcting this issue -- Rather, in simpler terms, look through every single ammo item and check for a maximum range, then if one is found, set it to something like 1000 so ammo can fly forever >:D for _, a in pairs(data.raw["ammo"]) do local t = a.ammo_type if t.action then for _, q in ipairs(t.action) do if q.action_delivery then if q.action_delivery.max_range then log("Before: " .. tostring(q.action_delivery.max_range)) local c = q.action_delivery.max_range q.action_delivery.max_range = 1000 log("After: " .. tostring(q.action_delivery.max_range)) if c == q.action_delivery.max_range then log("Uh-oh! These are the same!") end end end end end end
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
Re: Ammo range modification
My mod actually has zero dependencies. I run a check for other mods but there is no need for those mods to be present. The only reason I can think of regarding other mods overriding the behavior of mine is, my attempt to ensure my mod loads last by appending 'zzzzzz' was futile.
Hi hungry, I'm dad!
Re: Ammo range modification
It doesn't really make sense to use prefixes like "zzz" for making your mod load last. Other modders may also want to load last, so they might add a 'z' more … The best way is to add (optional) dependencies on the mods known to interfere with yours. Also, the multi-phase data stage is useful if everybody follows some guidelines:
- data: Create the essential prototypes for your mod.
- data-updates (optional): Create optional prototypes and adjust your essential prototypes depending on what the other mods have created.
- data-final-fixes (optional): Make final adjustments to existing prototypes, but don't create new ones!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
- BraveCaperCat
- Filter Inserter
- Posts: 273
- Joined: Mon Jan 15, 2024 10:10 pm
- Contact:
Re: Ammo range modification
Or, Hidden Optional Dependencies!Pi-C wrote: ↑Tue Jan 16, 2024 11:11 amIt doesn't really make sense to use prefixes like "zzz" for making your mod load last. Other modders may also want to load last, so they might add a 'z' more … The best way is to add (optional) dependencies on the mods known to interfere with yours. Also, the multi-phase data stage is useful if everybody follows some guidelines:If you want to see whether any other mods have overwritten your changes, you can use the in-game prototype browser. You can use CTRL+SHIFT+E to open a GUI that provides access to all prototypes in the game, or you can hover your cursor over any entity, item, recipe etc. and type CTRL+SHIFT+F to directly open the view of its prototype. Also, when hovering the cursor over something, the description appearing on the right side of the display shows the order in which mods created/changed the prototype.
- data: Create the essential prototypes for your mod.
- data-updates (optional): Create optional prototypes and adjust your essential prototypes depending on what the other mods have created.
- data-final-fixes (optional): Make final adjustments to existing prototypes, but don't create new ones!
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.