Jump to content

Beginner script format assistance


ENO

Recommended Posts

Being a copy paste guy myself- as grimes said if I'm copying a script (as oppsed to writing my own) with the intention of modifying it, I'll modify it in notepad++ because its much easier.

 

Tip: instead of just copy paste, copy the code manually. It doesn't take that much longer time but you get a much better sense of what the code does and you learn quicker.

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

Thanks ragnarda da- that's a valid point.

 

As for the script not sure but must has a unit in moving zone which can set a flag (1-100 only) that you can use to set a condition for a hold that can have a stop condition of duration or whatever you choose. That's what I would do anyway.

 

Only issue is you'd need to do a time since flag 1-100 and turn it back off again as I'm not sure if mist turns it off when the aircraft is out of zone. Can't remember.


Edited by ENO

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

Check the flag status in either a script or a trigger and simply use either a triggered task "Group>Hold" or the script trigger.action.groupStopMoving(Group.getByName('whatever')). And then when to have them resume use the trigger "Group Resume" or trigger.action.groupContinueMoving(Group.getByName('whatever'))

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

Working on a thing here- basically just adjusted from the hogit wiki... I have this cloned for Patrol2 and Patrol3 as well...

 

This is the format from wiki:

 

vars =

{

groupName/groupTable = string/table groupName/groupTable,

useGroupRoute/route = string/table useGroupRoute/route,

speed = number speed,

offRoadForm = string offRoadForm,

onRoadForm = string onRoadForm,

patrolType = string patrolType,

}

 

This is the example given with my mods in there...

 

 

do

local vars = {}

vars.gpData = 'Patrol',

vars.offRoadForm = 'diamond',

vars.pType = 'doubleBack'

mist.ground.patrolRoute(vars)

end

 

 

Ends up in this:

 

 

00088.291 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

00089.222 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol2') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

00089.870 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol3') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

 

 

00064.311 ERROR DCS: Mission script error: : [string "do..."]:4: unexpected symbol near '='

00075.855 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

00076.591 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol2') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

00077.967 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol3') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'


Edited by ENO

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

I promise to make this quick grimes (or someone else)... I know this isn't your favourite.

 

Made the adjustments and tried it again on the server... The group itself just has a normal route... 3 road based waypoints... 4 total I think including the SP.

 

 

Figured out one problem... had an unneeded space on one of the names.

 

00058.007 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

00059.785 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol2') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

00061.064 ERROR DCS: Mission script error: : [string "if not Group.getByName('Patrol3') then..."]:3: 'end' expected (to close 'if' at line 1) near '<eof>'

 

 

Still getting this one though...


Edited by ENO

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

Did you remove the commas that are highlighted in red? I accidentally had left those in there because I used the alternative formatting while testing it.

 

do

local vars = {}

vars.gpData = 'Patrol',

vars.offRoadForm = 'diamond',

vars.pType = 'doubleBack'

mist.ground.patrolRoute(vars)

end

 

What I used in testing

 

mist.ground.patrolRoute({gpData = 'test2', offRoadForm= 'diamond', pType = 'doubleBack'})

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

Whoops- looking in the wrong place.

 

I think this is where the error message was coming from:

 

if not Group.getByName('Patrol') then

mist.respawnGroup('Patrol', true)

 

Sorry, I think I can figure this one out

 

 

Frick- yeah that was it. I thought the error message was something happening behind the scene. I saw from the error message I was missing an "end" - once that got put in it's fine.

 

Thanks for sticking with it.

 

Question though- what's the difference between ground patrol and ground patrol route? Is it just that you can add a route if it doesn't already have one?


Edited by ENO

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

mist.ground.patrolRoute() accepts a table of variables

mist.ground.patrol() uses multiple variables.

 

mist.ground.patrol() doesn't actually do much aside from putting the data into a format for mist.ground.patrolRoute(), which is the function that actually does all of the work and its the one that gets called again when the group reaches the end of their patrol route.

 

I originally just had the mist.ground.patrol() function but I had some modifications I wanted to make so I created a new function to do all of the work, but kept the original one around out of utility.

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

  • 3 months later...

Eh guys- I've put this out there a couple times but haven't got much feedback on it... not sure if it's because it's impossible or just because it didn't get any traction.

 

A couple threads that relate:

 

http://forums.eagle.ru/showthread.php?t=106213&highlight=pilot+eject

http://forums.eagle.ru/showthread.php?t=105700&highlight=pilot+eject

