21266 Posts in 3600 Topics - by 7452 Members - Latest Member: Kruzeru

Author Topic: [SOLVED!] Help with integrating custom modules into game (spoilers ahead)  (Read 1905 times)

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile
     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:
Code: [Select]
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:
Code: [Select]
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.
« Last Edit: March 20, 2017, 11:08:10 PM by jupiter878 »

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile
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.
« Last Edit: March 20, 2017, 05:58:16 AM by jupiter878 »

infal

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: [REQ] Help with integrating custom modules into game (spoilers ahead)
« Reply #2 on: March 20, 2017, 07:58:01 AM »
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:
Code: [Select]
local result = transformToCustomSuperModule(items)
if result == nil then
result = transform(items)
end

and then
Code: [Select]
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
If you go to Profile->Forum Profile there is an option to enter your ICQ number! Pretty rad... if this were 1995!

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile
Re: [REQ] Help with integrating custom modules into game (spoilers ahead)
« Reply #3 on: March 20, 2017, 04:42:35 PM »
Nice to see you again, sir!  ;D
Code: [Select]
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?
« Last Edit: March 20, 2017, 05:05:16 PM by jupiter878 »

infal

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: [REQ] Help with integrating custom modules into game (spoilers ahead)
« Reply #4 on: March 20, 2017, 06:10:18 PM »
So this code
Code: [Select]
local result = transformToCustomSuperModule(items)
if result == nil then
    result = transform(items)
end
would go in the research function and would replace
Code: [Select]
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
Code: [Select]
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.
If you go to Profile->Forum Profile there is an option to enter your ICQ number! Pretty rad... if this were 1995!

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile
Re: [REQ] Help with integrating custom modules into game (spoilers ahead)
« Reply #5 on: March 20, 2017, 10:34:03 PM »
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?
Code: [Select]
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!
« Last Edit: March 21, 2017, 12:28:06 AM by jupiter878 »

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile



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?
« Last Edit: March 21, 2017, 12:30:39 AM by jupiter878 »

Wilponderoci

  • Full Member
  • ***
  • Posts: 203
  • one fish two fists
    • View Profile
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
“Everything that irritates us about others can lead us to an understanding of ourselves.”

Martin Levac

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
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.

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile
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! :)
« Last Edit: March 21, 2017, 02:37:22 AM by jupiter878 »

Martin Levac

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
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.

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile
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.
« Last Edit: March 21, 2017, 03:47:15 AM by jupiter878 »

Wilponderoci

  • Full Member
  • ***
  • Posts: 203
  • one fish two fists
    • View Profile
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.
“Everything that irritates us about others can lead us to an understanding of ourselves.”

jupiter878

  • Newbie
  • *
  • Posts: 25
  • This game is a godsend
    • View Profile
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?

Martin Levac

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
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.