Is it possible to add a new "preferred building method" ?

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
errorname1002
Posts: 99
Joined: Fri, 30. Nov 18, 23:54
x4

Is it possible to add a new "preferred building method" ?

Post by errorname1002 » Fri, 30. Sep 22, 21:43

I am currently working on a Xenon mod which allows you to use Xenon structures, ships, weapons, equipment, and economy but I am having to overwrite the "closedloop" method for drones so I can build them on my stations using Xenon economy, is there a way to create a new selectable build method ?

User avatar
Stoats not Goats
Posts: 144
Joined: Wed, 6. Dec 17, 09:49
x4

Re: Is it possible to add a new "preferred building method" ?

Post by Stoats not Goats » Sat, 1. Oct 22, 13:28

Yeah mate, most of what you'll be looking for is in wares.xml, particularly the Terran DLC's patch for it. At the start of the file you can declare a new build method as well as which faction(s) will use it as a default.
Taking a bath in Kingdom End :boron:

My X4:F guides, maps and summaries|My highway mods|Get involved with the X4 wiki :)

errorname1002
Posts: 99
Joined: Fri, 30. Nov 18, 23:54
x4

Re: Is it possible to add a new "preferred building method" ?

Post by errorname1002 » Sat, 1. Oct 22, 15:47

Stoats not Goats wrote:
Sat, 1. Oct 22, 13:28
Yeah mate, most of what you'll be looking for is in wares.xml, particularly the Terran DLC's patch for it. At the start of the file you can declare a new build method as well as which faction(s) will use it as a default.
That is indeed the way to create a new building method, but you can't select the new build method in your global orders tab: https://prnt.sc/XFE7eKxcdNsM meaning , your player faction can't use this new method.

User avatar
Stoats not Goats
Posts: 144
Joined: Wed, 6. Dec 17, 09:49
x4

Re: Is it possible to add a new "preferred building method" ?

Post by Stoats not Goats » Sun, 2. Oct 22, 07:50

I wonder what makes the vanilla build methods different then? Have you tried adding the player as a faction to the list?
Taking a bath in Kingdom End :boron:

My X4:F guides, maps and summaries|My highway mods|Get involved with the X4 wiki :)

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13289
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Is it possible to add a new "preferred building method" ?

Post by euclid » Sun, 2. Oct 22, 12:37

Check the lua files. I think it requires the player's race to have this build method.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

errorname1002
Posts: 99
Joined: Fri, 30. Nov 18, 23:54
x4

Re: Is it possible to add a new "preferred building method" ?

Post by errorname1002 » Sun, 2. Oct 22, 18:00

euclid wrote:
Sun, 2. Oct 22, 12:37
Check the lua files. I think it requires the player's race to have this build method.

Cheers Euclid
Thanks for narrowing it down, sadly I am not that proficient in Lua, but I think I did found the area where you can set the preferred build method:

Code: Select all

 
 -- preferred build method
local row = ftable:addRow(false, { bgColor = Helper.defaultTitleBackgroundColor })
row[1]:setColSpan(8):createText(ReadText(1001, 11298), Helper.headerRowCenteredProperties)

local cursetting = ffi.string(C.GetContainerBuildMethod(controllable))
local curglobalsetting = ffi.string(C.GetPlayerBuildMethod())
local foundcursetting = false
local locresponses = {}
local n = C.GetNumPlayerBuildMethods()
if n > 0 then
	local buf = ffi.new("ProductionMethodInfo[?]", n)
	n = C.GetPlayerBuildMethods(buf, n)
	for i = 0, n - 1 do
		local id = ffi.string(buf[i].id)
		-- check if the curglobalsetting (which can be the method of the player's race) is in the list of options
		if id == curglobalsetting then
			foundcursetting = true
		end
		table.insert(locresponses, { id = id, text = ffi.string(buf[i].name), icon = "", displayremoveoption = false })
	end
end
-- if the setting is not in the list, default to default (if the race method is not in the list, there is no ware that has this method and it will always use default)
if not foundcursetting then
	curglobalsetting = "default"
end
local hasownsetting = cursetting ~= ""
	local rowdata = "info_buildrule_global"
local row = ftable:addRow({ rowdata }, { bgColor = Helper.color.transparent })
row[1]:createCheckBox(not hasownsetting, { width = config.mapRowHeight, height = config.mapRowHeight })
row[1].handlers.onClick = function(_, checked) return menu.checkboxSetBuildRuleOverride(controllable, checked, curglobalsetting) end
row[2]:setColSpan(7):createText(ReadText(1001, 8367))

local row = ftable:addRow("info_buildrule", { bgColor = Helper.color.transparent })
row[1]:setColSpan(8):createDropDown(locresponses, { height = Helper.standardTextHeight, startOption = hasownsetting and cursetting or curglobalsetting, active = hasownsetting }):setTextProperties({ fontsize = config.mapFontSize })
row[1].handlers.onDropDownConfirmed = function (_, id) return menu.dropdownBuildRule(controllable, id) end
row[1].handlers.onDropDownActivated = function () menu.noupdate = true end

ftable:addEmptyRow()

local row = ftable:addRow(false, { bgColor = Helper.defaultTitleBackgroundColor })
row[1]:setColSpan(8):createText(ReadText(1001, 7725), Helper.headerRowCenteredProperties)
Any idea what the next step will be ?

Edit1: so method definition is as follows:

Code: Select all

	} ProductionMethodInfo;
	typedef struct {
		const char* name;
		int32_t skilllevel;
		uint32_t amount;
drop down menu:

Code: Select all

function menu.dropdownOrdersBuildRule(_, id)
	C.SetFactionBuildMethod("player", id)
end
Last edited by errorname1002 on Sun, 2. Oct 22, 20:07, edited 3 times in total.

errorname1002
Posts: 99
Joined: Fri, 30. Nov 18, 23:54
x4

Re: Is it possible to add a new "preferred building method" ?

Post by errorname1002 » Sun, 2. Oct 22, 18:02

Stoats not Goats wrote:
Sun, 2. Oct 22, 07:50
I wonder what makes the vanilla build methods different then? Have you tried adding the player as a faction to the list?
Yes I did try that but sadly a negative result, I believe this used to work before 4.0 since before that you were not able to select different build methods so technically the game treated the player faction like any other faction.

Post Reply

Return to “X4: Foundations - Scripts and Modding”