Jump to content

[SOLVED!] Help with integrating custom modules into game (spoilers ahead)


jupiter878

Recommended Posts

    So I've been trying to get around the 90 turrets limit for a while now. First I've tried modding the number of slots available, but that turned out to be near impossible since it was hard coded. Then I've tried to create my own modules, and integrate them into the game through research - more specifically, basing it on the way how the 2nd Xsotan artifact is obtained by putting 3 or more legendary system upgrades and researching them. The full extent of my plan is to create four more modules above the Xsotan artifacts, each giving 25, 125, 625, and 3125 extra turret slots, with each of them obtained only by putting 5 of the previous level upgrade through the research station, and the first one being obtained by researching five artifacts.

    When I asked about this in the subreddit, they said that creating the upgrades would be easy enough, but the other part would be a hassle, and they were right; I have created the modules, complete with (hopefully non copyrighted) images for their icons. However, even after looking at the researchstation.lua file for hours and hours on end, I simply cannot seem to figure out how this should work; the part I feel that I should base my scripts on is this:

function transform(items)

    local transformToKey

    if items[1].itemType == InventoryItemType.SystemUpgrade
        and items[2].itemType == InventoryItemType.SystemUpgrade
        and items[3].itemType == InventoryItemType.SystemUpgrade
        and items[1].rarity.value == RarityType.Legendary
        and items[2].rarity.value == RarityType.Legendary
        and items[3].rarity.value == RarityType.Legendary then

        local inputKeys = 0
        for _, item in pairs(items) do
            if string.match(item.script, "systems/teleporterkey") then
                inputKeys = inputKeys + 1
            end
        end

        if inputKeys <= 1 then
            transformToKey = true
        end
    end

    local result

    if transformToKey then
        result = SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua", Rarity(RarityType.Legendary), random():createSeed())

Although it does seem to say that the three items can be any kind of legendary upgrade, when I put in three Xsotan artifacts in the research station to search for any possible conflicts, the resulting Xsotan artifact wasn't always the 2nd one, despite them all being legendary system upgrades. Does this mean that the artifacts are in a separate category from the rest of the upgrades?

    Also, despite myself having near zero programming experience whatsoever, I still tried modifying the researchstation.lua file once, with my first goal being implementing the first of the four custom upgrades, while also limiting it to one recipe - five of the 2nd Xsotan artifacts - and here is the end result:

function transform(items)

    local transformTo25

    if items[1].itemType == InventoryItemType.SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua")
        and items[2].itemType == InventoryItemType.SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua")
        and items[3].itemType == InventoryItemType.SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua")
        and items[4].itemType == InventoryItemType.SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua")
        and items[5].itemType == InventoryItemType.SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua") then

        local input25 = 0
        for _, item in pairs(items) do
            if string.match(item.script, "systems/teleporterkey") then
                input25 = input25 + 1
            end
        end

        if input25 <= 1 then
            transformTo25 = true
        end
    end

    local transformToKey

    if items[1].itemType == InventoryItemType.SystemUpgrade
        and items[2].itemType == InventoryItemType.SystemUpgrade
        and items[3].itemType == InventoryItemType.SystemUpgrade
        and items[1].rarity.value == RarityType.Legendary
        and items[2].rarity.value == RarityType.Legendary
        and items[3].rarity.value == RarityType.Legendary then

        local inputKeys = 0
        for _, item in pairs(items) do
            if string.match(item.script, "systems/teleporterkey") then
                inputKeys = inputKeys + 1
            end
        end

        if inputKeys <= 1 and not transformTo25 = true then
            transformToKey = true
        end
    end

    local result

    if transformTo25 then
        result = SystemUpgradeTemplate("data/scripts/systems/25.lua", Rarity(RarityType.Legendary), random():createSeed())
    if transformToKey then
        result = SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua", Rarity(RarityType.Legendary), random():createSeed())

And when I overwrote the original files to this and played the game, the research station flat out refused to give me the "research" option at all, so I reverted it back to the original and gave up. Is there any way to properly limit the item types from all system upgrades to just the Xsotan artifacts? How do I manage to properly separate the "conditions" of the two functions, and how could I do this for the three other custom upgrades, if this is possible at all? Am I looking at the wrong file entirely? Are the custom upgrade files themselves flawed? I would gladly accept help from any of you lua&programming wizards out there. Files for the custom upgrades and my half assed attempt at modifying the researchstation.lua file is attatched below.

