Setting a patrol

umairazfar edited this page Nov 16, 2014 · 3 revisions

In this tutorial, we will learn how to set up a patrol. Since we are going to create a patrol that goes around near the edges of the map, we start off by creating appropriate waypoints. As always, we are using the map created in the previous tutorials. Open map.yaml to begin.

map.yaml

We create four waypoints that our units will be using by creating these four actors:

Patrol1: waypoint
	Location: 16,16
	Owner: Neutral
Patrol2: waypoint
	Location: 47,16
	Owner: Neutral
Patrol3: waypoint
	Location: 47,47
	Owner: Neutral
Patrol4: waypoint
	Location: 16,47
	Owner: Neutral

Then we turn off shroud and fog of war so that we can see what is actually happening. This is not recommended if you want to have an engaging single player experience. We are only doing this to see what is happening.

Options:
	Crates: False
	Fog: False
	Shroud: False
	AllyBuildRadius: False
	FragileAlliances: False
	StartingCash: 5000
	ConfigurableStartingUnits: False

Now we make changes to the tutorialmap.lua file (or the file in which you do coding)

tutorialmap.lua

We first define the units that are going to be the part of our patrol and also the path that the patrol will begin with:

apcPatrol = {"apc", "3tnk"}
apcPath = { Patrol1.Location, Patrol2.Location, Patrol3.Location, Patrol4.Location }

We then define the function that will be called to initiate the patrol

SendPatrol = function()
    Reinforcements.Reinforce(india, apcPatrol, apcPath, 15, function(vehicle)
	vehicle.Patrol(apcPath, true, 5) 
    end)
end

So the patrol will be called for india and once it reaches the last patrol point, the Patrol function will be called making the units to move from one point to another in attack move stance:

You can see that the units will keep on going in a circle and engage anything that will come in their path. You can change the time to win the map from 60 to 120 seconds to see the units make their patrol journey. Now as always, I give you the complete code for the map.

Complete code

JeepReinforcements = {"jeep", "jeep"}
JeepReinforcementsPath = { PakEntry.Location, PakRally.Location }
JeepDelay = 12
JeepInterval = 2

Force = { "e1", "e1", "e1", "e1", "e2"}
ForcePath = { IndiaEntry.Location, IndiaRally.Location }
ForceDelay = 15
ForceInterval = 2

apcPatrol = {"apc", "3tnk"}
apcPath = { Patrol1.Location, Patrol2.Location, Patrol3.Location, Patrol4.Location }
apcInterval = 2


ParadropUnitTypes = { "e1", "e1", "e1", "e3", "e3"}
ParadropWaypoints = { PakRally, IndiaRally}

AttackersTeam = { Attacker1, Attacker2 }
InsertionHelicopterType = "tran"
SniperReinforcements = { "gnrl", "sniper" }

SendPatrol = function()
    Reinforcements.Reinforce(india, apcPatrol, apcPath, 15, function(vehicle) vehicle.Patrol(apcPath, true, 5) end)
end

AttackersKilled = function()
    Trigger.AfterDelay(DateTime.Seconds(5), SendSnipers)
end

SendSnipers = function()
    local passengers = Reinforcements.ReinforceWithTransport(player, InsertionHelicopterType,
        SniperReinforcements, JeepReinforcementsPath, { PakEntry.Location })[2] 
    local vip = passengers[1]
    Trigger.OnKilled(vip, MissionFailed)
    vip.Stance = "Defend"
end

SendJeeps = function()
    Reinforcements.Reinforce(player, JeepReinforcements, JeepReinforcementsPath, DateTime.Seconds(JeepInterval))
    Media.PlaySpeechNotification(player, "ReinforcementsArrived")
end

SendIndianInfantry = function()
    local units = Reinforcements.Reinforce(india, Force, ForcePath, ForceInterval)
    Utils.Do(units, function(unit)
        BindActorTriggers(unit)
    end)
    Trigger.AfterDelay(DateTime.Seconds(5), SendIndianInfantry)
end

BindActorTriggers = function(a)
    if a.HasProperty("Hunt") then
        if a.Owner == india then
            Trigger.OnIdle(a, a.Hunt)
        else
            Trigger.OnIdle(a, function(a) a.AttackMove(Outpost.Location) end)
        end
    end
end

OutpostDestroyed = function()
    MissionFailed()
end

MissionAccomplished = function()
    Media.PlaySpeechNotification(player, "Win")
end

MissionFailed = function()
    Media.PlaySpeechNotification(player, "Lose")
    player.MarkFailedObjective(SurviveObjective)
    india.MarkCompletedObjective(DestroyObjective)
end

ParadropIndianUnits = function()
	local lz = Utils.Random(ParadropWaypoints).Location
	local start = Map.CenterOfCell(Map.RandomEdgeCell()) + WVec.New(0, 0, Actor.CruiseAltitude("badr"))
	local transport = Actor.Create("badr", true, { CenterPosition = start, Owner = india, Facing = (Map.CenterOfCell(lz) - start).Facing })

	Utils.Do(ParadropUnitTypes, function(type)
		local a = Actor.Create(type, false, { Owner = india })
		BindActorTriggers(a)
		transport.LoadPassenger(a)
	end)

	transport.Paradrop(lz)
	Trigger.AfterDelay(DateTime.Seconds(15), ParadropIndianUnits)
end



WorldLoaded = function()
    player = Player.GetPlayer("PAKISTAN")
    india = Player.GetPlayer("INDIA")

    Trigger.OnObjectiveCompleted(player, function(p, id)
        Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed")
    end)

    Trigger.OnObjectiveFailed(player, function(p, id)
        Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed")
    end)

    Trigger.OnKilled(Outpost, OutpostDestroyed)

    SurviveObjective = player.AddPrimaryObjective("The outpost must survive.")
    DestroyObjective = india.AddPrimaryObjective("The Pakistani outpost must be destroyed.")

    Trigger.AfterDelay(DateTime.Seconds(120), function()
        MissionAccomplished()
        player.MarkCompletedObjective(SurviveObjective)
        india.MarkFailedObjective(DestroyObjective)
    end)
    Trigger.AfterDelay(DateTime.Seconds(2), function() Actor.Create("camera", true, { Owner = player, Location = PakRally.Location }) end)
	Camera.Position = Outpost.CenterPosition
    Trigger.AfterDelay(DateTime.Seconds(5), SendJeeps) --Sending Allied reinforcements 
    SendIndianInfantry(IndiaEntry.Location, Force, ForceInterval) --Sending Indian ground troops every 15 seconds   
    ParadropIndianUnits()
    Trigger.OnAllKilled(AttackersTeam, AttackersKilled)
    Trigger.AfterDelay(DateTime.Seconds(5), SendPatrol)
end
  • made by Umair Azfar Khan
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.