LUA Scripting:- Random Jamming, Possible?
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
LUA Scripting:- Random Jamming, Possible?
Folks,
I wonder if this is possible, can a script be devised to allow for random jamming?
I have a scenario where I have some Tornados striking targets deep in enemy territory, I don’t want the player to control the EF-111 so I have stuck that in a separate side, and set up a support mission.
What I would like to do, is create a script or learn to utilise someone elses, where once on station the EF111 randomly jams and randomly doesn’t. So that sometimes the players Tornados will benefit from the jamming, but the player cant rely or control that.
Is that something that can be done?
Regards
Butch
I wonder if this is possible, can a script be devised to allow for random jamming?
I have a scenario where I have some Tornados striking targets deep in enemy territory, I don’t want the player to control the EF-111 so I have stuck that in a separate side, and set up a support mission.
What I would like to do, is create a script or learn to utilise someone elses, where once on station the EF111 randomly jams and randomly doesn’t. So that sometimes the players Tornados will benefit from the jamming, but the player cant rely or control that.
Is that something that can be done?
Regards
Butch
RE: LUA Scripting:- Random Jamming, Possible?
Have not tested anything like this but wouldn't two 'random time' triggers on repeatable events work. One to switch the jammers off and one to switch them on.
I think this would be pretty chaotic so perhaps there is a slick Lua solution out there.
B
I think this would be pretty chaotic so perhaps there is a slick Lua solution out there.
B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
RE: LUA Scripting:- Random Jamming, Possible?
Hi,
You can activate or deactivate that jamming support mission at the start of the scenario with this:
use scenario has started trigger
and for action use this Lua code:
- Instead of 'side' use the name of the side with that support mission
- Instead of 'mission' use the name of the that support mission
This will give a 50/50 chance when you or somebody starts the scenario, that support mission will be active or not.
You can activate or deactivate that jamming support mission at the start of the scenario with this:
use scenario has started trigger
and for action use this Lua code:
Code: Select all
math.randomseed(os.time())
math.random(); math.random()
local num = math.random(1,100)
if num <=50 then ScenEdit_SetMission('side', 'mission', {isactive=true})
elseif num > 50 then ScenEdit_SetMission('side', 'mission', {isactive=false})
end
- Instead of 'mission' use the name of the that support mission
This will give a 50/50 chance when you or somebody starts the scenario, that support mission will be active or not.
RE: LUA Scripting:- Random Jamming, Possible?
Somi83/Gunner98
Thanks for the reply, Somi83 I think I havent been clear with what Im looking to do, when my EF111 gets on station, is there a script I can use to make its OECM random?
Regards
Butch
Thanks for the reply, Somi83 I think I havent been clear with what Im looking to do, when my EF111 gets on station, is there a script I can use to make its OECM random?
Regards
Butch
- Attachments
-
- TEST3Bri..nEurope.zip
- (341.39 KiB) Downloaded 13 times
-
- Posts: 2418
- Joined: Thu Dec 18, 2014 1:53 am
- Location: Brooklyn, NY
RE: LUA Scripting:- Random Jamming, Possible?
Hi butch,
This is a bit of a 'piece of string' in that you can make this uber complex or fairly simple. Given that you're asking for an example I will go for something you can tinker with easily.
Set up an event that triggers when the EF-111 is on station (e.g. a 'remains in area' trigger, pick a time that suits, make it repeatable), and have the action be a Lua script like so:
When the EF-111 is on station, the event will fire every X minutes with the 'remains in area' trigger. Each time that happens, there is a percent chance that the OECM will turn/remain on, otherwise it will turn/remain off.
This could be simplified quite a lot but I wrote it so that you can easily change the variables without having to trial-and-error which bits to change [:)]
This is a bit of a 'piece of string' in that you can make this uber complex or fairly simple. Given that you're asking for an example I will go for something you can tinker with easily.
Set up an event that triggers when the EF-111 is on station (e.g. a 'remains in area' trigger, pick a time that suits, make it repeatable), and have the action be a Lua script like so:
Code: Select all
math.randomseed(os.time()) --Inititates a new random seed based on your system time, this makes the numbers more 'random', otherwise you will get fairly similar results every time
unitname = 'xxxx' --Your unit name goes here replacing xxxx, make sure to leave the inverted commas, must be an exact match
unitside = 'yyyy' --Your unit's side name goes here replacing yyyy, same constraints as above
percent = 50 --The percentage chance that the emcon will change turn/remain on
unit = ScenEdit_GetUnit({side=unitside,name=unitname}) --gets the unit data based on what you entered above
if unit ~= nil then --Checks to see if there's a unit with that name/side
roll = math.random(1,100) --generates a random number, simulating a 100 sided dice roll
if roll <= percent then
ScenEdit_SetEmcon('Unit',unit.guid,'OECM=Active') --what happens if the percentage threshold is met, in this case set OECM to active
else
ScenEdit_SetEmcon('Unit',unit.guid,'OECM=Passive') --what happens if the percentage threshold is not met, in this case set OECM to passive
end --Ends the 'roll' if/else statement
else
ScenEdit_MsgBox("Couldn't find a unit with that name or side -- is it possible the jammer died?", 6) -- An error message to let you know what's wrong if it doesn't fire, you can delete this line once you've got it working in testing if you like and nothing will change
end
When the EF-111 is on station, the event will fire every X minutes with the 'remains in area' trigger. Each time that happens, there is a percent chance that the OECM will turn/remain on, otherwise it will turn/remain off.
This could be simplified quite a lot but I wrote it so that you can easily change the variables without having to trial-and-error which bits to change [:)]

