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 » 18. Mai 2013, 16:58

Hier mal mein erstes Skript. :mrgreen:

Man muß dafür einen Heli mit Namen "test" haben und eine Inf Gruppe mit Namen "pickup" und einer Einheit in dieser mit Namen "pickup". Dann kann das Skript initialisiert werden, am besten, so daß man es mehrmals ausführen kann, z.B. mit der F-10 Operation die die Flagge 902 auf true setzt und so die Infantrie Gruppe anfordert den Heli zu besetzen.

Nähert man sich der Infantriegruppe, poppt diese grünen Rauch. Wenn man dann in der Nähe landet, kommt die Gruppe zum Heli und steigt ein (natürlich nicht wirklich, sie verschwindet und eine Flagge wird gesetzt, die später genutzt werden kann um einen vollen Heli zu simulieren).

Manchmal muß man die Infantrie mit der F-10 Option mehrmals rufen, bis sie sich durchringt zum Heli zu kommen da die AI nicht immer sehr zielstrebig ist. Ich arbeite noch einem Skript mit dem man dann die Infantrie an beliebiger Stelle wieder absetzen kann und in einer vordefinierte Zone schicken kann, aber erstmal dieser Schnipsel:

Code: Alles auswählen

--create F10 options for flag 902 to request to pick up troops
--script should be called by scwitched condition / flag 902, which is initialized by F-10 menu
--create a group with the name "pickup" and the first unit name "pickup"
--create a heli with unit name "test"

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

mist.flagFunc.units_in_moving_zones 
{
        units           = {"pickup"}, 
        zone_units      = {"test"},
        radius          = 200,--distance to call infantry
        flag            = 903,
        stopflag        = 4
}

local helipos = heli:getPosition().p
local heliagl = helipos.y - land.getHeight({x = helipos.x, y = helipos.z}) - 1.5
local helivel = heli:getVelocity()
local abshelivel = math.abs(helivel.x) + math.abs(helivel.y) + math.abs(helivel.z)

function main()
if (trigger.misc.getUserFlag(902) > 0 and trigger.misc.getUserFlag(903) > 0)
			then
				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)
				
				if (abshelivel > 1)  
					then 
					trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Slow down"), 10) 
					end

					if (heliagl > 1)  
						then 
						trigger.action.outTextForGroup(Group.getID(heligroup), string.format("Get lower"), 10) 
						end
						
							if (heliagl <= 1 and abshelivel <= 1) 
								then 
								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
								local getin = 
											{
											group = Group.getByName('pickup'),
											point = {y = helipos.y, x = helipos.x, z = helipos.z},
											radius = 1,
											form = "Diamond",
											speed = 10,
											disableRoads = 1
											}
								mist.groupToRandomPoint(getin)
								mist.flagFunc.units_in_moving_zones --creating zone to trigger that troops embarked
											{
											units           = {"test"}, 
											zone_units      = {"pickup"},
											radius          = 20, --distance at which infanty embark
											flag            = 905,
											stopflag        = 906,
											req_num			= 1
											}
							end
			else
			trigger.action.outTextForGroup(Group.getID(heligroup), string.format("You are too far away from LZ!"), 10)
			trigger.action.setUserFlag('902', false) --initial trigger set false again
end


if (trigger.misc.getUserFlag(904) > 0 and trigger.misc.getUserFlag(905) > 0)
			then
				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(funcID)
			end
end
local funcID = mist.scheduleFunction(main, {}, timer.getTime() + 10, 120)
Zuletzt geändert von JaBoG32_SNAFU am 22. Mai 2013, 19:06, insgesamt 1-mal geändert.

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

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

Beitrag von JaBoG32_Herby » 22. Mai 2013, 17:34

Code: Alles auswählen

local apc = Unit.getByName("APC")
local apcpos = apc:getPosition().p
local apcheading = mist.getHeading(apc)

