M.I.S.T. - Skriptschnipsel

Alles rund um die Funktionen des ME

Moderator: JaBoG32 Stab

Benutzeravatar
JaBoG32_SNAFU
Semi-Professional
Beiträge: 2759
Registriert: 4. Mär 2013, 08:50

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_SNAFU » 23. Mai 2013, 18:19

Ist zwar kein MIST Skript, aber ich schreibe es trotzdem mal in die Sammlung, da man es immer mal wieder braucht. Läßt Rauch spawnen in einem zufällig definierten Abstand von einer Einheit und nicht driekt auf ihr:

Code: Alles auswählen

local inf = Unit.getByName('test')
local infpos = inf:getPosition().p
trigger.action.smoke({x=infpos.x + math.random(5,10), y=infpos.y-2, z=infpos.z + math.random(5,10)}, trigger.smokeColor.Green)

Benutzeravatar
JaBoG32_SNAFU
Semi-Professional
Beiträge: 2759
Registriert: 4. Mär 2013, 08:50

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_SNAFU » 23. Mai 2013, 20:36

Hier ein Beispiel einer Kombination von dem addGroup Befehlt mit mist.goRoute anhand von erzeugter Infantrie, die an eine zufällige Position in einer Zone "test" laufen. Das ganze werde ich noch mit einer If Schleife verknüpfen, die wenn der "heli" landet, die Infantrie erzeugt, das ist aber auch schon in den vorherigen Skriptschnipsel festgehalten. Hier geht es mehr um Wegpunkte erzeugen und diese mit dem MIST.goRoute Befehl einzusetzen. (Das hat mich echt Nerven gekostet und am Ende habe ich es nur durch Psyrixx Skript geschaft, halbwegs zu verstehen, wie der Mist geht)

Code: Alles auswählen

local heli = Unit.getByName('heli') 
local heligroup = Group.getByName('heli') 
local helipos = heli:getPosition().p
local heliheading = mist.getHeading(heli)	

local targetunit = trigger.misc.getZone('test')
local targetunitpos = {}

targetunitpos.x = targetunit.point.x + math.random(targetunit.radius * -1, targetunit.radius)
targetunitpos.z = targetunit.point.z + math.random(targetunit.radius * -1, targetunit.radius)
				
local data = {
								   ["visible"] = false,
								   ["groupId"] = "PontiacInf",
								   ["taskSelected"] = true,
								   ["hidden"] = false,
								   ["units"] = 
								   {
									  [1] = 
									  {
										 ["y"] = helipos.z + 8,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 1,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = helipos.x,
									  },
									[2] = 
									  {
										 ["y"] = helipos.z,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 2,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = helipos.x  + 8,
									  },
									[3] = 
									  {
										 ["y"] = helipos.z - 8,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 3,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = helipos.x,
									  },
									[4] = 
									  {
										 ["y"] = helipos.z,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 4,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = helipos.x - 8,
									  },						  
								   },
								["name"] = "PontiacInf",
								["task"] = "Ground Nothing",
								} 
coalition.addGroup(country.id.USA, Group.Category.GROUND, data)
trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Troops are disembarking, hold position!"), 10)

local infgroup = Group.getByName('PontiacInf')	