http://forums.eagle.ru/showthread.php?t=107303&highlight=pilot+eject

 

Anyway I'm trying to figure out a way to grab a coordinate from an ejected pilot (something we've already been able to manage through one of my earlier efforts as well as such scripts as the SAR medevac etc) and create a waypoint for AI vehicles.

 

The concept is to have recovery / capture groups from one or both sides to head to the ejected pilots location to retrieve him (her).

 

If there was a way to determine which one was closest- and activate that group... that would be perfect but all could converge until the pickup happened then return to their original locations or a random point.

 

Now in saying this- I know there are a variety of MIST functions that would be put to work here and I can do that homework... I just don't know how to tie it together.

 

 

Ooooh yes- and top it off with the capture group returning the prisoner to a compound with known coordinates that the huey and it's team need to put an assault on. Oh god- the potential... back to the MIST drawing board!

 

Going to put a few tools down here...

 

customEventHandler = {};

 

function customEventHandler:onEvent(event)

if (world.event.S_EVENT_EJECTION == event.id) then

local _location = event.initiator:getPoint();

local _time = timer.getTime();

 

local _latitude, _longtitude, _ = coord.LOtoLL(_location);

 

trigger.action.outText('Pilot ejected at point: latitude: ' .. string.format("%.3f", _latitude) .. ', longitude: ' .. string.format("%.3f", _longtitude), 10);

 

end

end;

 

world.addEventHandler(customEventHandler);

 

And this comment from Joyride:

 

Yeah, we've got a couple threads going :-)

 

All you need to do is remove "local" from the line "local _location = event.initiator:getPoint();" and it's now available in subsequent scripts to spawn a group/unit at that location.

 

Your x coordinates for the spawned group need to be "_location.x" and y is "_location.z"


Edited by ENO

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