More_Turrets.zip

Link to comment
Share on other sites

Also, if you guys want to just finish the mod yourselves based on this proposal, then go ahead; this is just a concept at this point, and I do not claim any ownership over this, if that's even possible in the first place. If there's any mods that do similar things that I've missed, please write about them as well. And yes, I know that I can just modify the values of the existing upgrades and Xsotan artifacts, I just want to figure out a solution that would be slightly fancier and feels more "natural", i guess.

Link to comment
Share on other sites

When I asked about this in the subreddit, they said that creating the upgrades would be easy enough, but the other part would be a hassle, and they were right;
Hey, that was me!  ;D

 

I would probably look at putting a check in before the transform method is even called. eg:

local result = transformToCustomSuperModule(items)
if result == nil then
result = transform(items)
end

 

and then

function transformToCustomSuperModule(items)
-- If there are the 5 modules you need to make the super module,
-- return the super module.
-- Otherwise, return nil and let the default transform function
-- handle it
end

Link to comment
Share on other sites

Nice to see you again, sir!  ;D

function receiveResult(result)
    results:clear();
    results:addInventoryItem(result);

    onShowWindow()
end

function
    local result = transformToCustomSuperModule(items)
    if result == nil then
result = transform(items)
end

function transformToCustomSuperModule(items)
    -- If there are the 5 modules you need to make the super module,
    -- return the super module.
    -- Otherwise, return nil and let the default transform function
    -- handle it
end

function transformToCustomSuperModule(items)

    local transformto25


end

function transform(items)

    local transformToKey

    if items[1].itemType == InventoryItemType.SystemUpgrade
        and items[2].itemType == InventoryItemType.SystemUpgrade
        and items[3].itemType == InventoryItemType.SystemUpgrade
        and items[1].rarity.value == RarityType.Legendary
        and items[2].rarity.value == RarityType.Legendary
        and items[3].rarity.value == RarityType.Legendary then

        local inputKeys = 0
        for _, item in pairs(items) do
            if string.match(item.script, "systems/teleporterkey") then
                inputKeys = inputKeys + 1
            end
        end

        if inputKeys <= 1 then
            transformToKey = true
        end
    end

    local result

    if transformToKey then
        result = SystemUpgradeTemplate("data/scripts/systems/teleporterkey2.lua", Rarity(RarityType.Legendary), random():createSeed())

Where should I go from here? Am I doing this right?

editedresearchstation_V2.zip

Link to comment
Share on other sites

So this code

local result = transformToCustomSuperModule(items)
if result == nil then
    result = transform(items)
end

would go in the research function and would replace

local result = transform(items)

That way, the function transformToCustomSuperModule would be called first and transform would only be called if the player didn't have the right ingredients for your module(s).

Instead of calling transform, we want to call transform only if the player doesn't have the ingredients for the custom modules.

 

transformToCustomSuperModule would do the checks for any custom modules eg

function transformToCustomSuperModule(items)
-- i is a counter to keep track of how many modules match the required input
local i


i = 0
for _, item in pairs(items) do
	if string.match(item.script, "systems/teleporterkey") then
		-- if the input was okay, add 1 to i
		i = i + 1
	end
end
-- check if i is 5. If it is then the player put 5 of the right modules in.
if i == 5 then
	-- return the custom 25 module
	return SystemUpgradeTemplate("data/scripts/systems/25turret.lua", Rarity(RarityType.Legendary), random():createSeed())
end


-- Just copy and paste from above to get the next recipe
i = 0
for _, item in pairs(items) do
	if string.match(item.script, "systems/25turret") then
		-- if the input was okay, add 1 to i
		i = i + 1
	end
end
-- check if i is 5. If it is then the player put 5 of the right modules in.
if i == 5 then
	-- return the custom 125 module
	return SystemUpgradeTemplate("data/scripts/systems/125turret.lua", Rarity(RarityType.Legendary), random():createSeed())
end


-- the input was not valid for any of our recipes so just return nil
    return nil
end

 

Most of the code in transform is not really relevant to what you need to do.

Link to comment
Share on other sites

The research station still doesn't want to show me the research option. Is there anything that I did wrong? Or do I need to create a new map to make this kind of change take effect?

local errors = {}
    errors[EntityType.Station] = "You must be docked to the station to research items."%_T
    errors[EntityType.Ship] = "You must be closer to the ship to research items."%_T
    if not CheckPlayerDocked(player, station, errors) then
        return
    end

    local result = transformToCustomSuperModule(items)
    if result == nil then