function generateWaypoints(targetunit, heli, waypointType)
        local waypoints = {}
        local targetunit = trigger.misc.getZone('test')
		local targetunitpos = {}

		targetunitpos.x = targetunit.point.x + math.random(targetunit.radius * -1, targetunit.radius)
		targetunitpos.z = targetunit.point.z + math.random(targetunit.radius * -1, targetunit.radius)
		
        local helipos = heli:getPosition().p
        local landingpos = Unit.getByName("PontiacInf"):getPosition().p
 
        local targetpoint = {
                ["type"] = "Flyover Point",
                ["ETA"] = 0,
                ["y"] = targetunitpos.z,
                ["x"] = targetunitpos.x,
                ["ETA_locked"] = true,
                ["speed"] = 15,
                ["speed_locked"] = true,
        }
 

        local landingpoint = {
                ["type"] = "Flyover Point",
                ["ETA"] = 0,
                ["y"] = landingpos.z,
                ["x"] = landingpos.x,
                ["ETA_locked"] = true,
                ["speed"] = 15,
                ["speed_locked"] = true,
        }
        
        if waypointType == 'LZ' then
                waypoints[#waypoints+1] = mist.ground.buildWP(landingpoint, 'Off Road', 20)
                waypoints[#waypoints+1] = mist.ground.buildWP(targetpoint, 'Diamond', 20)

        end
        
        return waypoints
end

LZ = generateWaypoints(targetunit, heli, 'LZ')
trigger.action.outText("Airborneassault on the move!", 40)

                                
mist.goRoute(infgroup, LZ)					
	

Benutzeravatar
JaBoG32_SNAFU
Semi-Professional
Beiträge: 2759
Registriert: 4. Mär 2013, 08:50

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_SNAFU » 24. Mai 2013, 20:29

So, hier jetzt das Skript, das eine Gruppe Infantrie bei einem Heli spawnt und diese dann in eine Zone schickt. Dafür notwendig ist die Bedingung das der Heli Truppen an Bord an (Flagge 906=true), eine Landezone "LZ" in der der Heli landet und eine Angriffszone, hier Namen "test". Sobald der Heli in der LZ aufsetzt spawnen die Infantrie auf der Angriffzonen zugewandten Seite des Helis und laufen los.

Eingesetzt:
mist.flagFun.units_in_zones
coalition.addGroup
mist.scheduleFunction
mist.goRoute
mist.removeFunction

Code: Alles auswählen

local heli = Unit.getByName('heli') 
local heligroup = Group.getByName('heli') 


local target = trigger.misc.getZone('test')
local targetpos = {}
targetpos.x = target.point.x + math.random(target.radius * -1, target.radius)
targetpos.z = target.point.z + math.random(target.radius * -1, target.radius)

mist.flagFunc.units_in_zones
	{
	units = {'heli'},
	zones = {'LZ'},
	flag = 910,     
	 } 
	 
function landingcheck()
trigger.action.setUserFlag('906', true) -- for testing, indicates heli has infantry on board, remove later
	
	if heli:inAir()
				then return
				else if (trigger.misc.getUserFlag(910) > 0 and trigger.misc.getUserFlag(906) > 0)
					then
					trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Troops are dismbarking, hold position!"), 10)
					disembarking()
				end
	end
end	

disembarktimer = mist.scheduleFunction(landingcheck, {}, timer.getTime(), 10)

function disembarking()	
	local helipos = heli:getPosition().p
	local heliheading = mist.getHeading(heli)	
	trigger.action.outText("disembarking", 4)
	
	    local infGroupX = helipos.x + 10 * math.cos(heliheading + math.pi / 2)
        local infGroupY = helipos.z + 10 * math.sin(heliheading + math.pi / 2)
        local infGroupLeftX = helipos.x + 10 * math.cos(heliheading + (math.pi * 3) / 2)
        local infGroupLeftY = helipos.z + 10 * math.sin(heliheading + (math.pi * 3) / 2)
        local leftDistance = math.sqrt((infGroupLeftX - targetpos.x) ^ 2 + (infGroupLeftY - targetpos.z) ^ 2)
        local rightDistance = math.sqrt((infGroupX - targetpos.x) ^ 2 + (infGroupY - targetpos.z) ^ 2)
        
        if rightDistance >= leftDistance then
                infGroupX = infGroupLeftX
                infGroupY = infGroupLeftY
        end
	local data = {
								   ["visible"] = false,
								   ["groupId"] = "PontiacInf",
								   ["taskSelected"] = true,
								   ["hidden"] = false,
								   ["units"] = 
								   {
									  [1] = 
									  {
										 ["y"] = infGroupY,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 1,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX,
									  },
									[2] = 
									  {
										 ["y"] = infGroupY,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 2,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX +2,
									  },
									[3] = 
									  {
										 ["y"] = infGroupY +2,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 3,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX,
									  },
									[4] = 
									  {
										 ["y"] = infGroupY +2,
										 ["type"] = "Soldier M4",
										 ["name"] = "PontiacInf",
										 ["unitId"] = 4,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX +2,
									  },						  
								   },
								["name"] = "PontiacInf",
								["task"] = "Ground Nothing",
								} 
					coalition.addGroup(country.id.USA, Group.Category.GROUND, data)
					trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Troops are disembarking, hold position!"), 10)

					local infgroup = Group.getByName('PontiacInf')	

	function generateWaypoints(target, heli, waypointType)
							local waypoints = {}
							local target = trigger.misc.getZone('test')
							local targetpos = {}

							targetpos.x = target.point.x + math.random(target.radius * -1, target.radius)
							targetpos.z = target.point.z + math.random(target.radius * -1, target.radius)
							
							local helipos = heli:getPosition().p
							local landingpos = Unit.getByName("PontiacInf"):getPosition().p
					 
							local targetpoint = {
									["type"] = "Flyover Point",
									["ETA"] = 0,
									["y"] = targetpos.z,
									["x"] = targetpos.x,
									["ETA_locked"] = true,
									["speed"] = 15,
									["speed_locked"] = true,
							}
					 

							local landingpoint = {
									["type"] = "Flyover Point",
									["ETA"] = 0,
									["y"] = landingpos.z,
									["x"] = landingpos.x,
									["ETA_locked"] = true,
									["speed"] = 15,
									["speed_locked"] = true,
							}
							
							if waypointType == 'Targetarea' then
									waypoints[#waypoints+1] = mist.ground.buildWP(landingpoint, 'custom', 20)
									waypoints[#waypoints+1] = mist.ground.buildWP(targetpoint, 'custom', 20)

							end
							
						return waypoints
	end
					

				Targetarea = generateWaypoints(target, heli, 'Targetarea')
				trigger.action.outText("Airborneassault on the move!", 40)
											
				mist.goRoute(infgroup, Targetarea)
				--trigger.action.setUserFlag('911', true)
				mist.removeFunction(disembarktimer)
	
end


Benutzeravatar
JaBoG32_SNAFU
Semi-Professional
Beiträge: 2759
Registriert: 4. Mär 2013, 08:50

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_SNAFU » 29. Mai 2013, 15:47

Hier nochmal das komplette Skript-Template zum Infantry mit dem Huey aufzunehmen, wieder absetzen und in eine Zone maschieren lassen, welches einfach nur geladen werden muß. Die Kommentare in den ersten Zeilen beachten und die Namen entsprechend anpassen, sowie die Triggerzonen in der Map erstellen:

Code: Alles auswählen

--create a group with the name "Infantryname" near a Triggerzone called "Pickupzone"
--create a heli with unit name "Heliname"
--create a Triggerzone called "Dropzone", thats where the infantry can be deployed
--create a Triggerzone called "Gotozone", thats the zone the infantry will move into
--note that flag # 902-906 are used in this script

local inf       		= Unit.getByName('Infantryname') --unit name of 1ste unit of Infantryname group
local infgroup		    = Group.getByName('Infantryname') --groupname of troops to be pickedup
local heli 				= Unit.getByName('Heliname') --unit name of transport heli
local heligroup 		= Group.getByName('Heliname') --group name of transport heli

mist.flagFunc.units_in_zones
	{
	units = {'Heliname'},
	zones = {'Pickupzone'},
	flag = 903,     
	 } 


function boarding()
	if (trigger.misc.getUserFlag(903) < 1)
	then 
	--trigger.action.outText("903", 4)
	return
		else
		if heli:inAir()
					then return
					else
						trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Troops are embarking, hold position!"), 10)
						trigger.action.setUserFlag('904', true) --Flag 1004 indicates troops can embark
						--trigger.action.outText("904", 4)
		end

		if (trigger.misc.getUserFlag(904) > 0 and trigger.misc.getUserFlag(905) < 1)
					then 
						local helipos = heli:getPosition().p
						trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Troops are embarking, hold position!"), 10)
						local getin = 
									{
									group = Group.getByName('Infantryname'),
									point = {x = helipos.x, z = helipos.z, y = helipos.y},
									radius = 0,
									form = "custom",
									speed = 20,
									disableRoads = 1
									}
						mist.groupToRandomPoint(getin)
						mist.removeFunction(boardingtimer)
		end
	end
end
boardingtimer = mist.scheduleFunction(boarding, {}, timer.getTime() + 1, 5) 

	mist.flagFunc.units_in_moving_zones --creating zone to trigger that troops embarked
								{
								units           = {"Infantryname"}, 
								zone_units      = {"Heliname"},
								radius          = 20, --distance at which infanty embark
								flag            = 905,
								stopflag        = 906,
								req_num			= 1
								}
function onboard()						
	if (trigger.misc.getUserFlag(905) > 0 and trigger.misc.getUserFlag(906) < 1)
				then
					
					local inf = Unit.getByName('Infantryname') --unit name of 1ste unit of Infantryname group
					local infgroup = Group.getByName('Infantryname') --groupname of troops to be pickedup
					infgroup:destroy()
					trigger.action.setUserFlag('906',true) --Flag 1006 indicates troops are on board
					trigger.action.outTextForGroup(Group.getID(heligroup), string.format("All troops on board!"), 10)
					mist.removeFunction(onboardchecktimer)
	end
end

onboardchecktimer = mist.scheduleFunction(onboard, {}, timer.getTime() + 1, 2) 



local target = trigger.misc.getZone('Gotozone')
local targetpos = {}
targetpos.x = target.point.x + math.random(target.radius * -1, target.radius)
targetpos.z = target.point.z + math.random(target.radius * -1, target.radius)

mist.flagFunc.units_in_zones
	{
	units = {'Heliname'},
	zones = {'Dropzone'},
	flag = 902,     
	 } 
	 
function landingcheck()
--trigger.action.setUserFlag('906', true) -- for testing, indicates heli has Infantryname on board, remove later
	
	if heli:inAir()
				then return
				else if (trigger.misc.getUserFlag(902) > 0 and trigger.misc.getUserFlag(906) > 0)
					then
					trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Troops are dismbarking, hold position!"), 10)
					disembarking()
				end
	end
end	

disembarktimer = mist.scheduleFunction(landingcheck, {}, timer.getTime(), 10)

function disembarking()	
	local helipos = heli:getPosition().p
	local heliheading = mist.getHeading(heli)	
	--trigger.action.outText("disembarking", 4)
	
	    local infGroupX = helipos.x + 10 * math.cos(heliheading + math.pi / 2)
        local infGroupY = helipos.z + 10 * math.sin(heliheading + math.pi / 2)
        local infGroupLeftX = helipos.x + 10 * math.cos(heliheading + (math.pi * 3) / 2)
        local infGroupLeftY = helipos.z + 10 * math.sin(heliheading + (math.pi * 3) / 2)
        local leftDistance = math.sqrt((infGroupLeftX - targetpos.x) ^ 2 + (infGroupLeftY - targetpos.z) ^ 2)
        local rightDistance = math.sqrt((infGroupX - targetpos.x) ^ 2 + (infGroupY - targetpos.z) ^ 2)
        
        if rightDistance >= leftDistance then
                infGroupX = infGroupLeftX
                infGroupY = infGroupLeftY
        end
	local data = {
								   ["visible"] = false,
								   ["groupId"] = "InfantryDeployed",
								   ["taskSelected"] = true,
								   ["hidden"] = false,
								   ["units"] = 
								   {
									  [1] = 
									  {
										 ["y"] = infGroupY,
										 ["type"] = "Soldier M4",
										 ["name"] = "InfantryDeployed",
										 ["unitId"] = 1,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX,
									  },
									[2] = 
									  {
										 ["y"] = infGroupY,
										 ["type"] = "Soldier M4",
										 ["name"] = "InfantryDeployed",
										 ["unitId"] = 2,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX +2,
									  },
									[3] = 
									  {
										 ["y"] = infGroupY +2,
										 ["type"] = "Soldier M4",
										 ["name"] = "InfantryDeployed",
										 ["unitId"] = 3,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX,
									  },
									[4] = 
									  {
										 ["y"] = infGroupY +2,
										 ["type"] = "Soldier M4",
										 ["name"] = "InfantryDeployed",
										 ["unitId"] = 4,
										 ["heading"] = heliheading,
										 ["playerCanDrive"] = true,
										 ["skill"] = "Excellent",
										 ["x"] = infGroupX +2,
									  },						  
								   },
								["name"] = "InfantryDeployed",
								["task"] = "Ground Nothing",
								} 
					coalition.addGroup(country.id.USA, Group.Category.GROUND, data)
					trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Troops are disembarking, hold position!"), 10)

					local infgroup = Group.getByName('InfantryDeployed')	

	function generateWaypoints(target, heli, waypointType)
							local waypoints = {}
							local target = trigger.misc.getZone('Gotozone')
							local targetpos = {}

							targetpos.x = target.point.x + math.random(target.radius * -1, target.radius)
							targetpos.z = target.point.z + math.random(target.radius * -1, target.radius)
							
							local helipos = heli:getPosition().p
							local landingpos = Unit.getByName("InfantryDeployed"):getPosition().p
					 
							local targetpoint = {
									["type"] = "Flyover Point",
									["ETA"] = 0,
									["y"] = targetpos.z,
									["x"] = targetpos.x,
									["ETA_locked"] = true,
									["speed"] = 15,
									["speed_locked"] = true,
							}
					 

							local landingpoint = {
									["type"] = "Flyover Point",
									["ETA"] = 0,
									["y"] = landingpos.z,
									["x"] = landingpos.x,
									["ETA_locked"] = true,
									["speed"] = 15,
									["speed_locked"] = true,
							}
							
							if waypointType == 'Targetarea' then
									waypoints[#waypoints+1] = mist.ground.buildWP(landingpoint, 'custom', 20)
									waypoints[#waypoints+1] = mist.ground.buildWP(targetpoint, 'custom', 20)

							end
							
						return waypoints
	end
					

				Targetarea = generateWaypoints(target, heli, 'Targetarea')
				--trigger.action.outText("Airborneassault on the move!", 40)
				trigger.action.setUserFlag('906', false)							
				mist.goRoute(infgroup, Targetarea)
				--trigger.action.setUserFlag('911', true)
				mist.removeFunction(disembarktimer)
	
end


Benutzeravatar
JaBoG32_Siddharta
Senior Member
Beiträge: 1812
Registriert: 17. Mai 2012, 21:39

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_Siddharta » 29. Mai 2013, 22:43

Wie KRASS ist Das denn?!
Ich denke so ungefähr könnte ein Duell zwischen Euklid und Heron aussehen :lol:
JaBoG32 322nd "Flying Monsters"

Bild

Benutzeravatar
JaBoG32_Herby
Senior Member
Beiträge: 1742
Registriert: 4. Dez 2009, 11:32

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_Herby » 2. Jun 2013, 08:25

Das ist auch hübsch.

Patrouillenfunktion für Groundunits.

Code: Alles auswählen

mist.ground.patrol = function(gpData, pType)
	
	local tempRoute = {}
	local useRoute = {}
	if type(gpData) == 'string' then
		gpData = Group.getByName(gpData)
	end

	local posStart = mist.getLeadPos(gpData)
	if not route then
		tempRoute = mist.getGroupRoute(gpData:getName())
	else
		for i = 1, #route do
			tempRoute[#tempRoute +1] = mist.ground.buildWP(route[i], form, speed)
		end
	end
	
	useRoute[#useRoute + 1] = mist.ground.buildWP(posStart, form, speed)
	for i = 1, #tempRoute do
		useRoute[#useRoute + 1] = mist.ground.buildWP(tempRoute[i], form, speed)
	end
		
	if pType and pType == 'doubleBack' then
		for i = #tempRoute, 2, -1 do
			useRoute[#useRoute + 1] = mist.ground.buildWP(tempRoute[i], form, speed)
		end
	end

	local tempTask = {
		id = 'WrappedAction', 
		params = { 
			action = {
				id = 'Script',
				params = {
					command = tostring('local group = ... \n mist.ground.patrol(group:getName() , ' .. mist.utils.basicSerialize(pType) .. ')') , 
					
				},
			},
		},
	}

	useRoute[#useRoute].task = tempTask
	mist.goRoute(gpData, useRoute)
end
Bild

Benutzeravatar
JaBoG32_Herby
Senior Member
Beiträge: 1742
Registriert: 4. Dez 2009, 11:32

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_Herby » 2. Jun 2013, 08:28

Und das setzt dem Ganzen noch die Krone auf.

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

Artillery Enhancement Script
Bild

Benutzeravatar
JaBoG32_SNAFU
Semi-Professional
Beiträge: 2759
Registriert: 4. Mär 2013, 08:50

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_SNAFU » 2. Jun 2013, 11:05

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?

Benutzeravatar
JaBoG32_SNAFU
Semi-Professional
Beiträge: 2759
Registriert: 4. Mär 2013, 08:50

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_SNAFU » 11. Jun 2013, 21:34

So, hier mal ein Skript, welches zufälligen Luftverkehr durch mehrstrahlige Transporter, Aufklärer, Tanker, AWACS etc an 3 Flugplätzen generiert. In gewissen Abständen spawnt ein zufälliges Flugzeugmuster an einem der 3 Plätze, startet und fliegt in einem Bereich einen zufälligen Punkt an und landet an einem der 3 Flugplätze. Nach dem der Flieger seine Maschinen runtergefahren hat, wird er von der Karte entfernt. Auch wenn es zu einem Unfall auf der Bahn kommt, wird der Flieger entfernt, so daß Staus vermieden werden sollten.

Dafür muß allerdings im ME 4 Triggerzonen gesetzt werden und in dem Skript, die Namen der Flugplätze eingetragen werden.
3 Zonen müßen über den Flugplätzen liegen, dessen Namen in entsprechender Reihenfolge im Skript eingetragen wurden.

Zone 1. "airfield1",
Zone 2. "airfield2",
Zone 3. "airfield3" bestimmen die 3 Flugplätze wo der Verkehr erzeugt wird, während die
Zone 4. "airlanehub1" den Bereich bestimmt, welchen die Flieger anfliegen, bevor sie wieder auf einem Flugplatz landen.

Das gleiche Skript wollte ich noch in kompatibler Version für Helis schreiben und für Fighter (Jäger, Bomber), das aber ein anderes mal.
Achja, das ganze benötigt wieder "MIST2.0".


PS: Updated to v4, fixed some issues with other scripts, when random AI planes was destroyed.
Dateianhänge
RandAT3AF_v4.zip
(8.42 KiB) 488-mal heruntergeladen
Zuletzt geändert von JaBoG32_SNAFU am 25. Okt 2013, 10:11, insgesamt 1-mal geändert.

Benutzeravatar
JaBoG32_SNAFU
Semi-Professional
Beiträge: 2759
Registriert: 4. Mär 2013, 08:50

Re: M.I.S.T. - Skriptschnipsel

Beitrag von JaBoG32_SNAFU » 17. Jun 2013, 18:49

Hier eine neue Version, die an 3 Flugfelder zufälligen Verkehr erzeugt. Zufällige Flugzeuge und Helikopter spawnen, starten, fliegen zu einem zufälligen Punkt in einer Zone und landen an einem anderen Flugfeld wieder. Jäger und Bomber fliegen als 2er Formation, ansonsten sind alle Fluggeräte mit Skin und Waffenladung im Pool (ausnahme P51,Fw190, F-117). Nach dem der Flieger seine Maschinen runtergefahren hat, wird er von der Karte entfernt. Auch wenn es zu einem Unfall auf der Bahn kommt, wird der Flieger entfernt, so daß Staus vermieden werden sollten. Die vertretenen Nationen bestehen aus Russland, Georgrien, USA, UK, France, Germany und Niederland.

Um Komplikation mit Flugabwehr zu vermeiden, sollten im Skript die folgenden Parameter in Zeile 26-28 editiert werden.

Code: Alles auswählen

randomAirplane = math.random(1,18) -- random for airplanettype; Russian AC 10-18 , for russion only set (10,18), or otherwise for other nations
randomHeli = math.random(1,18) --Russian AC 13-18, for russion only set (13,18), or otherwise for other nations
randomFighter = math.random(1,36) --Russian AC 18-36, for russion only set (18,36), or otherwise for other nations
In Zeile 10 kann die Spawnintervallzeit editiert werden:

Code: Alles auswählen

intervall = math.random(300,900) --(x,y) minimum x seconds, max. y seconds
Dafür muß allerdings im ME 4 Triggerzonen gesetzt werden und in dem Skript in Zeilen 12-14, die Namen der Flugplätze entsprechen den Zonen 1-3 eingetragen werden.
3 Zonen müßen über den Flugplätzen liegen, dessen Namen in entsprechender Reihenfolge im Skript eingetragen wurden.

Zone 1. "airfield1",
Zone 2. "airfield2",
Zone 3. "airfield3" bestimmen die 3 Flugplätze wo der Verkehr erzeugt wird, während die
Zone 4. "airlanehub1" den Bereich bestimmt, welchen die Flieger anfliegen, bevor sie wieder auf einem Flugplatz landen.

Achja, das ganze benötigt wieder "MIST2.0".
Dateianhänge
RandAT3AF_v1.zip
(8.38 KiB) 484-mal heruntergeladen

Antworten