Jump to content

1.2.6 Scripting Engine Changes.


Grimes

Recommended Posts

The ED wiki is still locked down due to spam, so I have uploaded the scripting engine documentation to the hoggit wiki. I'll also be working toward reformatting the documentation to be a little bit easier to use. But its going to take a long time to complete MIST and SSE documentation, not to mention learning how to best format stuff using wiki.

 

The changelog for 1.2.6 scripting engine is as follows.

 

atmosphere singleton was added

Unit.getCallsign() function was added

Airbase.getDescByName() function was added

Airbase.getCallsign() function was added

Controller.getDetectedTargets() and Controller.knowTarget() functions were added

Controller.isTargetVisible() was modified

Spot class was added

Group.getSize() now returns current size

Group.getInitialSize() function was added

 

Full documentation can be found here: http://wiki.hoggit.us/view/Simulator_Scripting_Engine_Documentation

 

Things of note:

As you can see getSize is now a "getCurrentSize" type of function. getInitialSize has been added and functions the way getSize worked up to 1.2.4.

atmosphere functions have been added to simply get the wind and turbulence values at a vec3 point.

Spot class allows you to spawn in a laser to illuminate a target with an IR pointer or for laser guided weapons.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

noob question: how do I access a singleton (i.e. "atmosphere") from within the Export.lua?

 

I am trying to generate a log file with the current wind conditions during the flight. But when I try to access the properties of "atmosphere", DCS.log tells me:

58: attempt to index global 'atmosphere' (a nil value)


Edited by Flagrum
Link to comment
Share on other sites

Spot class allows you to spawn in a laser to illuminate a target with an IR pointer or for laser guided weapons..

Cooooool!!! This will make Special Ops much easier! No more hope the guy has LOS etc.:D

Shagrat

 

- Flying Sims since 1984 -:pilotfly:

Win 10 | i5 10600K@4.1GHz | 64GB | GeForce RTX 3090 - Asus VG34VQL1B  | TrackIR5 | Simshaker & Jetseat | VPForce Rhino Base & VIRPIL T50 CM2 Stick on 200mm curved extension | VIRPIL T50 CM2 Throttle | VPC Rotor TCS Plus/Apache64 Grip | MFG Crosswind Rudder Pedals | WW Top Gun MIP | a hand made AHCP | 2x Elgato StreamDeck (Buttons galore)

Link to comment
Share on other sites

  • 4 weeks later...
Can somone post an example of how to use the spot class? I have tried for awhile and cannot get it working.

 

Finally got around to messing with this. With a little help from BAntDit, here's a simple working example (in spoiler) for generating an IR pointer and laser:

 

 

function SparkleLase(OriginGroupName, TargetGroupName, LCode)

local OriginGroup, TargetGroup = Group.getByName(OriginGroupName), Group.getByName(TargetGroupName)

local OriginUnits, TargetUnits = OriginGroup:getUnits(), TargetGroup:getUnits()

local TargetVec3 = TargetUnits[1]:getPoint()

local TargetAdjVec3 = {x = TargetVec3.x, y = TargetVec3.y + 2, z = TargetVec3.z}

Spot.createInfraRed(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3)

Spot.createLaser(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3, LCode)

end

 

SparkleLase('Group1', 'Group2', 1444)

 

 

Note that I raised the beam 2m off ground at the generating object and at the target point. If you use defaults, the beam is on the ground.

Link to comment
Share on other sites

  • 1 month later...
Finally got around to messing with this. With a little help from BAntDit, here's a simple working example (in spoiler) for generating an IR pointer and laser:

 

 

function SparkleLase(OriginGroupName, TargetGroupName, LCode)

local OriginGroup, TargetGroup = Group.getByName(OriginGroupName), Group.getByName(TargetGroupName)

local OriginUnits, TargetUnits = OriginGroup:getUnits(), TargetGroup:getUnits()

local TargetVec3 = TargetUnits[1]:getPoint()

local TargetAdjVec3 = {x = TargetVec3.x, y = TargetVec3.y + 2, z = TargetVec3.z}

Spot.createInfraRed(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3)

Spot.createLaser(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3, LCode)

end

 

SparkleLase('Group1', 'Group2', 1444)

 

 

Note that I raised the beam 2m off ground at the generating object and at the target point. If you use defaults, the beam is on the ground.

 

Thanks JoyRide!

Link to comment
Share on other sites

Finally got around to messing with this. With a little help from BAntDit, here's a simple working example (in spoiler) for generating an IR pointer and laser:

 

 

function SparkleLase(OriginGroupName, TargetGroupName, LCode)

local OriginGroup, TargetGroup = Group.getByName(OriginGroupName), Group.getByName(TargetGroupName)

local OriginUnits, TargetUnits = OriginGroup:getUnits(), TargetGroup:getUnits()

local TargetVec3 = TargetUnits[1]:getPoint()

local TargetAdjVec3 = {x = TargetVec3.x, y = TargetVec3.y + 2, z = TargetVec3.z}

Spot.createInfraRed(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3)

Spot.createLaser(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3, LCode)

end

 

SparkleLase('Group1', 'Group2', 1444)

 

 

Note that I raised the beam 2m off ground at the generating object and at the target point. If you use defaults, the beam is on the ground.

 

Joyride,

 

Is there a way to make the laser/ir follow a target when it moves?

Link to comment
Share on other sites

Joyride,

 

Is there a way to make the laser/ir follow a target when it moves?

 

Looks like you would use the mist.scheduleFunction to call SparkleLase at a set interval to get the new location of the unit.

 

Though you may have some problems in situations where the ground elevation gets in the way and the laser points to the ground.

 