Hi Eno! I thought I replied to about this aswell... :(

 

I really like your idea! If you want to measure the distance between two points you can have a look in the medevac script, I think there's a function called measure distance or something that you can just copy-paste. If you want to see a iteration through units to see which is closest have a look at my GCI-script here http://forums.eagle.ru/showpost.php?p=1845129 and if you want to see a example of units going for a de-tour and then continuing their mission have a look at modification of Mbots script: http://forums.eagle.ru/showpost.php?p=1780081&postcount=9

 

Hope this helps and good luck!

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

I ran into the problem of getting the ejection position for pilots as well when I build my CSAR script. That was back in the 1.2.4 days and I couldn't get it to work with the event handlers, so I'm not sure if something changed here.

 

Anyways, I ended up recording the current location of all the units I was tracking in 1s intervals and used the SLMod ejection detection. So when someone ejected, I used his last recorded position.

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

If we're opening up old scripts, how about this 1 -

http://forums.eagle.ru/showthread.php?t=116134&page=2

 

 

Haven't got around to finish it really although I think it would be great to have it, especially in the upcoming campaigns that are starting -

http://forums.eagle.ru/showthread.php?t=120452

 

The hard part should be over, it's just getting the mission file in the correct format where I was struggling with.

Link to comment
Share on other sites

I'm going at it in a bit of a less random way to exercise the concept- trying to figure out what I need scripts to be able to do.

 

Right now I have multiple locations chosen where an aircraft will be hot down- it'll fly through the zone and "explode unit" (50) which triggers ragnardas medevacs script. Because I've controlled the location I can send ground forces to a predetermined point. They can then be stopped for a bit- then head to their next waypoint which is the prison compound. I'm going to see if I can task push the groups back to their starting positions or just deactivate.

 

I'm wondering if it would be easier to use the ejection script I posted and then build in the medevac script functionality (popping smoke, radio item add etc) or if I can of iffy it in a way that will allow the pilot to be disabled / captured once in zone. If the blue pilot is brought to the red mash unit for example.

 

I'm worried that it may be more complicated to incorporate the red side function- especially with AI.

 

But... It does suggest a tantalizing opportunity for your script Ragnarda. If red medevac can be scripted to pick up blue and versa vice that would make for a pretty intense mission concept. Hmmmmm.

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

  • 2 weeks later...

Eh guys.

 

I'm trying to get some stuff worked out with "removing" the pilot from the above scenario- Ragnarda was nice enough to point me to the script- and I've been trying to put it to use from the hoggit wiki.

 

function Object.destroy(Object self) is the proper script and 'vega1 downed pilot #1' is the name of the pilot "object."

 

I've tried putting the name in (Object self)'s place... and in various other places... seems it isn't going to be that easy. A quick hand would be appreciated...

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

OOOOOOoooooooh! Man, I was way off.

 

Thanks!

 

 

So now I know I'm pushing it but hey- this is beginner script assistance.

 

I want to push a task on a unit to go to a point grabbed by a parachute detection script on an earlier page. I'm trying to match this

 

customEventHandler = {};

 

function customEventHandler:onEvent(event)

if (world.event.S_EVENT_EJECTION == event.id) then

location = event.initiator:getPoint();

local _time = timer.getTime();

 

local _latitude, _longtitude, _ = coord.LOtoLL(_location);

 

trigger.action.outText('Pilot ejected at point: latitude: ' .. string.format("%.3f", _latitude) .. ', longitude: ' .. string.format("%.3f", _longtitude), 10);

 

end

end;

 

world.addEventHandler(customEventHandler);

 

 

with this:

 

do

local path = {}

path[#path + 1] = mist.ground.buildWP(startPoint, 'Diamond', 5)

path[#path + 1] = mist.ground.buildWP(endPoint, 'Diamond', 5)

end

 

 

Is that possible or no?


Edited by ENO

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

Why does this not work? No unit is spawned, no error message logged? I want to spawn a vanilla soldier at the side of the helicopter.

 

CODE CORRECTED AND WORKS!

 

local status, err = pcall( --Add error-handling
   function (_args)    
       local chopper = Unit.getByName("Pilot1")

       if not chopper then
            env.info("chopper is nil")
       end
       local medicSpawnPositionAlt1 = chopper:getPosition().p
       medicSpawnPositionAlt1.x = medicSpawnPositionAlt1.x - math.sin(mist.getHeading(chopper)) * 5
       medicSpawnPositionAlt1.z = medicSpawnPositionAlt1.z + math.cos(mist.getHeading(chopper)) * 5

       mist.dynAdd(
       {
            units = {
                [1] = {
                 ["y"] = medicSpawnPositionAlt1.z,
                 ["type"] = "Soldier M4",
                 ["name"] = "Medic1",
                 ["unitId"] = 1111,
                 ["heading"] = 3,
                 ["playerCanDrive"] = true,
                 ["category"] = Group.Category.GROUND,
                 ["skill"] = "Excellent",
                 ["x"] = medicSpawnPositionAlt1.x,
               }
            },
            country = "USA",
            category = "GROUND",
            name = "MedicGroup",
            groupId = 11112,
            }
       )
   end
, _args)
if (not status) then env.error(string.format("Error in the script: \n\n%s",err), true) end -- Display error message


Edited by ArturDCS
correct sin / cos
Link to comment
Share on other sites

Anyone that can help me with a script that gives me a message and/or sound when any airplane goes below certain altitude AGL in a certain trigger zone?

It needs to monitor continuously.

 

Would be much appreciated.

dUJOta.jpg

 

Windows 11 | i9 12900KF | 64GB DDR4 | RTX 3090 | TM Warthog HOTAS | Saitek Combat Rudder Pedals | TM MFDs + Lilliput 8" | TIR5 Pro

Link to comment
Share on other sites

@ArturDCS, try something like this:

local status, err = pcall( --Add error-handling
       function (_args)    
local chopper = Unit.getByName("Pilot1")

if not chopper then
   env.info("chopper is nil")
end
medicSpawnPositionAlt1 = chopper:getPosition().p
medicSpawnPositionAlt1.x = medicSpawnPositionAlt1.x + math.cos(mist.getHeading(chopper)) * 10
medicSpawnPositionAlt1.z = medicSpawnPositionAlt1.z - math.sin(mist.getHeading(chopper)) * 10

mist.dynAdd(
{
   {
       ["y"] = medicSpawnPositionAlt1.z,
       ["type"] = "Soldier M4",
       ["name"] = "Medic1",
       ["unitId"] = 1111,
       ["heading"] = 3,
       ["playerCanDrive"] = true,
       ["category"] = Group.Category.GROUND,
       ["skill"] = "Excellent",
       ["x"] = medicSpawnPositionAlt1.x,
   },
   country = 2, -- I think these needs to be named
   category = "GROUND",
   name = "MedicGroup",
   groupId = 11112,
   }
)

, _args)
   
   if (not status) then env.error(string.format("Error in the script: \n\n%s",err), true) end -- Display error message
   

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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