Random artillery fire

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
LorenAgus
Posts: 12
Joined: Wed Nov 24, 2021 3:00 pm

Random artillery fire

Post by LorenAgus »

Hello. First of all, sorry for my English. I am not an LUA expert. Until now I have only asked questions, but thanks to what I have learned in this forum, I have been able to make a small script and I would like to share it in case it helps someone.
Surely there will be other, more efficient ways to do it, but my little knowledge of LUA has only allowed me to do it this way. The important thing is that it works.
Context: The enemy side has several artillery batteries deployed near the FLOT (Forward Line of Own Troops). They have no contact about us. So they decide to launch artillery fire towards an area where they think we can be.
The script fires artillery in a 1km radius circular area centered on a preset RP.

local N = ScenEdit_GetReferencePoint( { side="RUSSIA", name="ART1"} )
local PosX = N.longitude
local PosY = N.latitude
math.randomseed(os.time());
local NM = math.random(0,1000)
local d = NM / 1800
local b = math.random(1,360)
local weap = math.random(1,3)
local head
if weap ==1
then
head = 786
else
if weap == 2
then
head = 54
else
head = 314
end
end
ScenEdit_AddUnit({type ='Ground Unit', unitname ='A', dbid =326, side ='RUSSIA', Lat=PosY,Lon=PosX})
local Civ = ScenEdit_GetUnit( { side='RUSSIA', unitname='A'} )
local lat = Civ.latitude
local lon = Civ.longitude
local point = ScenEdit_AddReferencePoint( {side='RUSSIA', name='IMPACT', RelativeTo='A', bearing=b ,distance=d })
ScenEdit_DeleteUnit( { side="RUSSIA", unitname='A' } )
local elevation = World_GetElevation({latitude=lat, longitude=lon})
local RP = ScenEdit_GetReferencePoint( { side="RUSSIA", name="IMPACT"} )
local ExplLat = RP.latitude
local ExplLon = RP.longitude
ScenEdit_DeleteReferencePoint( { side="RUSSIA", name='IMPACT' } )
ScenEdit_AddExplosion({warheadid = head, latitude = ExplLat, longitude = ExplLon, altitude = elevation})


I have chosen three different types of ammunition, corresponding to each of the different types of artillery deployed.
Once I have this script what I do is create a repeatable event so that, for example, every 30 seconds it triggers, so that every 30 seconds there is a random munition explosion at a random position within the defined area ( in this case 1km).
Parel803
Posts: 941
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: Random artillery fire

Post by Parel803 »

Good evening,

Thx for sharing

best regards GJ
LorenAgus
Posts: 12
Joined: Wed Nov 24, 2021 3:00 pm

Re: Random artillery fire

Post by LorenAgus »

Sorry, but the first line is missing "})". It should look like this:

local N = ScenEdit_GetReferencePoint( { side="RUSSIA", name="ART1"} )
Post Reply

Return to “Lua Legion”