I imagine you'll have to modify the SparkleLase method to check if the unit is within the line of site (land.isVisible), if false then cut off the laser.

314-я смешанная авиационная дивизия

314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119

Link to comment
Share on other sites

Looks like you would use the mist.scheduleFunction to call SparkleLase at a set interval to get the new location of the unit.

 

Though you may have some problems in situations where the ground elevation gets in the way and the laser points to the ground.

 

I imagine you'll have to modify the SparkleLase method to check if the unit is within the line of site (land.isVisible), if false then cut off the laser.

 

Last question could you use a flag false or unit alive command to turn off the script? Thanks for the above answer, I am new to .lua, but love its capabilities.

Link to comment
Share on other sites

Last question could you use a flag false or unit alive command to turn off the script? Thanks for the above answer, I am new to .lua, but love its capabilities.

 

What do you mean by turn off the script?

 

If you mean to stop the MIST scheduled function, at the beginning of your function you can check the status of a flag

 

number function trigger.misc.getUserFlag(string userFlagName)
function trigger.action.setUserFlag(string userFlagName, boolean or number userFlagValue)

 

Remember when setting a flag to put the flag name in quotes.

 

And if you no longer require the MIST scheduled function use:

 

http://wiki.hoggit.us/view/RemoveFunction

314-я смешанная авиационная дивизия

314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119

Link to comment
Share on other sites

Ranger, this (below) updates it once every tenth of a second and follows a target. As number3 pointed out, you'd need to add a LOS check to avoid terrain potentially getting in the way. Haven't had time to get there yet, but would be pretty easy to roll incorporate using MIST.

 

	function SparkleLase(OriginGroupName, TargetGroupName, LCode)
	local OriginGroup, TargetGroup = Group.getByName(OriginGroupName), Group.getByName(TargetGroupName)
	local OriginUnits, TargetUnits = OriginGroup:getUnits(), TargetGroup:getUnits()			
	local spots = {}
	local TargetVec3 = TargetUnits[1]:getPoint()													
	local TargetAdjVec3 = {x = TargetVec3.x, y = TargetVec3.y + 2, z = TargetVec3.z} 		
	local status, result = pcall(function () 
		spots['Sparkle'] = Spot.createInfraRed(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3)					
		spots['Laser'] = Spot.createLaser(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3, LCode)
	return spots
	end)
	if not status then
		env.error('ERROR: ' .. assert(result), false)
	else
		if result.Sparkle then
			local Sparkle = result.Sparkle
			function KillSparkle()
				Spot.destroy(Sparkle)
			end
			function UpdateSparkleLase()
				KillSparkle()
				KillLase()
				SparkleLase(OriginGroupName, TargetGroupName, LCode)
			end	
			timer.scheduleFunction(UpdateSparkleLase, nil, timer.getTime() + 0.1)
		end
		if result.Laser then
			local Laser = result.Laser
			function KillLase()
				Spot.destroy(Laser)
			end
		end
	end
end

Link to comment
Share on other sites

  • 2 weeks later...

Reschedule the function to draw a new laser. As far as I understand the game doesn't have an issue with constantly redrawing the laser to follow moving targets. I'm honestly not entirely sure if removing itself after 60 seconds is on purpose or a bug.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Reschedule the function to draw a new laser. As far as I understand the game doesn't have an issue with constantly redrawing the laser to follow moving targets. I'm honestly not entirely sure if removing itself after 60 seconds is on purpose or a bug.

 

Tried, worked if only one target is used, but if you set a trigger to laze another target (after first is destroyed) the laser turns off after about 130-150 seconds.

Link to comment
Share on other sites

Got her working, added a schedule function to the script, works pretty good:

 

function SparkleLase(OriginGroupName, TargetGroupName, LCode)
   local OriginGroup, TargetGroup = Group.getByName(OriginGroupName), Group.getByName(TargetGroupName)
   local OriginUnits, TargetUnits = OriginGroup:getUnits(), TargetGroup:getUnits()            
   local spots = {}
   local TargetVec3 = TargetUnits[1]:getPoint()                                                    
   local TargetAdjVec3 = {x = TargetVec3.x, y = TargetVec3.y + 2, z = TargetVec3.z}         
   local status, result = pcall(function () 
       spots['Sparkle'] = Spot.createInfraRed(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3)                    
       spots['Laser'] = Spot.createLaser(OriginUnits[1], {x = 0, y = 2, z = 0}, TargetAdjVec3, LCode)
   return spots
   end)
   if not status then
       env.error('ERROR: ' .. assert(result), false)
   else
       if result.Sparkle then
           local Sparkle = result.Sparkle
           function KillSparkle()
               Spot.destroy(Sparkle)
           end
           function UpdateSparkleLase()
               KillSparkle()
               KillLase()
               SparkleLase(OriginGroupName, TargetGroupName, LCode)
           end    
           mist.scheduleFunction(UpdateSparkleLase, {'Group1', 'DET_HELO', 1444}, timer.getTime() + 0.5, 36000)
       end
       if result.Laser then
           local Laser = result.Laser
           function KillLase()
               Spot.destroy(Laser)
           end
       end
   end
end

 

Called with:

 

SparkleLase('Group1', 'DET_HELO', 1444)

 

The weird thing is I can add another DO SCRIPT (example below), which activates once GROUP DEAD (DET_HELO group) and the IR/Laser will switch to the tar1 target, works great! It even switches to different targets in a group until all targets are down, pretty neat!

 

SparkleLase('Group1', 'tar1', 1444)

 

Proof of Concept Video:

 


Edited by Ranger79
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...