Page 1 of 1

Use lua script to change prerequisites trait?

Posted: Sun Jun 06, 2021 7:39 pm
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?

Re: Use lua script to change prerequisites trait?

Posted: Mon Jun 07, 2021 11:28 am
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.

Re: Use lua script to change prerequisites trait?

Posted: Mon Jun 07, 2021 2:00 pm
by Lassar
Would you give me a example on how to do this?

Re: Use lua script to change prerequisites trait?

Posted: Mon Jun 07, 2021 5:56 pm
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.)