Coder Social home page Coder Social logo

missionscriptingtools's People

Contributors

davidp57 avatar jarpy avatar jeremysmitherman avatar lugghawk avatar lukrop avatar morpheusxaut avatar mrskortch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

missionscriptingtools's Issues

I believe that mist.getNextUnitId() is broken at the moment. (with 1.5.5)

mist.getNextUnitId() keeps giving me the number "14000" over and over, I did a quick and dirty replacement by putting in math.random(100000000,200000000) for _unitId in CTLD and it worked.

What was happening is I was spawning crates. and everytime I respawn the same crate the previous one dissappeared, this is due to the ID being the same number

getLeadPos returns a nil value in some rare cases

The getLeadPos does some error-checking to make sure that the group lead exists. If a group lead doesn't exist, the function returns a nil value and functions like groupToRandomPoint will fail.

For some reason, getUnits of a DCSGroup instance might in some rare cases return a list of units that are actually "non-existing"/destroyed, which will make groupToRandomPoint throw an error. This happened very frequently when group units were killed off (so the list of group units should be empty) in my mission until I figured out I have to double-check that the group actually has existing units before calling groupToRandomZone.

I suggest to add a condition to functions invoking getLeadPos to check the returned value.

Specifying string name does not work after latest DCS update

Here are more details, I used the two latest versions of MIST, can't get it to work.
Was working a long time (it's a CSAR POW Mod for DCS that I added using MIST)

Line that Errors out:

POW1MARKER.pos = Unit.getByName("NameOfUnit"):getPoint() -- This is the line that errored out, used to work
or
POW1MARKER.pos = Group.getByName("NameOfUnit"):getPoint() -- This is the line that errored out, used to work

I narrowed my error to this last line above either of the two.

Error from dcs.log:
2022-08-14 04:56:46.250 ERROR SCRIPTING: Error while handling event [string "C:\Users\username\AppData\Local\Temp\DCS.openbeta/~mis00003EE0.lua"]:1060: attempt to index a nil value

Full Code Sample:

----create a orange marker for POW when released!
local myLog = mist.Logger:new('PRISONLOG')
POW1MARKER = {} ---this table is instantiated at the top of the code
csar.enableCSAROrangeCircles = True
csar.enableCSARForVIP = True
if csar.enableCSAROrangeCircles then	
     if csar.enableCSARForVIP then
           myLog:msg("D1")	
           POW1MARKER.pos = Unit.getByName("POW1"):getPoint() -- this is the line that errors out, worked b4
	   --POW1MARKER.pos = _unit.getByName("POW1"):getPoint() -- tried this as well, doesn't work  
           --POW1MARKER.pos = _unit:getByName("POW1"):getPoint() -- tried this as well, doesn't work  	    
           --POW1MARKER.pos = Group.getByName("POW1"):getPoint() -- tried this as well, doesn't work                  
           myLog:msg("D2")	
           POW1MARKER.id = mist.marker.getNextId()
           myLog:msg("D3")	
           POW1MARKER.mType = 0
           myLog:msg("D4")	
           POW1MARKER.readOnly = 0
           myLog:msg("D5")	
           POW1MARKER.text = "POW1 Located Here!"
           myLog:msg("D6")	
           mist.marker.add(POW1MARKER)
           myLog:msg("D7")	
           POW1MARK_check = "YES"
           myLog:msg("D8")	
           POW1DEAD_check = "YES"  
           myLog:msg("D9")	              
     end
end

myLog:msg("E")

dcs.log file messages:
2022-08-14 04:56:46.250 INFO SCRIPTING: PRISONLOG|1056: D1
2022-08-14 04:56:46.250 ERROR SCRIPTING: Error while handling event [string "C:\Users\username\AppData\Local\Temp\DCS.openbeta/~mis00003EE0.lua"]:1060: attempt to index a nil value

Object.getPosition() calls generating errors with some statics

So seems that some calls to Object.getPosition are being made with a nil argument which causes an error with that function (doesn't generate a nil return as seems to be expected), specifically seems to happen when certain statics are destroyed.

Suggest maybe protecting the call

image

getUnitsInZones return value seems incorrect?

Hi, I'm having some issues with getUnitsInZones. It's returning a table with different format than expected or documented (as best I can make out from the documentation).

I have a simple mission with a few named units. Upon execution and evaluation of the debug output I'm seeing the following:
mist.makeUnitTable({'[blue][vehicle]'}) is returning: { [1] = FARP 1 BLUE VEH 1,[2] = FARP 1 BLUE VEH 2,[3] = FARP 1 BLUE VEH 3,[4] = FARP A RED VEH 1-1-1,[5] = FARP 1 RED VEH 1-1-1,[6] = FARP 1 BLUE VEH 4,["processed"] = 1.801,} which seems to make sense - apart from the last value, which I can live with.
However:
mist.getUnitsInZones(mist.makeUnitTable({'[blue][vehicle]'}), zone_names) is returning: { [1] = { ["id_"] = 16779264,} ,[2] = { ["id_"] = 16780032,} ,[3] = { ["id_"] = 16780288,} ,[4] = { ["id_"] = 16780544,} ,}

I can't see anything obviously wrong with my code, albeit I'm fairly new to Lua and finding it somewhat obnoxious to work with. Could be it an issue with the function returning the unit IDs instead of the names?

missing nil check in removeMark()

There's a missing nil check in removeMark() when id is not a table, resulting in an error when manually removing a named marker and trying to re-add it.

    local function removeMark(id)
        --log:info("Removing Mark: $1", id
        local removed = false
        if type(id) == 'table' then 
            for ind, val in pairs(id) do
                local r = getMarkId(val)
                if r then 
                    trigger.action.removeMark(r)
                    mist.DBs.markList[r] = nil
                    removed = true
                end
            end
          
        else
            local r = getMarkId(id)
            trigger.action.removeMark(r)
            mist.DBs.markList[r] = nil
            removed = true
        end
        return removed
    end

Fixed:

    local function removeMark(id)
        --log:info("Removing Mark: $1", id
        local removed = false
        if type(id) == 'table' then 
            for ind, val in pairs(id) do
                local r = getMarkId(val)
                if r then 
                    trigger.action.removeMark(r)
                    mist.DBs.markList[r] = nil
                    removed = true
                end
            end
          
        else
            local r = getMarkId(id)
            if r then
                trigger.action.removeMark(r)
                mist.DBs.markList[r] = nil
                removed = true
            end
        end
        return removed
    end

dynAddStatic should set heading to radians

DCS seems to need the static units heading in radians.

I'm not sure weither it's only for statics or if it's the same for all units, but reading the code here could lead to thinking that the parameter should be in degrees, whereas it's not.

Just my two cents, ร” magnificent builder of worlds ;)

Unable to remove a line

Mission2= mist.marker.drawShape('ellypse') => working
mist.marker.remove(Mission2) => working with polygons

Mission1= mist.marker.drawShape('line') => working
mist.marker.remove(Mission1) => not working with a line

Unit.getGroup(event.initiator):getName() is broken with new patch: 1.5.5.60338

I think the f10 menu is now broke because of this...

Line 980 in mist, its throwing this error:

01526.775 ERROR DCS: Mission script error: : [string "C:\Users\andre\AppData\Local\Temp\DCS/~mis000058E4"]:980: Group doesn't exist
stack traceback:
[C]: ?
[C]: in function 'getName'
[string "C:\Users\andre\AppData\Local\Temp\DCS/~mis000058E4"]:980: in function 'f'
[string "C:\Users\andre\AppData\Local\Temp\DCS/~mis000058E4"]:1534: in function 'onEvent'
[string "Scripts/World/EventHandlers.lua"]:13: in function <[string "Scripts/World/EventHandlers.lua"]:11>

I think in the patch notes this has something to do with it:
" * MP. Wingman of client will take off "

playerCanDrive is being overridden to true.

if not unitData.playerCanDrive then
    unitData.playerCanDrive = true
end

If unitData.playerCanDrive is false explicitly, then it will evaluate as if not false then so playerCanDrive is always true.

I'll submit a PR shortly for this.

Issue with teleport functions or documentation

Tested against MIST 4.3.74 and 4.4.90
DCS version: 2.7.3.8494

Groupname= "REDCON1" defined in Mission Editor
image

Using the following condition;

if not Group.getByName('REDCON1') then
<mist function here>
end

mist.respawnGroup, mist.respawnInZone both fail with the attached exceptions in the teleport element. It seems like the groupName value is failing to return a group object.

respawnGroup
image

Zone:
image

I'm not sure if this is an issue in the code, or a gap in the documentation that misses any pre-requisite steps not already taken.

DB entries missing "Hidden on MFD" and "Cold at Start" values

The DB doesn't retain the "Hidden on MFD" or "Cold at Start" values for groups and units respectively. This means that groups and units spawned with MIST will not retain these options.

Simply add these two lines of codes to their appropriate places in initDBs() function to fix:

mist.DBs.units[coa_name][countryName][category][group_num].hiddenOnMFD = group_data.hiddenOnMFD
units_tbl[unit_num].coldAtStart = unit_data.coldAtStart

mist.flagFunc.mapobjs_dead_zones not working in later DCS

So I was fiddling around in Mission editor and wanted to do a mission where I destroy a bridge. However using mist.flagFunc.mapobjs_dead_zones just returns error when used and callback seems to be empty or blank.

To investigate further I loaded up a old mission basedon MIST 4.3 that previously worked and ran it, but it just craps out when activated. So something has changed in DCS later releases, using latest open beta.

Codesnip I used was
mist.flagFunc.mapobjs_dead_zones{
zones = {'BridgeZone'},
flag = 10
}

image

mist.removeFunction should return boolean true when function is removed

The current implementation does not return anything, despite the docs saying so:

	--- Removes a scheduled function.
	-- @tparam number id function id
	-- @treturn boolean true if function was successfully removed, false otherwise.
	function mist.removeFunction(id)
		local i = 1
		while i <= #scheduledTasks do
			if scheduledTasks[i].id == id then
				table.remove(scheduledTasks, i)
			else
				i = i + 1
			end
		end
	end

The function should look like this:

	--- Removes a scheduled function.
	-- @tparam number id function id
	-- @treturn boolean true if function was successfully removed, false otherwise.
	function mist.removeFunction(id)
		local i = 1
		local removedFunction = false
		while i <= #scheduledTasks do
			if scheduledTasks[i].id == id then
				table.remove(scheduledTasks, i)
				removedFunction = true
			else
				i = i + 1
			end
		end
		return removedFunction
	end

Wrapper for spawning effects

Test if spawning effects works. I mean it should but you never know. If not thats a bug for ED then. :)

Probably also requires me to update the DB code anyways. Ugh. There goes getting slmod and mist ready for initial 2.5 release.

If it works make a wrapper function for mist.dynAddStaticObject.

mist.RespawnGroup no longer working on ground units

One of the recent DCS updates has broken the functionality of 'mist.respawnGroup' on ground units in my missions, only. Air units respawn normally. Script reference:

`if not
Group.getByName('GROUP')
then

mist.respawnGroup('GROUP', true)
end`

Thank you for the great tool, happy to provide any more information as needed.

Cannot spawn vehicles on runway

in mist.teleportToPoint, I had to add 'RUNWAY' as a valid terrain type for vehicles :

        local validTerrain = {'LAND', 'ROAD', 'SHALLOW_WATER', 'WATER', 'RUNWAY'}
        if string.lower(newGroupData.category) == 'ship' then
            validTerrain = {'SHALLOW_WATER' , 'WATER'}
        elseif string.lower(newGroupData.category) == 'vehicle' then
            validTerrain = {'LAND', 'ROAD', 'RUNWAY'}
        end

marker.pos cannot receive position unit:getPoint()

I've Narrowed it down further ...
Note: Yes there is a unit and group name with "POW1" in mission editor.

--Simplistic Version of problem
marker= {}
name = "POW1"
marker.pos = Unit.getByName(name):getPoint()     <-- marker.pos cannot receive position from unit name point 

Can you verify this works on your end?
Or tell me how this might have changed and how it should be used?

I have verified that it's not that Unit.getByName("xyz") that's having the issue.
I know this works because I got it to work elsewhere.
It's position marker trying to receive the position point that's having the issue.

Error from dcs.log:
2022-08-14 04:56:46.250 ERROR SCRIPTING: Error while handling event [string "C:\Users\username\AppData\Local\Temp\DCS.openbeta/~mis00003EE0.lua"]:1060: attempt to index a nil value

Full Code:

----create a orange marker for POW when released!
POW1MARKER = {}
csar.pow1name = "POW1"               
POW1MARKER.pos = Unit.getByName(csar.pow1name):getPoint()   <-- This is where I get the dcs.log error
POW1MARKER.id = mist.marker.getNextId()
POW1MARKER.mType = 0	
POW1MARKER.readOnly = 0
POW1MARKER.text = "POW1 Located Here!"	
mist.marker.add(POW1MARKER)

I used Hoggit's example: (at the very bottom)
https://wiki.hoggitworld.com/view/MIST_markerAdd

   local v = {}
   v.pos = Unit.getByName('update'):getPoint()
   v.id = 5
   v.markForCoa = 2
   v.mType = 0                  <-- 0 for orange circle markers ... was '2'
   v.radius = 10000
   mist.marker.add(v)

mist.DBs.const.shapeNames Duplicate Entries

I am trying to understand why there are duplicate entries in mist.DBs.const.shapeNames

Specifically for version 4.5.107

"FARP Fuel Depot" and "Fuel tank" are referred to twice.

Show errors thrown from a function invoked by `mist.scheduleFunction` as popup?

Hello,

I've noticed that functions invoked by mist.scheduleFunction are "lost" somewhere. Consider this script:

local function throwSomeError()
  local obj = {}
  print(obj.x.y.z)
end

throwSomeError()

Running this code will give me a popup error like this

However, the following code yields no such error:

local function throwSomeError()
  local obj = {}
  print(obj.x.y.z)
end

mist.scheduleFunction(throwSomeError,nil,timer.getTime()+1)

But of course, the function is erroneous, and in my opinion I should get an error (somewhere) so I can fix it.

Cheers!

mist.groupToPoint documentation mentions undocumented "random distance"

From the mist.groupToPoint documentation:

... point can be a zoneTable or zoneName. If not specified a
random distance between 300 and 1000 meters will be defined. form is the def ...

This "random distance" should be documented, is it computing a random point from the point specified (by som radius)?

I'd fix it myself but I don't have Microsoft Office at home

please add neutral group

Please add to line 126 if you don't mind and perhaps to other tables as well, so neutral units can be handled. Thank you!
if (coa_name == 'red' or coa_name == 'blue' or coa_name == 'neutrals') and type(coa_data) == 'table' then

Part of MIST interfering with password-protected Game Master slots, leading to mission script errors

Whenever we use password-protected Game Master slots in missions containing MIST, we get a mission script error for line 5291 in the MIST script.

This is the part of MIST that seems to cause the error:

local caSlots = false
local caMSGtoGroup = false

if env.mission.groundControl then -- just to be sure?
	for index, value in pairs(env.mission.groundControl) do
		if type(value) == 'table' then
			for roleName, roleVal in pairs(value) do
				for rIndex, rVal in pairs(roleVal) do
                    if env.mission.groundControl[index][roleName][rIndex] > 0 then
                        caSlots = true
                        break
                    end
					
				end
			end
		elseif type(value) == 'boolean' and value == true then
			caSlots = true
			break
		end
	end
end

Attached is the error message. Do I have to change something in these lines to prevent the error?

Thanks a lot for the help!
MIST error

mist.getUnitsInPolygon errors v4.3.74

When called, this produced two errors that I managed to troubleshoot and resolve so it worked for me as intended.

  1. the first parameter is called unit_names but unitNames is referenced in the body.

  2. an error that you are trying to do arithmetic on a table is shown, caused on line 2520:
    inZoneUnits[inZoneUnits + 1] = units[i]

I fixed it by changing it to:

inZoneUnits[#inZoneUnits + 1] = units[i]

Thanks

Static object teleport does not work

Using the latest dev branch, the teleport function does not work for static objects.

I placed a bunker named BunkerA, used teleport command. Instead of teleporting, it cloned the object, leaving the original in place. Using triggers to test the name, the original object triggered, the new object didn't. So this indicates that it clones a new object, and the original maintains its name and all properties.

Aircraft groups "go dumb" after respawnInZone() or teleportInZone()

I am trying to randomize the spawn location of aircraft groups. I can make them spawn at a random location or move them to a random location after spawning (using respawnInZone() or teleportInZone(), respectively), but after this they "go dumb." They slowly descend to ~200' agl and eventually crash into the ground if there's a terrain rise. They don't follow flight plan, and don't engage.

The same groups work fine if I spawn them at their ME-specified starting point with respawnGroup(). Is there any fix or workaround for this?

Thanks!

LUA Tables to JSON

Since JSON is a more common dataformat (generally speaking), is it possible to add export LUA table to JSON feature to MIST?

attempt to index field 'unitsByName' (a nil value) at launch of version 4.5.121

Updated mist from version 4.5.107 to 4.5.121 and launching the mission with the new version of mist returns an error
excerpt from my logs with the updated mist version (and no other changes).

2023-11-22 04:14:30.582 INFO SCRIPTING (Main): Chaos Log: Loading: mist.lua
2023-11-22 04:14:30.616 ERROR SCRIPTING (Main): Mission script error: [string "C:/Users/Chaos/Downloads/DCS LUA scripts/mist.lua"]:133: attempt to index field 'unitsByName' (a nil value)

`respawnGroup` leads to drift in position and `teleportToPoint` erases bot tasks.

I'm trying to create a mission, in which a plane controlled by a bot respawns in its initial position when a set of conditions is met.

At first, I did this with mist.respawnGroup(groupName, true). This worked, however, after multiple respawns (~500) the planes started to drift. I.e. the respawn location was not the same as the initial location when the mission started.

I then tried to use mist.getGroupData(groupName) to save the initial position of the planes and then used mist.teleportToPoint to set them back to this position. However, I observed very inconsistent behavior when using teleportToPoint, such as:

  1. Initial altitude seems to be random (getGroupData only returns coordinates x and y, z is not included for some reason).
  2. The bots forget their tasks and just fly to the waypoints (they were assigned to a CAP mission).

What is the recommended way to respawn a unit to exactly their initial location without forgetting their tasks?

Line 2520 : In function "mist.getUnitsInPolygon" , missing "#" before "inZoneUnits"

function mist.getUnitsInPolygon(unit_names, polyZone, max_alt)
	local units = {}

	for i = 1, #unit_names do
		units[#units + 1] = Unit.getByName(unitNames[i])
	end

	local inZoneUnits = {}
	for i =1, #units do
		if units[i]:isActive() and mist.pointInPolygon(units[i]:getPosition().p, polyZone, max_alt) then
			inZoneUnits[inZoneUnits + 1] = units[i] -- HERE !!!
		end
	end

	return inZoneUnits
end

@mrSkortch

typo

-- if we add more coalition specific data then bullsye should be categorized by coaliton. For now its just the bullseye table

data then bullsye should be

should be

data then bullseye should be

Cheers!
Chuck

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.