Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

LUA Scripting:- Random Jamming, Possible?

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> LUA Scripting:- Random Jamming, Possible? Page: [1]
Login
Message << Older Topic   Newer Topic >>
LUA Scripting:- Random Jamming, Possible? - 9/14/2017 12:48:24 PM   
butch4343

 

Posts: 327
Joined: 3/26/2015
Status: offline
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
Post #: 1
RE: LUA Scripting:- Random Jamming, Possible? - 9/14/2017 10:42:35 PM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
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

(in reply to butch4343)
Post #: 2
RE: LUA Scripting:- Random Jamming, Possible? - 9/15/2017 3:58:05 AM   
somi83


Posts: 59
Joined: 2/6/2016
From: Novi Sad, Serbia
Status: offline
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.

< Message edited by somi83 -- 9/15/2017 5:14:48 AM >

(in reply to Gunner98)
Post #: 3
RE: LUA Scripting:- Random Jamming, Possible? - 9/15/2017 7:18:56 AM   
butch4343

 

Posts: 327
Joined: 3/26/2015
Status: offline
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

Attachment (1)

(in reply to somi83)
Post #: 4
RE: LUA Scripting:- Random Jamming, Possible? - 9/15/2017 8:48:47 AM   
Rory Noonan

 

Posts: 2816
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
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

< Message edited by apache85 -- 9/15/2017 8:55:40 AM >

(in reply to butch4343)
Post #: 5
RE: LUA Scripting:- Random Jamming, Possible? - 9/19/2017 9:30:42 AM   
butch4343

 

Posts: 327
Joined: 3/26/2015
Status: offline
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

< Message edited by butch4343 -- 9/19/2017 9:32:13 AM >

(in reply to Rory Noonan)
Post #: 6
RE: LUA Scripting:- Random Jamming, Possible? - 1/12/2018 11:28:26 AM   
butch4343

 

Posts: 327
Joined: 3/26/2015
Status: offline
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





Attachment (1)

(in reply to butch4343)
Post #: 7
RE: LUA Scripting:- Random Jamming, Possible? - 1/12/2018 12:09:02 PM   
Gunner98

 

Posts: 5508
Joined: 4/29/2005
From: The Great White North!
Status: offline
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

(in reply to butch4343)
Post #: 8
RE: LUA Scripting:- Random Jamming, Possible? - 1/12/2018 3:13:44 PM   
stilesw


Posts: 1497
Joined: 6/26/2014
From: Hansville, WA, USA
Status: offline
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

(in reply to butch4343)
Post #: 9
RE: LUA Scripting:- Random Jamming, Possible? - 1/12/2018 7:07:44 PM   
msc

 

Posts: 108
Joined: 7/31/2013
From: Austria
Status: offline
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.

(in reply to stilesw)
Post #: 10
RE: LUA Scripting:- Random Jamming, Possible? - 1/12/2018 10:59:25 PM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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

(in reply to stilesw)
Post #: 11
RE: LUA Scripting:- Random Jamming, Possible? - 1/15/2018 2:15:38 PM   
stilesw


Posts: 1497
Joined: 6/26/2014
From: Hansville, WA, USA
Status: offline
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

< Message edited by stilesw -- 1/15/2018 2:16:23 PM >

(in reply to stilesw)
Post #: 12
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> LUA Scripting:- Random Jamming, Possible? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

1.203