RE: LUA Scripting:- Random Jamming, Possible?
Guys,
Apoligies in delaying my reply, but thank you for yet again taking the time to help me, and explaining the above script, I have a good understanding of what each line does.
Im indebted to you and all the folks on here who have assisted me.
Regards
Butch
Apoligies in delaying my reply, but thank you for yet again taking the time to help me, and explaining the above script, I have a good understanding of what each line does.
Im indebted to you and all the folks on here who have assisted me.
Regards
Butch
RE: LUA Scripting:- Random Jamming, Possible?
Guys
I wonder if anyone could give me a little help with this script?
For some reason am getting an error as it thinks I havent closed properly, but for the life of me I cant work out why am getting it
My script is as below
math.randomseed(os.time())
unitname = 'Sandman #1'
unitside = 'Jamming'
percent = 50
unit = ScenEdit_GetUnit({side=unitside,name=unitname})
if unit ~= nil then
roll = math.random(1,100)
if roll <= percent then
ScenEdit_SetEmcon('Unit',unit.guid,'OECM=Active')
else
ScenEdit_SetEmcon('Unit',unit.guid,'OECM=Passive')
end
I end up with the following error
16 end expected (to close if at line 8)
Any ideas where I have gone wrong?
Ive included the screen print if that helps?
I feel such a doughnut for getting stuck with this [&:]
Kind regards
Butch

I wonder if anyone could give me a little help with this script?
For some reason am getting an error as it thinks I havent closed properly, but for the life of me I cant work out why am getting it
My script is as below
math.randomseed(os.time())
unitname = 'Sandman #1'
unitside = 'Jamming'
percent = 50
unit = ScenEdit_GetUnit({side=unitside,name=unitname})
if unit ~= nil then
roll = math.random(1,100)
if roll <= percent then
ScenEdit_SetEmcon('Unit',unit.guid,'OECM=Active')
else
ScenEdit_SetEmcon('Unit',unit.guid,'OECM=Passive')
end
I end up with the following error
16 end expected (to close if at line 8)
Any ideas where I have gone wrong?
Ive included the screen print if that helps?
I feel such a doughnut for getting stuck with this [&:]
Kind regards
Butch

- Attachments
-
- 1.jpg (43.44 KiB) Viewed 444 times
RE: LUA Scripting:- Random Jamming, Possible?
This is usually the 'hunt & peck' phase for me, finding all the syntax errors.
I think this one is that there is an 'if' statement started at line 8 and it is not closed off so you need an 'end' in line 16
B
I think this one is that there is an 'if' statement started at line 8 and it is not closed off so you need an 'end' in line 16
B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
RE: LUA Scripting:- Random Jamming, Possible?
Hi Butch,
Found a couple of things. Gunner98 correctly points out that there should be an "end" on the nil check. You should use the actual unit name instead of the guid statement. Also, Lua is unforgiving on spelling and capitalization. You need "ScenEdit_SetEMCON" instead of "ScenEdit_SetEmcon"
Here's your slightly modified code that I just used on one of my test scenarios. Hope this helps.
-Wayne Stiles
math.randomseed(os.time())
local unitname = 'Mahan'
local unitside = 'Blue'
local percent = 50
local unit = ScenEdit_GetUnit({side=unitside,name=unitname})
if unit ~= nil then end
roll = math.random(1,100)
if roll <= percent then
ScenEdit_SetEMCON('Unit','Mahan', 'OECM=Active')
else
ScenEdit_SetEMCON('Unit','Mahan', 'OECM=Passive')
end
Found a couple of things. Gunner98 correctly points out that there should be an "end" on the nil check. You should use the actual unit name instead of the guid statement. Also, Lua is unforgiving on spelling and capitalization. You need "ScenEdit_SetEMCON" instead of "ScenEdit_SetEmcon"
Here's your slightly modified code that I just used on one of my test scenarios. Hope this helps.
-Wayne Stiles
math.randomseed(os.time())
local unitname = 'Mahan'
local unitside = 'Blue'
local percent = 50
local unit = ScenEdit_GetUnit({side=unitside,name=unitname})
if unit ~= nil then end
roll = math.random(1,100)
if roll <= percent then
ScenEdit_SetEMCON('Unit','Mahan', 'OECM=Active')
else
ScenEdit_SetEMCON('Unit','Mahan', 'OECM=Passive')
end
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
RE: LUA Scripting:- Random Jamming, Possible?
You may also try a solution with different propabilities in event editor.
Take a look into "BALTAP-Repräsentative Schnellbootlage" scenario on CommunityScearioPack. Radars are activated and deactivated on "regular time"-triggers with different propabilities of events, so radar transmissions have a random activation time and duration.
Take a look into "BALTAP-Repräsentative Schnellbootlage" scenario on CommunityScearioPack. Radars are activated and deactivated on "regular time"-triggers with different propabilities of events, so radar transmissions have a random activation time and duration.
- michaelm75au
- Posts: 12457
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: LUA Scripting:- Random Jamming, Possible?
I personally prefer using the GUID if using a returned object, like unit. The logic is that often I have come across cases where a unit name is not always unique, and to complicate players can rename the unit (but it's GUID doesn't change), and it is possible the wrong 'unit' might be accessed.
Michael
RE: LUA Scripting:- Random Jamming, Possible?
Butch,
Couple of updates:
I put the "end" in the wrong place. Should be:
if unit ~= nil then
roll = math.random(1,100)
end
And, michaelm75au is right, you should probably use the unit = ScenEdit_GetUnit({guid=})instead of the side= and unit= method. That avoids any possible problems with having units with the same name.
-Wayne
Couple of updates:
I put the "end" in the wrong place. Should be:
if unit ~= nil then
roll = math.random(1,100)
end
And, michaelm75au is right, you should probably use the unit = ScenEdit_GetUnit({guid=})instead of the side= and unit= method. That avoids any possible problems with having units with the same name.
-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)