LUA script to force AI to build in a certain Order

Information and discussion for custom maps and mods.
Post Reply
User avatar
Zeruel87
Posts: 56
Joined: Mon Oct 15, 2018 8:18 pm
Location: Austria
Contact:

LUA script to force AI to build in a certain Order

Post by Zeruel87 »

Good evening,

i know it is possible but i dont know how cause i'am still not that experienced with LUA, maybe someone can give me an idea.

my goal is for some mod factions for my mod to tell the AI that if a bot plays that faction he is forced to build the first couple of buildings in a certain order.
Lets say for example: "power plant - refinery - refinery"

my idea is to start the Script like the SupplyTruck Script like that to define if the player is a bot:

p1cash = function()
if p1 and p1.IsBot then


and then tell him to build in a certain order, i guess it is doable with this operation?
bool Build(String[] actorTypes, LuaFunction actionFunc = nil)

i played around with this a little but dont know how to get it to work
Check out my CnC mod at:
https://www.moddb.com/mods/cameo

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

Re: LUA script to force AI to build in a certain Order

Post by abcdefg30 »

We do not support letting players place buildings via Lua, sorry. The Soviet-06 maps are currently using (horrible) workarounds to simulate the AI building a base, maybe you can get some inspiration from there.

User avatar
Zeruel87
Posts: 56
Joined: Mon Oct 15, 2018 8:18 pm
Location: Austria
Contact:

Re: LUA script to force AI to build in a certain Order

Post by Zeruel87 »

abcdefg30 wrote:
Thu Nov 22, 2018 8:09 pm
We do not support letting players place buildings via Lua, sorry. The Soviet-06 maps are currently using (horrible) workarounds to simulate the AI building a base, maybe you can get some inspiration from there.
i guess you are reffering to "soviet06a-AI"?


but then what is this for?: bool Build(String[] actorTypes, LuaFunction actionFunc = nil)


so it is not supportet to let players place buildings and even force them to build in a specific queue in a specific order?
Check out my CnC mod at:
https://www.moddb.com/mods/cameo

User avatar
Inq
Posts: 95
Joined: Sun Sep 27, 2015 2:48 am

Re: LUA script to force AI to build in a certain Order

Post by Inq »

A workaround could be using yaml prerequisite & condition systems.

For instance you could clone the refinery (make it only available to the specific bot/faction) & make ai build Powerplant then Refinery & then refinery 2 before it can unlock other buildings.

You’d need to clone most of the bots techtree do you could change the prerequisite buildings & also add the clone buildings to the AI.yaml.

User avatar
Zeruel87
Posts: 56
Joined: Mon Oct 15, 2018 8:18 pm
Location: Austria
Contact:

Re: LUA script to force AI to build in a certain Order

Post by Zeruel87 »

Inq wrote:
Fri Nov 23, 2018 12:51 am
A workaround could be using yaml prerequisite & condition systems.

For instance you could clone the refinery (make it only available to the specific bot/faction) & make ai build Powerplant then Refinery & then refinery 2 before it can unlock other buildings.

You’d need to clone most of the bots techtree do you could change the prerequisite buildings & also add the clone buildings to the AI.yaml.
that is exactly how iam doing it at the moment :D

for example, i attatch to the Main Building "fact" the lines:

Code: Select all

	GrantConditionOnBotOwner:
		Condition: botplayer
		Bots: cabal, watson, hal9001
	ProvidesPrerequisite@botowner:
		Prerequisite: botplayer
		RequiresCondition: botplayer
then i exclude buildings for the bot so he can have his own with his own prerequisites with:

Code: Select all

	Buildable:
		Prerequisites: !botcity
Clone the Building (give it a new, copy the line or do it with "inherits:") and add the lines so the building is not visible for Human players and of course it shows a correct sprite:

Code: Select all

	Buildable:
		Prerequisites: ~botcity
	RenderSprites:
		Image: pyle
if there is no LUA solution then i will stick to this work around.


except i find another way.. i have to try if it is somehow possible to stack conditions and then get a prerequisite?
i mean, at least it is possible for ranking units that there is a counter for their ranks:

Code: Select all

	DamageMultiplier@RANK-3:
		RequiresCondition: rank-veteran == 3
		Modifier: 85
maybe i can utilize this for a work around somehow, so i can tell a bot player for example he needs 4 Refineries before he gets the prerequisite to build a Weapons Factory.
i will look into it :)
Check out my CnC mod at:
https://www.moddb.com/mods/cameo

User avatar
Zeruel87
Posts: 56
Joined: Mon Oct 15, 2018 8:18 pm
Location: Austria
Contact:

Re: LUA script to force AI to build in a certain Order

Post by Zeruel87 »

hmmm... i looked into it, i cant seem to find a way to provide a prerequisite as soon as a certain number of one building is build on the map.

for example:
as soon as a player has 4 Power Plants - the Power Plants provide a new prerequisite necesary to build other buildings... that does not seem do be possible in any way i think.

only with another work around, if i make 4 seperate Power Plants, limit them to 1 and each of those grant an unique prerequisite "power1" ""power2" "power3" "power4" i can tell all other further buildngs they need to have all of the 4 unique prerequisites before they can be build.
the problem with this is, if i also make it possible afterwards to build as many "normal" power plants as you want, it DOES matter wich power plant is destroyed for the player.
if one of the first 4 is destroyed, the prerequisites are not met anymore for many buildings... if one of the later "normal" power plants is destroyed, nothing happens to the 4 prerequisites...

well... no advantage without a disadvantage
Check out my CnC mod at:
https://www.moddb.com/mods/cameo

Post Reply