Klingt interessant, stecke aber gerade selber in einem "Problem" fest.
Ich will zufällig generierten FixedWing Verkehr an einem Flugfeld skripten, also ankommenden und abfliegende Transportmaschinen, die in einem defnierten Raum sich bewegen. Bisher habe ich zwei Funktionen die jede für sich funktioniert. Eine um
zufällige Fliegertypen auf dem Flugfeld oder in Luft spawnen zu lassen:
Code: Alles auswählen
--MIST 2.0 required
--Following trigger zones need to be placed in the ME:
--1: Zone called 'airspawnzone1', which defines the area in which planes will airspawn
--2: Zone called 'landingpoint', which includes the airport on which the planes will land
--3: Zone called 'entrypoint1', which defines the entry/exit point of the airfield the planes are set to land or takeoff
groupcounter = 0
function generateAirplane()
randomnr1 = math.random(1,2) -- random for spawnpoints; 1=arrival, 2=depature
randomnr2 = math.random(1,8) -- random for aircrafttype
groupcounter = groupcounter + 1
if randomnr2 == 1
then
_aircrafttype = "C-17A" --or whatever type
else
if randomnr2 == 2
then
_aircrafttype = "Yak-40" --or whatever type
else
if randomnr2 == 3
then
_aircrafttype = "A-10C" --or whatever type
else
if randomnr2 == 4
then
_aircrafttype = "F/A-18C" --or whatever type
else
if randomnr2 == 5
then
_aircrafttype = "C-130" --or whatever type
else
if randomnr2 == 6
then
_aircrafttype = "Su-25T" --or whatever type
else
if randomnr2 == 7
then
_aircrafttype = "IL-76MD" --or whatever type
else
if randomnr2 == 8
then
_aircrafttype = "Su-25" --or whatever type
end
end
end
end
end
end
end
end
if randomnr1 == 1
then
_spawnairplane = trigger.misc.getZone('airspawnzone1')
_spawnairplanepos = {}
_spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
_spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
_alt = 6000
_speed = 250
_waypointtype = "Turning Point"
_waypointaction = "Turning Point"
_airdromeId = nil
route = 'arrival'
else
if randomnr1 == 2
then
_spawnairplane = trigger.misc.getZone('landingpoint')
_spawnairplanepos = {}
_spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
_spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
_alt = 88
_speed = 0
_waypointtype = "TakeOffParking"
_waypointaction = "From Parking Area"
_airdromeId = 24
route = 'departure'
end
end
_airplanedata = {
["modulation"] = 0,
["tasks"] =
{
}, -- end of ["tasks"]
["task"] = "CAS",
["uncontrolled"] = false,
["route"] =
{
["points"] =
{
[1] =
{
["alt"] = _alt,
["type"] = _waypointtype,
["action"] = _waypointaction,
["alt_type"] = "BARO",
["formation_template"] = "",
["ETA"] = 0,
["airdromeId"] = _airdromeId,
["y"] = _spawnairplanepos.z,
["x"] = _spawnairplanepos.x,
["speed"] = _speed,
["ETA_locked"] = true,
["task"] =
{
["id"] = "ComboTask",
["params"] =
{
["tasks"] =
{
}, -- end of ["tasks"]
}, -- end of ["params"]
}, -- end of ["task"]
["speed_locked"] = true,
}, -- end of [1]
}, -- end of ["points"]
}, -- end of ["route"]
["groupId"] = 1,
["hidden"] = false,
["units"] =
{
[1] =
{
["alt"] = _alt,
["heading"] = 0,
["type"] = _aircrafttype,
["psi"] = 0,
["onboard_num"] = "10",
["parking"] = 19,
["y"] = _spawnairplanepos.z,
["x"] = _spawnairplanepos.x,
["name"] = string.format(groupcounter),
["payload"] =
{
}, -- end of ["payload"]
["speed"] = _speed,
["unitId"] = string.format(groupcounter),
["alt_type"] = "BARO",
["skill"] = "High",
}, -- end of [1]
}, -- end of ["units"]
["y"] = _spawnairplanepos.z,
["x"] = _spawnairplanepos.x,
["name"] = string.format(groupcounter),
["communication"] = true,
["start_time"] = 0,
["frequency"] = 124,
}
trigger.action.outText("airplane data generated", 3)
coalition.addGroup(country.id.USA, Group.Category.AIRPLANE, _airplanedata)
trigger.action.outText("airplane spawned", 3)
end
generateAirplane()
Und eine Funktion die
Fliegern Wegpunkte generiert und diese abfliegen läßt:
Code: Alles auswählen
--MIST 2.0 required
--Following trigger zones need to be placed in the ME:
--1: Zone called 'airspawnzone1', which defines the area in which planes will airspawn
--2: Zone called 'landingpoint', which includes the airport on which the planes will land
--3: Zone called 'entrypoint1', which defines the entry/exit point of the airfield the planes are set to land or takeoff
groupcounter = 1 --airplanename = 1
route = 'departure' --waypoints set for departure, alternative 'arrival'
function generateWaypoints(_spawnairplane, _entrypoint1, _landingpoint1, waypointType)
local waypoints = {}
_spawnairplane = trigger.misc.getZone('airspawnzone1')
_spawnairplanepos = {}
_spawnairplanepos.x = _spawnairplane.point.x + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
_spawnairplanepos.z = _spawnairplane.point.z + math.random(_spawnairplane.radius * -1, _spawnairplane.radius)
_entrypoint1 = trigger.misc.getZone('entrypoint1')
_entrypoint1pos = {}
_entrypoint1pos.x = _entrypoint1.point.x + math.random(_entrypoint1.radius * -1, _entrypoint1.radius)
_entrypoint1pos.z = _entrypoint1.point.z + math.random(_entrypoint1.radius * -1, _entrypoint1.radius)
_landingpoint1 = trigger.misc.getZone('landingpoint')
_landingpoint1pos = {}
_landingpoint1pos.x = _landingpoint1.point.x + math.random(_landingpoint1.radius * -1, _landingpoint1.radius)
_landingpoint1pos.z = _landingpoint1.point.z + math.random(_landingpoint1.radius * -1, _landingpoint1.radius)
local startpoint1 = {
["alt"] = 6000,
["type"] = "Turning Point",
["action"] = "Turning Point",
["alt_type"] = "RADIO",
["formation_template"] = "",
["ETA"] = 0,
["y"] = _spawnairplanepos.z,
["x"] = _spawnairplanepos.x,
["speed"] = 250,
["ETA_locked"] = false,
["task"] =
{
["id"] = "ComboTask",
["params"] =
{
["tasks"] =
{
}, -- end of ["tasks"]
}, -- end of ["params"]
}, -- end of ["task"]
["speed_locked"] = true,
} -- end of [1]
local entrypoint1 =
{
["alt"] = 3000,
["type"] = "Turning Point",
["action"] = "Turning Point",
["alt_type"] = "RADIO",
["formation_template"] = "",
["ETA"] = 0,
["y"] = _entrypoint1pos.z,
["x"] = _entrypoint1pos.x,
["speed"] = 250,
["ETA_locked"] = false,
["task"] =
{
["id"] = "ComboTask",
["params"] =
{
["tasks"] =
{
}, -- end of ["tasks"]
}, -- end of ["params"]
}, -- end of ["task"]
["speed_locked"] = true,
}
local landingpoint1 =
{
["alt"] = 3000,
["type"] = "LAND",
["action"] = "Landing",
["alt_type"] = "RADIO",
["formation_template"] = "",
["ETA"] = 0,
["y"] = _landingpoint1pos.z,
["x"] = _landingpoint1pos.x,
["speed"] = 200,
["ETA_locked"] = false,
["task"] =
{
["id"] = "ComboTask",
["params"] =
{
["tasks"] =
{
}, -- end of ["tasks"]
}, -- end of ["params"]
}, -- end of ["task"]
["speed_locked"] = true,
}
local takeoffpoint =
{
["alt"] = _alt,
["type"] = "TakeOffParking",
["action"] = "From Parking Area",
["alt_type"] = "RADIO",
["formation_template"] = "",
["ETA"] = 0,
["y"] = _landingpoint1pos.z,
["x"] = _landingpoint1pos.x,
["speed"] = 0,
["ETA_locked"] = false,
["task"] =
{
["id"] = "ComboTask",
["params"] =
{
["tasks"] =
{
}, -- end of ["tasks"]
}, -- end of ["params"]
}, -- end of ["task"]
["speed_locked"] = true,
}
if waypointType == 'arrival'
then
waypoints[#waypoints+1] = mist.fixedWing.buildWP(startpoint1, "Turning Point", 250, 3000, "RADIO")
waypoints[#waypoints+1] = mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
waypoints[#waypoints+1] = mist.fixedWing.buildWP(landingpoint1, "LAND", 250, 3000, "RADIO") --string type, number speed, number altitude, string altitudeType
else if waypointType == 'departure'
then
waypoints[#waypoints+1] = mist.fixedWing.buildWP(takeoffpoint, "TakeOffParking", 250, 3000, "RADIO")
waypoints[#waypoints+1] = mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
waypoints[#waypoints+1] = mist.fixedWing.buildWP(startpoint1, "Turning Point", 250, 3000, "RADIO")
waypoints[#waypoints+1] = mist.fixedWing.buildWP(entrypoint1, "Turning Point", 250, 3000, "RADIO")
waypoints[#waypoints+1] = mist.fixedWing.buildWP(landingpoint1, "LAND", 250, 3000, "RADIO") --string type, number speed, number altitude, string altitudeType
end
end
return waypoints
end
flightplan = generateWaypoints(_spawnairplane, _entrypoint1, _landingpoint1, route)
local airtraffic1grp = Group.getByName(string.format(groupcounter))
mist.goRoute(airtraffic1grp, flightplan)
Doch
zusammen bekomme ich die Funktionen nicht zum laufen. Vielleicht hast du da eine Idee?