Use lua script to change prerequisites trait?

Is it possible to use luna script to change prerequisites trait?

Information and discussion for custom maps and mods.
Post Reply
Lassar
Posts: 33
Joined: Tue Dec 18, 2018 11:20 pm

Use lua script to change prerequisites trait?

Post by Lassar »

I am wanting to use a luna script to change the prerequisites trait of a ship yard.

A example of this would be to change prerequisites trait based on difficulty level.

A example in rules is:

SYRD:
Buildable:
Prerequisites: anypower

So if difficulty level is hard, the lua script would do the equivalent of.

SYRD:
Buildable:
Prerequisites: ~disabled

So how would I do this in lua script?

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

Re: Use lua script to change prerequisites trait?

Post by abcdefg30 »

You can use Lua to grant a preqrequisite, so you could change it to something like

Code: Select all

SYRD:
	Buildable:
		Prerequisites: ~easy, anypower
and grant the "easy" prerequisite from Lua.

Lassar
Posts: 33
Joined: Tue Dec 18, 2018 11:20 pm

Re: Use lua script to change prerequisites trait?

Post by Lassar »

Would you give me a example on how to do this?

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

Re: Use lua script to change prerequisites trait?

Post by abcdefg30 »

In your rules.yaml:

Code: Select all

SYRD:
	Buildable:
		Prerequisites: ~easy, anypower

EASY:
	AlwaysVisible:
	Interactable:
	ProvidesPrerequisite:
In Lua:

Code: Select all

-- assuming you have a variable "difficulty"
if difficulty == "easy" then
	-- creates the actor for player with variable name "player1", which grants the prerequisite
	Actor.Create("easy", false, { Owner = player1 })
end
That should hopefully do it. (Note that I wrote it off the top of my head, so it might need slight adjustments, but I hope you get the gist.)

Post Reply