LUA Scripting:- Random Jamming, Possible? (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


butch4343 -> LUA Scripting:- Random Jamming, Possible? (9/14/2017 12:48:24 PM)

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




Gunner98 -> RE: LUA Scripting:- Random Jamming, Possible? (9/14/2017 10:42:35 PM)

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




somi83 -> RE: LUA Scripting:- Random Jamming, Possible? (9/15/2017 3:58:05 AM)

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:
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 '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.




butch4343 -> RE: LUA Scripting:- Random Jamming, Possible? (9/15/2017 7:18:56 AM)

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




Rory Noonan -> RE: LUA Scripting:- Random Jamming, Possible? (9/15/2017 8:48:47 AM)

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:

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 [:)]




butch4343 -> RE: LUA Scripting:- Random Jamming, Possible? (9/19/2017 9:30:42 AM)

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




butch4343 -> RE: LUA Scripting:- Random Jamming, Possible? (1/12/2018 11:28:26 AM)

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


[image]local://upfiles/51353/6BCE95B5BE2A4D53B4FBBB8EF6955E03.jpg[/image]




Gunner98 -> RE: LUA Scripting:- Random Jamming, Possible? (1/12/2018 12:09:02 PM)

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




stilesw -> RE: LUA Scripting:- Random Jamming, Possible? (1/12/2018 3:13:44 PM)

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




msc -> RE: LUA Scripting:- Random Jamming, Possible? (1/12/2018 7:07:44 PM)

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.




michaelm75au -> RE: LUA Scripting:- Random Jamming, Possible? (1/12/2018 10:59:25 PM)

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.




stilesw -> RE: LUA Scripting:- Random Jamming, Possible? (1/15/2018 2:15:38 PM)

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




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.453125