group = {
	units = {
		[1] = {
			["x"] = apcpos.x - 5 * math.cos(apcheading),
			["y"] = apcpos.z - 5 * math.sin(apcheading),
			["type"] = "Soldier M4",
			["heading"] = apcheading - math.pi,
				},
		[2] = {
			["x"] = apcpos.x - 6 * math.cos(apcheading),
			["y"] = apcpos.z - 6 * math.sin(apcheading),
			["type"] = "Soldier M4",
			["heading"] = apcheading - math.pi,
				},
		[3] = {
			["x"] = apcpos.x - 7 * math.cos(apcheading),
			["y"] = apcpos.z - 7 * math.sin(apcheading),
			["type"] = "Soldier M249",
			["heading"] = apcheading - math.pi,
				},
			},
		}

sct.dynAdd("USA", "vehicle", group)
Spawned eine Gruppe Infanteristen hinter einem APC.

Benötigt eine Unit namens "APC".
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 » 22. Mai 2013, 19:09

Super, das kann ich auch noch gebrauchen. Im Moment kämpfe ich mit einem Skript, das Infantrie an der Landestelle erzeugen soll und diese dann sich zu einem Punkt in Marsch setzt, aber irgendwie ist da der Wurm drin...

Dafür hier ein Skript, ähnlich wie mein vorheriges, allerdings etwas eleganter und läßt Infantrie die bereits existiert zu dem Heli laufen, wenn dieser gelandet ist. Erreicht die Infantrie den Heli, verschwindet sie wieder und eine Flagge wird gesetzt, die den Status wiedergibt:

Code: Alles auswählen


--create a group with the name "AirborneInf" and the first unit name "AirborneInf"
--create a heli with unit name "Heli" and trigger script via Zone f.e.

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



function boarding()

	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 904 indicates troops can embark
			
	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('AirborneInf'),
								point = {x = helipos.x, z = helipos.z, y = helipos.y},
								radius = 0,
								form = "custom",
								speed = 20,
								disableRoads = 1
								}
					mist.groupToRandomPoint(getin)
	end

end

	mist.flagFunc.units_in_moving_zones --creating zone to trigger that troops embarked
								{
								units           = {"AirborneInf"}, 
								zone_units      = {"Heli"},
								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('AirborneInf') --unit name of 1ste unit of AirborneInf group
					local infgroup = Group.getByName('AirborneInf') --groupname of troops to be pickedup
					infgroup:destroy()
					trigger.action.setUserFlag('906', true) --Flag 906 indicates troops are on board
					trigger.action.outTextForGroup(Group.getID(heligroup), string.format("All troops on board!"), 10)
					--mist.removeFunction(funcID)
	end
end
mist.scheduleFunction(boarding, {}, timer.getTime() + 1, 120) 
mist.scheduleFunction(onboard, {}, timer.getTime() + 1, 2) 

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

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

Beitrag von JaBoG32_Herby » 22. Mai 2013, 20:24

Versuchs mal hiermit.

Code: Alles auswählen

local apc = Unit.getByName("APC")
local apcpos = apc:getPosition().p

local folgen = 
            {
            group = Group.getByName("USA gnd 4"),
            point = {y = apcpos.y, x = apcpos.z, z = apcpos.x},
            radius = 10,
                }

mist.groupToRandomPoint(folgen)
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 » 23. Mai 2013, 10:52

Ja, das hatte ich auch schon probiert, funktionierte erst wieder nachdem ich MIST zusätzlich über eine "Time more than 1 second Aktion" geladen habe und sämtlich Kommentare im Skript gelöscht habe. Die scheinen das Spiel noch durcheinander zu bringen...

Noch eine kurze Korrektur zu dem was im Guide steht bezüglich der MIST scheduleFunction, welche ermöglich eine Funktion zeitlich wiederholt abzufragen (z.B. if Bedingungen zu prüfen) und sehr nützlich ist:

Code: Alles auswählen

local function boarding()
if (trigger.misc.getUserFlag(505) > 0)
				then
					local infgroup = Group.getByName('test')
					infgroup:destroy()
	end
end

mist.scheduleFunction(boarding, {}, timer.getTime() + 5, 60) 

MIST scheduleFunction so 5 Sekunden nach initialisierung alle 60 Sekunden lang die Funktion "boarding" auf, welche die Gruppe "test" löscht, sollte Flagge 505 true sein. Das ist meiner Erfahrung falsch im Guide beschrieben.

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

Antworten