Jump to content

Recommended Posts

Posted (edited)

Ok I got it working however now it's quite deadly. Created a trigger zone (eg called test), set up a continuous trigger type with condition part of coalition blue in zone "test" with a do script when condition is true. Also need to load mist as a mission start or soon after trigger once event.

 

Script is:

 

do

local bluePlanes =

mist.makeUnitTable( {'[blue][plane]'} )

local inZoneUnits = mist.getUnitsInZones(bluePlanes, {'test'})

if #inZoneUnits > 0 then

for i = 1, #inZoneUnits do

local _targetpos = inZoneUnits:getPosition().p

local _landht = land.getHeight{x = _targetpos.x, y = _targetpos.z}

local vec3 = {

x=_targetpos.x,

y=(_targetpos.y - _landht + math.random(-500,500)),

z=_targetpos.z

}

trigger.action.explosion(vec3, 500)

end

end

end

 

 

I'm going to have to play around with the plus or minus 500 and perhaps the explosion strength now as the above script wiped out a four ship of P51s in about 30 secs from the time they entered the zone. Each aircraft had separate flak attacks. They did fly straight and level though so I guess that's another thing to check is how effective weaving and climbing and diving is as a defence against the flak.

 

I guess also need to check to see what performance impacts happen when a lot of aircraft are in the zone. I suppose this could also be created as a lua file passing the zone name and side as parameters (if I can figure out how you do that) so it's easier to plug into missions. Perhaps also have the explosion strength and plus or minus distance as parms too.

 

<edit> definitely too deadly lol, I just added the above to Sithspawn's flak mission by moving all the aircraft - 24 P51s - a bit further out from the target airfield and then created a test zone on their flight path. End result was all 24 aircraft shot down within 45 secs of entering the zone. I didn't notice any performance issue in single player with that number of planes although they did arrive at slightly staggered intervals so probably 18 aircraft was the max number in the zone at one time. Flak appeared around the individual aircraft as they entered just as if someone chose them down on the ground as their target. The downside is I guess you don't get the area denial flak barrage look of Sithspawn's original when you only have a few aircraft in zone ie it's kind of like 1 plane = 1 AAA gun rather than what probably happened in real life where you had every gun open up even if it was just one plane. So probably a mix of Sithspawn's script and this one so you have the look and the teeth ;D

 

Cheers,

Stonehouse

Edited by Stonehouse
Posted

Ok that's a good idea although I don't know how to do that yet. If I put a delay in the loop it will mean that there is a delay in attacking planes arriving in the zone doesn't it? Because it will stay on each entry in the table a bit longer or is that what you meant?

 

Perhaps put another loop around the for #inZoneUnits one and have the delay in that one?

Posted (edited)

Doing some more tweaking. The following gave 14 survivors out of 24 with about 9 without obvious damage - so call it approx. a 50% flak zone. Changing the range of _delay and the condition (_delay > n) will affect whether the script fires flak or not and also I believe the explosion strength could still go down as a near miss with strength 50 was still basically fatal although the pilot would bail out a direct hit = flaming wreck and dead pilot. Decreasing the "accuracy" of the flak by widening the -+ 1000 would also help generate higher miss ratio. Again this was a pure AI set of planes that flew straight and level through the zone.

 

do

local bluePlanes =

mist.makeUnitTable( {'[blue][plane]'} )

local inZoneUnits = mist.getUnitsInZones(bluePlanes, {'test'})

local _delay = math.random(0,30)