result = transform(items)

    if result then
        for index, amount in pairs(itemIndices) do
            for i = 1, amount do
                player:getInventory():take(index)
            end
        end

        player:getInventory():add(result)

        invokeClientFunction(player, "receiveResult", result)
    else
        print ("no result")
    end


end

function receiveResult(result)
    results:clear();
    results:addInventoryItem(result);

    onShowWindow()
end

function transformToCustomSuperModule(items)
-- i is a counter to keep track of how many modules match the required input
local i


i = 0
for _, item in pairs(items) do
	if string.match(item.script, "systems/teleporterkey") then
		-- if the input was okay, add 1 to i
		i = i + 1
	end
end
-- check if i is 5. If it is then the player put 5 of the right modules in.
if i == 5 then
	-- return the custom 25 module
	return SystemUpgradeTemplate("data/scripts/systems/25.lua", Rarity(RarityType.Legendary), random():createSeed())
end


i = 0
for _, item in pairs(items) do
	if string.match(item.script, "systems/25") then
		-- if the input was okay, add 1 to i
		i = i + 1
	end
end
-- check if i is 5. If it is then the player put 5 of the right modules in.
if i == 5 then
	-- return the custom 125 module
	return SystemUpgradeTemplate("data/scripts/systems/125.lua", Rarity(RarityType.Legendary), random():createSeed())
end


i = 0
for _, item in pairs(items) do
	if string.match(item.script, "systems/125") then
		-- if the input was okay, add 1 to i
		i = i + 1
	end
end
-- check if i is 5. If it is then the player put 5 of the right modules in.
if i == 5 then
	-- return the custom 625 module
	return SystemUpgradeTemplate("data/scripts/systems/625.lua", Rarity(RarityType.Legendary), random():createSeed())
end


i = 0
for _, item in pairs(items) do
	if string.match(item.script, "systems/625") then
		-- if the input was okay, add 1 to i
		i = i + 1
	end
end
-- check if i is 5. If it is then the player put 5 of the right modules in.
if i == 5 then
	-- return the custom 3125 module
	return SystemUpgradeTemplate("data/scripts/systems/3125.lua", Rarity(RarityType.Legendary), random():createSeed())
end


-- the input was not valid for any of our recipes so just return nil
    return nil
end

function transform(items)

    local transformToKey

    if items[1].itemType == InventoryItemType.SystemUpgrade
        and items[2].itemType == InventoryItemType.SystemUpgrade
        and items[3].itemType == InventoryItemType.SystemUpgrade
        and items[1].rarity.value == RarityType.Legendary
        and items[2].rarity.value == RarityType.Legendary
        and items[3].rarity.value == RarityType.Legendary then

        local inputKeys = 0

The turret files themselves are just called "25.lua", "125.lua", "625.lua", and "3125.lua"

 

*edit: forgot to put in "end" after the check. And praise the Xsotan deities, it WORKS! Perfectly, in fact!

Link to comment
Share on other sites

90JS9s1.jpg

790WUnn.jpg

cqdSh7A.jpg

Yeah, this is working exactly in the way I wanted it to work. Did you know that I made a reddit account for the first time to ask that question that I asked you back then? And here I am, with the finished mod! Thanks a bunch, infal.  :)

 

Do you know if I need to move this thread somewhere else, now that I no longer need help on this subject?

Link to comment
Share on other sites

jupiter878 You are like jesus or something....

 

The chosen one.

 

;)

 

I love that this kind of stuff is happening here!!!

 

Rock on! 

 

Post your files man and call it the Godsend turret mod.

 

You can even retitle this this thread! 

 

Infal!

Youre

So  8) 8) 8) 8)

 

<3 <3 <3

Link to comment
Share on other sites

Which Xsotan artifact is needed at first? Is it the turret artifact, forget exactly the name, but numeral is IV I think? I mean that would make sense since each gives +5 to turrets so 5x of those would logically produce a +25 super artifact, right?

 

I'm gonna try this mod. By the way, keep this thread in the mods sub-forum, it's a mod after all. And now that you solved it, change title to [MOD]. And thanks for making it, I appreciate it.

 

