Lua problem

AI production

Information and discussion for custom maps and mods.
Post Reply
SethXXX
Posts: 17
Joined: Sat Aug 30, 2014 9:07 am

Lua problem

Post by SethXXX »

Hello guys, I'm trying to create a simple mission, basically it's just a base vs base situation.

Ofc I want the Allies to attack me a bit, but they don't. They build the units I tell them to, so the first part works, but they don't attack me like they are supposed to, but instead just stand around in their base, doing nothing.

My Lua code:

Code: Select all

ParatrooperReinforcements = { "e1", "e1", "e4", "e4", "e4", "e4" }
Attack1Template  = { {AlliedBarracks, {"e1", "e1", "e1", "e3", "e3"}} }
Attack2Template  = { {AlliedWaFa, {"jeep", "1tnk"}} }
Attack3Template  = { {AlliedWaFa, {"2tnk", "2tnk"}} }

RunInitialActivities = function()
	Actor.Harvest(harv1)
	Actor.Harvest(harv2)
	Actor.Harvest(harvsov)
	Team.Do(InitialAttackers, function(c)
		Actor.Hunt(c)
	end)
end

HQDestroyed = function(self, e)
	MissionFailed()
end

BuildAttack1 = function()
	Production.BuildTeamFromTemplate(allies, Attack1Template, function(team)
		Team.Do(team, function(actor)
			Actor.OnIdle(actor, Actor.Hunt)
		end)
		Team.AddEventHandler(team.OnAllKilled, BuildAttack1)
	end)
end

BuildAttack2 = function()
	Production.BuildTeamFromTemplate(allies, Attack2Template, function(team)
		Team.Do(team, function(actor)
			Actor.OnIdle(actor, Actor.Hunt)
		end)
		Team.AddEventHandler(team.OnAllKilled, BuildAttack2)
	end)
end

BuildAttack3 = function()
	Production.BuildTeamFromTemplate(allies, Attack3Template, function(team)
		Team.Do(team, function(actor)
			Actor.OnIdle(actor, Actor.Hunt)
		end)
		Team.AddEventHandler(team.OnAllKilled, BuildAttack3)
	end)
end

MissionAccomplished = function()
	Mission.MissionOver({ player }, nil, false)
end

MissionFailed = function()
	Mission.MissionOver(nil, { player }, false)
end

WorldLoaded = function()
	player = OpenRA.GetPlayer("USSR")
	greece = OpenRA.GetPlayer("Greece")
	allies = OpenRA.GetPlayer("Allies")
	
	Actor.OnKilled(SovietHQ, HQDestroyed)
	
	InitialAttackers = Team.New({ Inf1, Inf2, Inf3, Inf4, Inf5, Inf6, Inf7 })
	
	RunInitialActivities()
	
	OpenRA.RunAfterDelay(2, BuildAttack1)
	
	OpenRA.RunAfterDelay(2, BuildAttack2)
	
	OpenRA.RunAfterDelay(2, BuildAttack3)
	
	OpenRA.RunAfterDelay(CameraDelay, function() Actor.Create("camera", { Owner = player, Location = camstart.Location }) end)
	
	OpenRA.SetViewportCenterPosition(camstart.CenterPosition)
	
	Media.PlayRandomMusic()
end

Tick = function()
	if Mission.RequiredUnitsAreDestroyed(allies) then
		MissionAccomplished()
	end
end
I am pretty sure this is just a simple misunderstanding by me, but nevertheless I can't figure out the reason.

Thanks in advance! :)

abcdefg30
Posts: 643
Joined: Mon Aug 18, 2014 6:00 pm

Post by abcdefg30 »

I think you missed something in line 22, 31, and 40.
This

Code: Select all

Actor.OnIdle(actor, Actor.Hunt)
has to be replaced with

Code: Select all

Actor.OnIdle(actor, function() Actor.Hunt(actor) end)

SethXXX
Posts: 17
Joined: Sat Aug 30, 2014 9:07 am

Post by SethXXX »

Sadly, this didn't work either, same problem still appears, the teams get built, but don't move anywhere... Maybe I should try using waypoints or Attack Move?

abcdefg30
Posts: 643
Joined: Mon Aug 18, 2014 6:00 pm

Post by abcdefg30 »

SethXXX wrote: Sadly, this didn't work either, same problem still appears, the teams get built, but don't move anywhere... Maybe I should try using waypoints or Attack Move?
Strange, but then try with attackmoves.

aria
Posts: 1
Joined: Wed Sep 03, 2014 5:05 pm

Post by aria »

This is what i pulled from my notes, not sure if it helps but give it a try.

Try adding this to

Production.EventHandlers.Setup(HOUSE)

House being the name the team to build for

;example

SetupWorld = function()
--this below needs to be on for teams to do actions in the team.do loop
Production.EventHandlers.Setup(HOUSE)
end

WorldLoaded = function()
SetupWorld()
end

Post Reply