if (#inZoneUnits > 0) and (_delay > 20) then

for i = 1, #inZoneUnits do

local _targetpos = inZoneUnits:getPosition().p

local _landht = land.getHeight{x = _targetpos.x, y = _targetpos.z}

local vec3= {

x=_targetpos.x,

y=(_targetpos.y - _landht + math.random(-1000,1000)),

z=_targetpos.z

}

trigger.action.explosion(vec3, 50)

end

end

end

 

 

Note a later attempt with the strength down to 10 gave 19 survivors out of 24 with 3 obviously damaged. The flak looked fairly believable. The above is pretty tweakable and it should be possible to come up with settings that give certain casualty rates on an average basis. I will actually try to take the strength down to 1 (it doesn't seem to change the explosion gfx in game) and perhaps see if close near misses are survivable so it becomes a challenge for human pilots to bring home a crippled plane and I still haven't flown through myself and tried dodging around to see how it affects things.

 

Another attempt that saw no KIAs but something like 5 damaged aircraft - increased frequency of attacks (for a better look of flak barrage) and introduced a random explosion strength

 

do

local bluePlanes =

mist.makeUnitTable( {'[blue][plane]'} )

local inZoneUnits = mist.getUnitsInZones(bluePlanes, {'test'})

local _delay = math.random(0,30)

if (#inZoneUnits > 0) and (_delay > 15) then

for i = 1, #inZoneUnits do

local _targetpos = inZoneUnits:getPosition().p

local _landht = land.getHeight{x = _targetpos.x, y = _targetpos.z}

local vec3= {

x=_targetpos.x,

y=(_targetpos.y - _landht + math.random(-1000,1000)),

z=_targetpos.z

}

trigger.action.explosion(vec3, math.random(1,5))

end

end

end

 

Realistically as the continuous triggers are evaluated supposedly once per sec you could have the _delay range say random(0,5) and then use the condition to control roughly how many secs elapse between each attack. So >= 0 would be 1 per sec whereas I think > 4 would be roughly 1 per 5 secs on average. This controls density of the flak. Using bigger ranges like 0,30 or 0,100 probably affect the speed the average is achieved so it still may be better to use a larger range. ie smooth the probability curve if you get what I mean.

 

The -1000,1000 is used to control flak accuracy as it equates to a spread. The smaller the range the more accurate the flak on average.

 

A slight randomisation of explosion strength gives it some pure luck on top and I suppose sort of simulates ammo calibre - noting that anything around 10 is pretty lethal for a near miss and even a strength of 1 can kill if it gets a direct hit. It would be nice to know whether the explosion strength is a linear scale or a curve if someone out there knows. Probably should also add a condition on the explosion action so if it's going to be under say land height + 200 it doesn't happen for a heavy flak battery. Still think the original script should be used too (maybe incorporated?) but with less flakzones so that you get a good look and feel with a small number of aircraft.

 

Just a end note, my final experiment for the day was to set up flak over Krasnodar by putting a 10 km trigger zone (Flakzone in Sithspawn's script) over the city with 7 smaller 4km flak trigger zones (Flak1, Flak2,...Flak7 in Sithspawn's script) arranged within the 10km zone to form slightly overlapping zones within the main one and covering the area of the main zone. For each 4km zone I used Sithspawn's script unchanged. I then added another do script to the 10km zone which used the last of my examples above. My test subject was a single P51 and first I sent him straight through at a constant course and height and speed. He made it about halfway before being badly hit and the pilot was killed, this was the sitting duck example. The next one I plotted a zig zag 6 waypoint course altering height 1000m between each way point, this time he made it across with a few close shaves and it was only when he ran out of waypoints and turned and flew across the edge of the zone straight and level that he was nicked once and then had what looked like a very near miss. This produced a black smoke trail and wing perforations and the AI pilot struggled for a few minutes before exiting the zone to safety. Second flight was about 10 mins of ducking and weaving in the flak zone. So it seems that just like real life not flying straight and level is a defense although not a guarantee but do otherwise and you can expect to get hit. The original script provided a very nice visual (and still dangerous) effect of a flak barrage while the new script was the actual danger to the aircraft. Using the two scripts together should give us the ability to add flak to missions which will naturally scale to suit the aircraft numbers and be able to be tuned to provide a desired average level of danger to players.

Edited by Stonehouse
various experiments
Posted (edited)

New version based on the idea this is to simulate something like an WW2 88mm flak gun. So this now incorporates some firing limits that hopefully make it more realistic (an 88mm flakgun had about a 7700m max vertical range and I assume if you went low enough then 88's had trouble hitting you and that's why you had light flak emplacements around heavy flak) and also prevent loss of performance caused by execution of the explosion action for underground positions.

 

Going to have to teach myself how but next I'm going to try to turn it into a mist style function that can be loaded at mission start and then the AAA sub function called in a do script with parameters like side and zone name etc to make it easier to add to multiple locations easily and by making the code load at mission start I assume it will avoid the performance overhead of calling a script file for each zone. Which might be important for MP servers with many players activating multiple flak zones.

 

Anyway new version:

 

do

local bluePlanes = mist.makeUnitTable( {'[blue][plane]'} )

local inZoneUnits = mist.getUnitsInZones(bluePlanes, {'test'})

local _delay = math.random(0,30)

 

if (#inZoneUnits > 0) and (_delay > 15) then

 

for i = 1, #inZoneUnits do

local _targetpos = inZoneUnits:getPosition().p

local _landht = land.getHeight{x = _targetpos.x, y = _targetpos.z}

local _aaAlt = _targetpos.y - _landht + math.random(-1000,1000)

 

if ((_aaAlt >= _landht + 30) and (_aaAlt <= 7700)) then

local vec3= {

x=_targetpos.x,

y=_aaAlt,

z=_targetpos.z

}

trigger.action.explosion(vec3, math.random(1,5))

end

 

end

 

end

 

end

 

Edited by Stonehouse
removed erroneous end statement
Posted

hey stonehouse... can you post an example mission so i can look at how you set the do script up?

 

is this merely a do script?

ASUS Tuf Gaming Pro x570 / AMD Ryzen 7 5800X @ 3.8 / XFX Radeon 6900 XT / 64 GB DDR4 3200 

"This was not in the Manual I did not read", cried the Noob" - BMBM, WWIIOL

Posted (edited)

Calculate aircraft position in x seconds (based on shot distance. You can use a simple formula for the flight time, no need for it to be too complex).

 

Assign a bunch of flak bursts at that position and that time. Do it once every second, and you have one of the realistic flak firing methods. There are others, but once you have this one the rest is cake.

 

This is a very accurate, 'tracking flak' method, and if the target flies on fat, dumb and happy, he will pay for it. You will need to use realistic flak evasion to deal with this (some amount of heading change every x sec)

 

 

New version based on the idea this is to simulate something like an WW2 88mm flak gun. So this now incorporates some firing limits that hopefully make it more realistic (an 88mm flakgun had about a 7700m max vertical range and I assume if you went low enough then 88's had trouble hitting you and that's why you had light flak emplacements around heavy flak) and also prevent loss of performance caused by execution of the explosion action for underground positions.

 

Going to have to teach myself how but next I'm going to try to turn it into a mist style function that can be loaded at mission start and then the AAA sub function called in a do script with parameters like side and zone name etc to make it easier to add to multiple locations easily and by making the code load at mission start I assume it will avoid the performance overhead of calling a script file for each zone. Which might be important for MP servers with many players activating multiple flak zones.

 

Anyway new version:

 

do

local bluePlanes = mist.makeUnitTable( {'[blue][plane]'} )

local inZoneUnits = mist.getUnitsInZones(bluePlanes, {'test'})

local _delay = math.random(0,30)

 

if (#inZoneUnits > 0) and (_delay > 15) then

 

for i = 1, #inZoneUnits do

local _targetpos = inZoneUnits:getPosition().p

local _landht = land.getHeight{x = _targetpos.x, y = _targetpos.z}

local _aaAlt = _targetpos.y - _landht + math.random(-1000,1000)

 

if ((_aaAlt >= _landht + 30) and (_aaAlt <= 7700)) then

local vec3= {

x=_targetpos.x,

y=_aaAlt,

z=_targetpos.z

}

trigger.action.explosion(vec3, math.random(1,5))

end

 

end

 

end

 

end

 

end

Edited by GGTharos

[sIGPIC][/sIGPIC]

Reminder: SAM = Speed Bump :D

I used to play flight sims like you, but then I took a slammer to the knee - Yoda

Posted

i jsut tried the changes with mist v 3.2.

 

I can get the last version in post #31 to work but cannot with post #32.

 

Following error:

[string "do..."]:24: '<eof>' expected near 'end'

ASUS Tuf Gaming Pro x570 / AMD Ryzen 7 5800X @ 3.8 / XFX Radeon 6900 XT / 64 GB DDR4 3200 

"This was not in the Manual I did not read", cried the Noob" - BMBM, WWIIOL

Posted (edited)

@Dooom, Sorry my fault, nothing to do with Mist. My cut and paste was a bit screwy and there is one too many "end" statements. Edited post 32 to correct. Yes I will put together a very simple sample mission when I get a sec and post it up

 

@Sithspawn, no problem. I'm learning a lot along the way so all good.

 

@GGTharos, yes some of my squadron mates have noticed that the current script generates flak that is lagging the targets rather than leading them as it should. I was considering using unit:getVelocity to get their velocity vector in m/s and then because the continuous triggers are evaluated every sec I was thinking this kind of gave you a prediction of their future position 1 sec ahead in meters if they don't change their vector. So if I added the velocity vector numbers to their current position and then generated an explosion at the resultant it should lead the target and they'll fly into it. It's kind of rough but I thought it may give a better flak gun AI than my post 32. Does that match what you had in mind or were you thinking something that gave a more accurate model?

 

Generally I've been doing some reading on flak batteries and it seems that even around 1940 or even earlier all the guns in an 88 battery were linked to a single command post which tracked the target/s and fed azimuth and bearing info back to each gun and made indicators move on the gun aimer's console. All the gun aimer did was turn his dials so that his indicators matched the command post's while the gun fired. They didn't manually lay the gun unless the command post was not providing tracking info. So if the command post gave good info and the targets didn't change their vector a lot then the battery was very ,very accurate. An 88 fired between 15 and 25 rounds a min. So a good crew fired a round about every 2-3 secs. Very scary there was also a 128mm gun which had roughly twice the vertical range and about the same rof.

Edited by Stonehouse
Posted (edited)

Ok been experimenting with getVelocity and it does work pretty much as I thought. For a 400ish kph P51 (about 250 mph or roughly cruising speed) in straight and level flight it puts the explosion directly ahead of the aircraft at the expected 100ish meters. The problem I have is that it appears that the blast radius of the explosion doesn't scale with strength and that the shrapnel from the blast doesn't exist (understandably as it would hit performance of the game a lot) beyond the instant of the explosion. So while the plane flies through the fading explosion and smoke it is never damaged. Increasing the explosion strength doesn't seem to help and even strengths of 1000-1500 didn't appear to damage the plane at a steady distance directly in front of the plane.

 

There are benefits though to using the velocity vector as it means that a plane in a steady dive/climb/turn will now be "tracked" and explosions can be put directly in the plane's line of flight. I'm still mucking about with it but I think that due to the way the trigger.action.explosion works I need to make the explosion happen within a sphere of the aircrafts current position with the sphere radius = to the blast radius of the explosion in order to damage the aircraft. Otherwise I think I would need to trigger the explosion based on where the aircraft was 1 sec in the past plus the velocity vector at that time and that's beyond my skill level at the moment. It would probably need to have a stored table with an element for each target unit in the flak zone so that the current iteration of the continuous trigger would use the previous iterations position and vector. As plane left you'd have to remove the table element for the exiting aircraft and as one entered you'd need to create a new one and so on.

 

So I think my approach will be to take the current position add the velocity vector and then take off a random amount to move the explosion point back generally along the line of flight towards the aircrafts current position. If the aircraft is within the sphere of blast at that time it will get damaged.

 

I've also started to add average battery skill to the mix so that you have a low, medium and high skill level and this influences average rate of fire and spread range in all 3 axes for each shot. I've also moved the _delay check inside the for loop so that each shot and target will have a different chance to decide whether the attack takes place. I decided that this better simulates slight difference in rof for different gun crews even though it means the script is slightly heavier performance wise ( does more work for each iteration of the for loop whereas before the _delay check decided whether the for loop happened at all). As part of this I've now parameterised the script so there are 3 variables at the top for side, zone name and skill with the intention that these will become the function parameters eventually. If I can and Sithspawn doesn't mind I'll add his script as one of the eventual subscripts as it still gives a better feel (as we imagine it anyway) to a flak barrage than mine as mine appears very targeted. The thump of the explosion going off nearby is pretty impressive from in the cockpit by the way ;D

 

I'll post up the script sometime today and my test bed mission I use for working on the script. It won't include Sithspawn's script as I've been using it however - I can do a sample of that later on if people want to see how I've interpreted it's use.

 

Cheers,

Stonehouse

Edited by Stonehouse
Posted

You shouldn't place it 1 sec ahead. You should place it 'time of flight' sec ahead, and trigger it when the time of flight elapses.

 

In other words, consider that your flak gun in the center of your zone. The distance of the aircraft to the gun will give you a time of flight for the rounds.

 

So, calculate 'flight time' number of velocity vectors ahead, and start a count-down. Hit that place with explosions placed randomly around that target but within a tight box. If the plane flies straight, it should be hit. If he changes course, he should see explosions where he would have been flying.

 

The shells should have a 'flight' time anywhere from 5 to 50 sec. depending on range to target.

[sIGPIC][/sIGPIC]

Reminder: SAM = Speed Bump :D

I used to play flight sims like you, but then I took a slammer to the knee - Yoda

Posted (edited)
You shouldn't place it 1 sec ahead. You should place it 'time of flight' sec ahead, and trigger it when the time of flight elapses................

 

The only reason I was hung up on 1 sec ahead was I was trying to use the natural cycle of the continuously evaluated trigger. Anyway I've been thinking about what you've posted for the last couple of hours while painting the outside of the house and while I understand the physics of the ballistics involved without problem and simulating times of flight I'm struggling with the lua side of things - I wasn't telling fibs or exaggerating when I said I'm very new to writing code in it.

 

So I can't see from my limited understanding how what you've said will be achieved using the continuous trigger unless it's possible to store values (eg counter value) in one cycle of the trigger and retrieve and update them in another. It sounds more like you are thinking a mission start style trigger that initiates a script that monitors aircraft in all flak zones and takes a position and vector when they enter, works out a distance to our "gun" and therefore flight time for our hypothetical AA shell and the co-ordinates for the location for the future AA explosion box based on the above and as you suggest a counter that records the number of secs before the box should be created. The script checks each sec for aircraft entering, leaving zones and reduces counters for each target aircraft and when it reaches zero creates the explosion box at the calc'd position. Once a counter is zero then get the position and vector again? or do the position check each second so that each target has many counters running? The second sounds more realistic but means a lot of data held for each target.

 

I guess as I know you are very experienced in lua scripting, can you give me a high level idea of how you would go about this efficiently to get me ( thumbnail design type thing not code) started as it seems to me to be quite a different script to what I am doing now and much more complex due to the table manipulation I suspect is required (which I'm very weak on at present).

 

Thanks,

Stonehouse

Edited by Stonehouse
Posted (edited)

Sorry between painting and trying to figure out GGTharos's idea of the flak script I didn't finish what I meant to with the new version of the current script so won't post up a new version or mission today after all. Try to do so over the new couple of days before my holiday is over but a lot depends on how the work on the house goes.

 

<edit> didn't have time to finish the wip script but felt I owed people something so did a quick recording of a test run of Sithspawn's original mission with my half baked script and his full one used together. I reduced the number of aircraft just to make it easier to keep things in screen. As you hopefully can see his script does a background effect to flesh out the barrage while mine actually goes for the planes. As luck would have it the 4 P51s ironically survived the first high skill attack and the lost a flight member to the low skill battery near the airfield. Sorry tired and couldn't figure out the youtube embedding here, quality isn't that great either due to crappy net connections offered in Australia.

 

https://www.youtube.com/watch?v=T-61-dyU5Es&feature=youtu.be

Edited by Stonehouse
Posted (edited)

Ok here's the wip script. It works but I feel the values may still need tweaking after play testing to get a better idea of an average damage for the different skill zones. I still intend to turn it into a function along with Sithspawn's script as mentioned several posts back but then I will try to do what GGTharos has suggested. I think that will take me a fair bit of time though as I'll have to get up to speed with a lot of different bits of lua as well as come up with some sort of approach for a solution as I don't think the way we do it now will be good enough. Obviously someone better at lua scripting with more idea about what it can and can't do and the tricks and traps may already see how to do it.

 

Anyway the script, theoretically you should only need to change the first three parameters to suit (1) the target side (2) the zone you attach it to (3) the AA battery skill you want to have (remember this is very much an average thing and wip) :

 

do

--parameter candidates

local _side = 'blue'

local _aaaZone = 'flak'

local _bttyskill = 'high' -- low med high battery skill

-- constants

local _hiDelay = 10

local _minAlt = 50

local _maxDmg = 10

local _maxAlt = 8000

-- defaults

local _shotRate = 5

local _altSprd = 250 -- altitude accuracy gives a plus/minus spread of this distance

local _NthErr = 250 -- North err gives error plus/minus spread of this distance

local _EstErr = 250 -- East err gives error plus/minus spread of this distance

local _factor1 = 2

local _factor2 = 2

-- init table

local sidePlanes = {}

-- for future function version as battery skill is optional parm and will default to med

if ((_bttyskill ~= 'low') and (_bttyskill ~= 'med') and (_bttyskill ~= 'high')) then

_bttyskill = 'med'

end

-- set skill attributes

if _bttyskill == 'low' then

_shotRate = 7

_altSprd = 250

_NthErr = 100

_EstErr = 100

_factor1 = 1.5

_factor2 = 3

elseif _bttyskill == 'med' then

_shotRate = 5

_altSprd = 100

_NthErr = 50

_EstErr = 50

_factor1 = 1.25

_factor2 = 2

elseif _bttyskill == 'high' then

_shotRate = 3

_altSprd = 75

_NthErr = 25

_EstErr = 25

_factor1 = 1

_factor2 = 1.5

end

-- calc lower spread/accuracy value

local _lowaltSprd = _altSprd * -1

local _lowNthErr = _NthErr * -1

local _lowEstErr = _EstErr * -1

-- get units for side

if _side == 'red' then sidePlanes = mist.makeUnitTable({'[red][plane]'})

else

sidePlanes = mist.makeUnitTable({'[blue][plane]'}) end

-- set up table entry for flak zone

local _zone = {}

_zone[1] = _aaaZone

-- get the units in the flak zone

local inZoneUnits = mist.getUnitsInZones(sidePlanes, _zone)

 

if (#inZoneUnits > 0) then

for i = 1, #inZoneUnits do

local _delay = math.random(0,_hiDelay)

if (_delay >= _shotRate) then

local _targetpos = inZoneUnits:getPosition().p

local _targetvel = inZoneUnits:getVelocity()

local _landht = land.getHeight{x = _targetpos.x, y = _targetpos.z}

local _lowNthvel = _targetvel.x * -1

local _lowEstvel = _targetvel.z * -1

local _lowAltvel = _targetvel.y * -1

local _aaAlt = _targetpos.y + _targetvel.y + math.random(_lowAltvel * _factor1, _targetvel.y * _factor2) - _landht + math.random(_lowaltSprd,_altSprd)

local _aaNth = _targetpos.x + math.random(_lowNthvel * _factor1,_targetvel.x * _factor2) + math.random(_lowNthErr,_NthErr)

local _aaEst = _targetpos.z + math.random(_lowEstvel * _factor1,_targetvel.z * _factor2) + math.random(_lowEstErr,_EstErr)

if ((_aaAlt >= _landht + _minAlt) and (_aaAlt <= _maxAlt)) then

local vec3= {

x=_aaNth,

y=_aaAlt,

z=_aaEst

}

trigger.action.explosion(vec3, math.random(1,_maxDmg))

end

end

end

end

end

 

In the above the _factor1,2 are intended to influence how far back along the velocity component vector the explosion can come as well as how far in front in can appear to try to give some look of target bracketing and the spread and err is just meant as a way of introducing inaccuracy. They probably could have been combined but it kind of grew over a period of time and it gives it a bit more tweakability for the skill levels. You will see the flak "track" planes as they change their velocity vector by speed and height changes. Slowing down is not a good idea as it reduces the velocity vector size and the explosions will get closer to your position even with the randomness I introduce.

 

Next is the attached test mission I use when trying out script changes. At zone "test" you have the earlier script that doesn't use velocity. At zone "flak" you have the script above with a couple of formations of various aircraft types and the two sides. While at Flakzone1 you have a sample of a very simple airfield attack scenario with a composite of Sithspawn's script used according to my interpretation of it's use and my script above.

 

As far as I know I don't have any crash bugs in the above script or mission but it is wip and my test mission so I may have missed something. Note that there is no need to name the trigger the same as the zone and I just do that to make life easier and ditto my naming scheme for Flak10,Flak11 etc. It just tells me it's Flak gun 0 for Flakzone1.

 

Hope it works ok for everyone. It certainly has given some extra life to the P51 missions the group I'm with are flying and given a boost to interest levels for the members who are mainly WW2 fans.

test.miz

Edited by Stonehouse
  • Like 2
Posted

its a beauty ! thanks Stonehouse and Sithspawn!!! I made a mission and have incorporated the latest zone flak version.

 

I also have now placed it in all my other P51 missions.

 

Can't thank you both enough! +1 if i can..

ASUS Tuf Gaming Pro x570 / AMD Ryzen 7 5800X @ 3.8 / XFX Radeon 6900 XT / 64 GB DDR4 3200 

"This was not in the Manual I did not read", cried the Noob" - BMBM, WWIIOL

Posted (edited)

ok some good news. I've converted the script above plus Sithspawn's into a script file that is loaded at mission start and then you can just call functions with parameters on your flak zones. It's been pretty much during my lunch time at work after reading up on how to do it on the train into the office so it may have some issues although I haven't seen any problems yet. Script file and sample mission is attached. Additionally I have got a prototype of the completely new solution based on actual time of flight of the shells well in progress and have begun testing and removing the (copious) bugs. You'll probably see a post up in the scripting beginners thread in the next day or so if I can't get a global multidimensional table working properly so if you more experienced lua coders can keep an eye out for it I'd appreciate your help.

 

<edit> it occurred to me overnight that instead of the once trigger with the do script file for flak.lua as in the sample mission that I probably could have just stuck it as a second do script file after the one for Mist on the mission start trigger. I haven't tried it yet (at work) but it would most likely work just as well

 

Cheers,

Stonehouse

flak.lua

newflaktest1.miz

Edited by Stonehouse
Posted

Sorry I spoke much too soon about the new flight time based version and I've hit some pretty major roadblocks and will have to either learn enough to get past them or do a redesign so I won't be coming out with it for quite a while.

 

Just to double check the existing flak.lua and the method of setup and compatibility with 1.2.8 and Mist 3.3 I've also updated my user files mission "Wolf in the fold" to v1.3 and added flak around the place for both sides. Interestingly by itself the vector based script looks really quite good as flak from a few ships - there are a couple of blue cargo ships in the mission and I added a static zone over them since they are quite slow moving. Not sure if a moving zone can be added to a naval unit but that would be an interesting experiment if it could be.

Posted

hey stonehouse,

 

it is possible to edit your script to fire the flak higher?

 

I am using it around the lake ritsa area and the flak is staying very low.... it's like its always ASL and doesnt compensate for the altitude of the town..

ASUS Tuf Gaming Pro x570 / AMD Ryzen 7 5800X @ 3.8 / XFX Radeon 6900 XT / 64 GB DDR4 3200 

"This was not in the Manual I did not read", cried the Noob" - BMBM, WWIIOL

Posted (edited)

Hi Dooom, yes definitely can change the altitude limits on firing although it should be firing between (at work so from memory) 150m to 8000m above the land height of the target's current position. At the start of the script there should be local vars set up with min and max altitudes (150 and 8000 respectively) and these variables are used to decide whether to allow the shot to be fired.

 

Can you put up a sample mission containing the situation you mean in case you've found a bug in what I've done please? Perhaps I've flipped a sign around or my cut and pasting from one version to another has let me down again. In any case I'll double check things this evening as I can't download stuff here.

 

Cheers,

Stoney

 

<edit> actually don't worry I found I had a copy of the script here that is close to the version I uploaded. Looking at it I can see that while I've taken the land ht off the tgt y co-ordinate to get it's true altitude to check against the 150-8000 limits I have not added it back when I create the explosion so it would tend to be always low by the land ht at the tgt position. I will fix this and reupload a new version this evening, lol and fix my own missions too. You might find that 'high' skill is going to be too accurate now at lot of the time which might lead to be being tweaked.

 

Thanks for finding the bug Dooom.

Edited by Stonehouse
Posted (edited)

Update version here. I did some other changes to get the rate of fire closer to what it should be as well.

 

Script below and attached is script file and mission. To update any existing mission you should be able to just change the DO SCRIPT FILE to point at the new version flakv1.lua.

 

Please note that I now recommend that you load this script on a mission start trigger with first MIST and then flakv1.lua as I found that if you had a target aircraft in a flak zone initially you would get a crash because the flak script hadn't loaded - loading mist and flakv1.lua on a mission start trigger avoids any possible issue - see example mission to see what I mean. The mission I've attached is an updated version of the prior to show some possibilities and skill levels. Please give it a good run and let me know if you have problems.

 

Cheers,

Stoney

 

Uploaded to userfiles with Sithspawns permission http://www.digitalcombatsimulator.com/en/files/683612/

 

Script:

flak = {}

--[[

-- *Version1 5 May 2014 flakv1.lua SithSpawn, Stonehouse

-- amendments to rate of fire logic to try to get closer to historic 15-25 rounds per min where 15 is low and 25 is high

-- correction to altitude of flak explosion (thanks Dooom for spotting the error and reporting it)

-- *Version0 30 April 2014 flak.lua SithSpawn, Stonehouse

-- Published in DCS forums http://forums.eagle.ru/showpost.php?p=2054641&postcount=46

-- **Credits

-- flak.fill function is very closely based on the original script authored by SithSpawn with minor tweaks to add altitude and damage limits by Stonehouse

-- and all credit and acknowledgment should be given to SithSpawn for this function which creates random flak bursts in a zone every second.

-- flak.attack function was created by Stonehouse based on the idea of using the target's velocity vector to create a "tracking" algorithm to

-- loosely simulate a flak battery trying to track targets and calculate a lead firing solution for them and attempting to

-- incorporate an average battery skill to control shot accurracy, spread and rate of fire

-- ***Usage

-- Load Mistv3_3.lua on a mission start trigger using DO SCRIPT FILE

-- On the same mission start trigger add another DO SCRIPT FILEand load flakv1.lua after MIST

-- create a trigger zone with a unique name to represent the flak battery zone of fire

-- If desired create smaller zones within this main trigger zone over towns, airfields etc

-- For each main trigger zone create a continuous trigger with at least the condition of part of coalition red/blue in zone name of main trigger zone

-- and then for the trigger actions add a DO SCRIPT for each smaller zone that executes DO flak.fill('XXXX') END where XXXX is the name of the small

-- trigger zone and then a DO SCRIPT for the main zone that executes DO flak.attack('SSSS','YYYY','KKKK') END where SSSS is either red or blue according to

-- which side is to be attacked by the flak, YYYY is the name of the main zone and KKKK is either low, med or high according to the skill of the flak.

-- Create as many of the above main zone, smaller zone combinations as desired with a continuous trigger for each. Note that you can leave out the

-- attack function is you just want a random flak effect in a zone or if trying to represent ship board flak you might use the attack function but not

-- the fill function.

--]]

 

-- constants

_minAlt = 150 -- min alt for Flak 88?

_maxAlt = 8000 -- max alt for Flak 88

_maxDmg = 10 -- simulates the 9.4 kg shell for Flak 88?

function flak.fill(_parm1)

local _zonename = _parm1

local pos = trigger.misc.getZone(_zonename)

 

local newpoint = mist.getRandPointInCircle(pos.point, pos.radius)

 

local vec3 = {

x = newpoint.x,

y = land.getHeight(newpoint) + mist.random(_minAlt, _maxAlt),

z = newpoint.y

}

 

trigger.action.explosion(vec3, _maxDmg)

end

 

function flak.attack(_parm2, _parm3, _parm4)

--parameters

local _side = _parm2 -- eg 'blue'

local _aaaZone = _parm3 -- eg 'flak'

local _bttyskill = _parm4

--constants

local _hiDelay = 60

local _shotRate = 46

local _spread = 500

local _altSprd = 250 -- altitude accuracy gives a plus/minus spread of this distance

local _NthErr = 250 -- North err gives error plus/minus spread of this distance

local _EstErr = 250 -- East err gives error plus/minus spread of this distance

local _factor1 = 2

local _factor2 = 2

 

-- init table

local sidePlanes = {}

 

-- battery skill is optional parm and will default to med

if ((_bttyskill ~= 'low') and (_bttyskill ~= 'med') and (_bttyskill ~= 'high')) then

_bttyskill = 'med'

end

 

-- set skill attributes, recall that this script is attached to a continuous trigger so is executed every second

if _bttyskill == 'low' then

_shotRate = 45 -- approx 15 in 60 chance of firing at each target so roughly 15 shots per min or roughly 1 shot every 4 secs per target

_altSprd = 250

_NthErr = 100

_EstErr = 100

_factor1 = 1.5

_factor2 = 3

elseif _bttyskill == 'med' then

_shotRate = 40 -- approx 20 in 60 chance of firing at each target so roughly 20 shots per min or roughly 1 shot every 3 secs per target

_altSprd = 100

_NthErr = 50

_EstErr = 50

_factor1 = 1.25

_factor2 = 2

elseif _bttyskill == 'high' then

_shotRate = 35 -- approx 25 in 60 chance of firing at each target so roughly 25 shots per min or roughly 1 shot every 2 secs per target

_altSprd = 75

_NthErr = 25

_EstErr = 25

_factor1 = 1

_factor2 = 1.5

end

 

-- calc lower spread/accuracy value

local _lowaltSprd = _altSprd * -1

local _lowNthErr = _NthErr * -1

local _lowEstErr = _EstErr * -1

 

-- get units for side

if _side == 'red' then sidePlanes = mist.makeUnitTable({'[red][plane]'})

else

sidePlanes = mist.makeUnitTable({'[blue][plane]'})

end

 

-- set up table entry for flak zone

local _zone = {}

_zone[1] = _aaaZone

 

-- get the target units in the flak zone

local inZoneUnits = mist.getUnitsInZones(sidePlanes, _zone)

 

-- for each target

if (#inZoneUnits > 0) then

for i = 1, #inZoneUnits do

 

-- decide whether to shoot or not according to skill

local _delay = math.random(1,_hiDelay)

if (_delay >= _shotRate) then

 

-- get current position and velocity vector

local _targetpos = inZoneUnits:getPosition().p

local _targetvel = inZoneUnits:getVelocity()

 

-- get the land height at target position

local _landht = land.getHeight{x = _targetpos.x, y = _targetpos.z}

 

-- get neg velocity vector components

local _lowNthvel = _targetvel.x * -1

local _lowEstvel = _targetvel.z * -1

local _lowAltvel = _targetvel.y * -1

 

-- get target true altitude above ground level

local _tgtAlt = _targetpos.y + _targetvel.y + math.random(_lowAltvel * _factor1, _targetvel.y * _factor2) - _landht + math.random(_lowaltSprd,_altSprd)

 

-- get north and east bearing of shot according to skill

local _aaNth = _targetpos.x + math.random(_lowNthvel * _factor1,_targetvel.x * _factor2) + math.random(_lowNthErr,_NthErr)

local _aaEst = _targetpos.z + math.random(_lowEstvel * _factor1,_targetvel.z * _factor2) + math.random(_lowEstErr,_EstErr)

 

-- If the target within altitude limits of flak gun

if ((_tgtAlt >= _minAlt) and (_tgtAlt <= _maxAlt)) then

 

-- get shot final 3D co-ords

local vec3= {

x=_aaNth,

y=_tgtAlt+_landht,

z=_aaEst

}

 

-- explode the shell, strength of attack between 1 and max damage (throwing some luck into the mix)

trigger.action.explosion(vec3, math.random(1,_maxDmg))

end

end

end

end

end

test.miz

flakv1.lua

Edited by Stonehouse
add link to user files
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...