I just noticed that you modify the researchstation.lua file. I use autoresearch mod that modifies the same file. Would it be possible for you to integrate your mod into autoresearch, or work with the author of autoresearch to combine the two? I'm very likely not good enough with lua to do that myself, but autoresearch has become kinda essential in my game. I had tried an alternative where I just mod the systems directly by multiplying the turret bonus but I'd prefer to do that with a genuine mod like yours.

Link to comment
Share on other sites

The mod works with all Xsotan artifacts. Five and only five of any of the 8 types of Xsotan artifacts - not just the fourth one - combined in a research station will create the first of my four types of super upgrades, the Jovian^2, and five of those will create the Jovian^3, and so on up until the last upgrade, the Jovian^5. While using the Xsotan upgrades instead of the legendary turret control slot upgrades may sound counterintuitive, remember that the Xsotan artifacts cost no energy; all of my added super upgrades cost no energy to use as well, even the last one that would give you 5^5, or 3125 upgrades.

 

Unfortunately, since I've also included images for the new icons, the total file size goes way beyond the attachment limit of 192KB, even after compressing it to ZIP form. One solution is that I change the icons that the custom upgrades use from completely new images that I put in to the images that are already there, but this may cause confusion. Another solution is to make a crude icon myself using photoshop or mspaint or something of the like while greatly lowering the file size, but this has the danger of looking quite unprofessional, if somewhat unique, and I think I need to take a day off before doing any of that after the day-long struggle of putting this together with the help of the mighty infal.

 

It would also take a while to ask the author of the auto research mod to get permission to meld the two mods together, and even then I don't know if I'll be able to actually manage the merging process. I am, after all, a n00b with zero programming experience and if any of the other lua&programming sorcerers would volunteer to do the merging, that would be better for all of us, but it's also a mere possibility at this point.

 

In any case, I think it would be impolite to go ahead and properly release this before infal allows me to, the person being the sole reason that I could create this in the first place. So sorry guys, you'll have to wait for at least a day or two. Thanks for the nice words though! :)

Link to comment
Share on other sites

Build it, and they will come. Aw shucks, I thought I had downloaded the mod. Keep us posted on your progress. No rush, but I promise you it's gonna become another essential for me, and likely for others as well. It gives a tremendous extra incentive to hunt for Xsotan artifacts.

Link to comment
Share on other sites

Do keep in mind though that these upgrades will still not protect you from an unfortunate, insta-kill asteroid collision. I expect the pain from losing upgrades that hold hundreds of times the power of normal artifacts to be significantly greater. Also, while the game already allows you to build smaller ships with extreme firepower to some extent, this mod will outright allow you to build fighters that have the firepower of an entire armada, given that you have enough thrust to cancel out the recoil and/or generators to supply the weapons. This effectively destroys the basic meta of "big, powerful" and "small, weak", and may become a killjoy for some, though I don't suspect that it'll be soon for any of us.

Link to comment
Share on other sites

I certainly don't need that many turrets but I will say that I love trying to put as many on as possible. 

 

Best thing for recoil is inertial dampers.

 

Noticed them lighting up when firing a ton of cannons from a small fighter.

 

I made a series of super manuverable fighters with either loads of cannons or rockets. They work pretty good with current AI.

Link to comment
Share on other sites

Hmm, I probably should try out inertia dampeners and gyros and whatnot. I've been mostly giving dreadnoughts maneuverability by making half of their volume out of thrusters.

 

Btw, I just figured that if the files are too big to just attach, I could just upload them to dropbox or mediafire or something and then post the download link. Do any of you fellows know if there's any restrictions to adding download links like that?

Link to comment
Share on other sites

No, I don't think there's any restriction for external download links for mods. Screenshots are mostly external links because of their size, i.e. imgur.com for example. XML files for ships are also mostly external links, also because of their size.

 

Personally, I see the benefit in the greater number of other types of systems (battery, generator, shield, hyperdrive, etc) that I could use by freeing up several slots with a single Jovian^2 artifact. I mean extra firepower is nice and all, but extra boost in other systems allows a much greater freedom in ship design, i.e. smaller battery/generator/shield/hyperdrive blocks. With a single legendary hyperdrive system for example, we can already plan for a half-size block for that. With an extra slot, we can plan for even smaller, and so forth. And then there's the extra surplus energy that is no longer required for full size blocks, allowing even smaller generator blocks.

Link to comment
Share on other sites

Here's a fun little story.

 

 

