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