1: Crash - repro
I only seem to get the issue when powering up more than 1 Howitzer at the same time.
(i.e If I place the howitzers one-by-one in an already powered area, I can play without any issue. If I place howitzer first, then place a power-pole so that it touches 2+ Howitzers, 100% crash within a minute or so.)
2: Crash - cause
I thought the issue might be that the offending line(and the following line) was not grabbing x-and-y coordinates of radar-scan-events, but this modified code did not help:
---begin paste---
local offsetX = tonumber(target[1]) + math.random(0,offsetR) * math.sin(math.random()(math.pi2))
local offsetY = tonumber(target[2]) + math.random(0,offsetR) * math.sin(math.random()(math.pi2))
---end paste---
What does the "ID 0" for "Tick" mean? Usually you would have a delta-time coming in for a Tick-function... hmm... I could try making sure the Tick does not receive a NIL argument. Why it would get this, I do not understand.
[EDIT]
Solved the crash!
Turns out "target" is nil when 2 or more Howitzers gets activated at the same time. Replacing the lines above with this, safeguards the crash. However, I'm not 100% sure if ammunition is counted correctly in networked situations. You'll have to evaluate this code yourself, Sore68. It's working well enough for me to continue my singleplayer game. ^_^
local offsetX = tonumber(target[1])
local offsetY = tonumber(target[2])
if (offsetX and offsetY) then
offsetX = offsetX + math.random(0,offsetR) * math.sin(math.random()(math.pi2))
offsetY = offsetY + math.random(0,offsetR) * math.sin(math.random()(math.pi2))
3: Heavy Howitzer not working properly
I've spent some time going through the script/testing, but I have yet to figure some stuff out before I can locate the reason behind the Howitzer not firing dependently... Even with a single howitzer, in creative mode.
(On that note - comment your code, dude! :D )
[EDIT]
Finally managed to make the Howitzer work...!!!
The Howitzer attempts to fire at certain intervals.
However, the scan-function keeps resetting the variable you use for storing the "target" found by the scanner. Thus, if the scanner does a new scan that contains no targets, before the Howitzer has fired - the Howitzer will never fire.
The offending is (around line 798)
function On_Scanned(event)
...
event.radar.backer_name = ""
...
Removing/commenting this line makes the howitzer fire reliably.
Though - because of how the radar works (only updating the oldest sector) it feels like it would be so much better to use a global list that could be shared with other Howitzers and a random target(in range) would be chosen before each attack.
4: Grovelling
I adore the automation that the Howitzer adds to the gameplay (when it works), but I personally see little to no use for the other turrets. So for me the other turrets merely clogs up the research interface. In the best of worlds - the Howitzer would be a separate mod. :) But that's kind of splitting hairs...
Thank you for making the mod! :)