Custom Paradrops on a Map

umairazfar edited this page Nov 9, 2014 · 3 revisions
Clone this wiki locally

This tutorial builds up on the previous one as it uses the same map and values

What to drop and where to drop

First of all we assign the units that we will be dropping.

ParadropUnitTypes = { "e1", "e1", "e1", "e3", "e3" }

Then we tell where to drop the units.

ParadropWaypoints = { PakRally, IndiaRally }

Defining the paradrop function

Now we define the function for para-dropping the units:

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

The first line tells the game to randomly pick one of the paradrop waypoints.

The second line tells the game that the transport can start from any random edge of the map.

We then create the "badr" bomber and use the values defined in the lines above to indicate from where it should start, who the owner is and in what direction it should face.

We then define a loop which tells the game what units to load on the bomber; using the ParadropUnitTypes array of values that we defined above.

Then we tell the bomber to paradrop on the lz and finally on the last line, we call the function again, which means that after 15 seconds, another bomber will come to do the paradrop.

Calling in the world

Finally, go to the WorldLoaded function and add this line in the end

ParadropIndianUnits()

And that is that. Not too hard was it? I am putting the entire code here for your convenience:

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

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

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(60), 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()
end
  • created by Umair Azfar Khan