I didn't like the names of the artifacts, so I changed them as a final touch, and then I tried to playtest to see if it still worked. I generated a new world with creative mode on and collision damage off - the very thoughts of those clumsy AI ships ramming into various parts of ships and destroying docks or that one unfortunate ship-killing type asteroid accidents make me shudder. I generated some nice hyperspace boosts in using the command pack mod to make my trip easier, and started to search for a research station.

 

I kid you not, it took me more than fifty fucking sectors to find one of those godforsaken stations. Fifty.

 

Z9WDLu8.jpg

jB5DfnK.jpg

 

Oh, and I almost forgot to tell you that I jumped halfway across the map

Vq96zBn.jpg

In sheer desperation.

 

I almost thought that my mod was causing issues with the spawn chance of the research stations, but noooooooo, it was just the game screwing with me thoroughly. The recent update suddenly allowed most of those malfunctioning steam achievements to work again. The reason that I noticed this was that I unlocked three achievements while looking for that one needle in a cosmic haystack.

 

Three.

 

Three potentially nice moments wasted in the self-imposed search/torment. I was almost about to delete and reinstall the game as well, but I didn't, so that's maybe a plus, I guess. Probably none of this would have happened had I not deleted all my previous saves for a fresh new start. What can I say?

 

At least no collision damage means that you can repeatedly ram your multi kilo-ton spacecraft at nearby asteroids with the speed of an ICBM, and distract yourself from the boredom of waiting for the next jump as you watch the entire ship momentarily turn as fast as a beyblade. The crew? Who cares. They're a bunch who would gladly be dismissed from the ship out in the middle of nowhere.

Even this short joy is taken away from you at sectors that have no asteroids though. In such trying times, I have never felt a stronger desire to be able to just boost into the planet in the background and see how the ship deals with the orange-yellow plasma that'll wrap around and slowly destroy it as it reenters, and/or smack into the ground with all the power of a tactical nuclear strike.

 

 

 

 

https://www.dropbox.com/s/w1kif30xxcjgf34/data.zip?dl=0

 

Here is the download link.

Unzip it and move it inside the "Steam\SteamApps\common\Avorion" folder. As with the conflict issue with the auto research mod, I'll see what I can do, but again, I can't say for sure if I'll be able to do it. And please, do enjoy.

For my sake. And my sanity.

And for infal as well, actually.

 

Speaking of which, infal, if you have time, tell me what you think about this. Since you have helped me carry this idea and allowed it to be completed, if you want me to mention you or not or leave a special thanks or anything else - just anything that you want to be done to this mod, any suggestions - just leave a reply.

 

Phew. 1:30 AM already. I should really go to sleep.

Link to comment
Share on other sites

Speaking of which, infal, if you have time, tell me what you think about this. Since you have helped me carry this idea and allowed it to be completed, if you want me to mention you or not or leave a special thanks or anything else - just anything that you want to be done to this mod, any suggestions - just leave a reply.

 

Phew. 1:30 AM already. I should really go to sleep.

Well I expect... no, demand, 75% of all profits  ;D

 

I don't really need any special mentions or anything, just pay it forward. As you get better and better at scripting /programming etc you start to find that you're less often the person asking questions and more often the person answering questions. So, as you get more experience, help the people starting out where and when you can. If you do that, my job here is complete.

 

I've run into the problem of renaming scripts causing problems myself. It seems like the game engine handles missing files by just deleting objects so, uninstalling mods is a challenge.

 

If you need to test, use the debug menu to spawn a research station.

/run Entity():addScript("lib/entitydbg.lua")

 

I'm glad it all worked for you. I like playing in a mid sized ship... don't like 5 - 6 of my 8 - 10 upgrade slots being Xsotan artifacts, so will definitely add this mod in.

 

I'd say start a new thread for the mod release, a lot of people just wanting to download mods wont necessarily click a thread asking for help with scripting.

Link to comment
Share on other sites

I don't really need any special mentions or anything, just pay it forward. As you get better and better at scripting /programming etc you start to find that you're less often the person asking questions and more often the person answering questions. So, as you get more experience, help the people starting out where and when you can. If you do that, my job here is complete.

 

 

Thanks batman!

...Or is it commissioner Gordon? Either way, thank you.

 

Oh, and I've went ahead and made the mod here:

https://www.avorion.net/forum/index.php/topic,3029.0.html

Anybody who wants more detailed instructions and whatnot can go there. Future updates (hopefully?) will be posted there as well, so use only that thread from now on.

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...