Jump to content

[MOD]Turret Factory seed randomizer


Neotician

Recommended Posts

I had issues finding a mod for changing the seed of turret factories, so decided to make my own!

https://steamcommunity.com/sharedfiles/filedetails/?id=2063508125

The mod basically adds a button, next to the shopping list at the turret factory, that adds a random value between -10000 and 10000 to the seed of that factory.

The new seed is persistent, but does not modify the savefiles, this also means that the seed will revert to normal if the mod is disabled

 

This is my first time writing a mod for anything, as well as writing LUA, so feedback is appreciated.

 

Also, does anyone know of a way  of storing  easily searchable data between reloads, that is better than having a txt file for every turret factory?

Really miss my C# lists

Link to comment
Share on other sites

Very simple, interesting idea  :)

 

There actually is a mod adding more seeds, but currently outdated: https://steamcommunity.com/sharedfiles/filedetails/?id=1792861870

However, I like that your mod is very small, easy to maintain and does not alter savegames.

 

For saving data you should use the functions secure and restore. Turret factory doesnt have them in vanilla but you can easily add them, watch factory.lua script for a good example.

 

In secure you can simply return a table of data, you wanna save. When the sector/galaxy is restored from disk the function restore is called, and the table you returned in secure is 1st parameter given to restore.

 

local someVarToSave = "myValue1"local someOtherVarToSave = "myOtherValue"


function MyAwesomeNamespace.secure()
    local data = {}    data.value1 = someVarToSave    data.value2 = someOtherVarToSave
    return data
end
function MyAwesomeNamespace.restore(data)
    someVarToSave = data.value1
    someOtherVarToSave = data.value2end

 

Link to comment
Share on other sites

 

For saving data you should use the functions secure and restore. Turret factory doesnt have them in vanilla but you can easily add them, watch factory.lua script for a good example.

 

In secure you can simply return a table of data, you wanna save. When the sector/galaxy is restored from disk the function restore is called, and the table you returned in secure is 1st parameter given to restore.

 

 

Thanks a lot!

My problem has turned into a two-parter, it seems  the Devs has made sectorturretgenerator.lua in such a way that each 15x15 quadrant can only have 5 different seeds for every type and rarity (so  20 variants per weapon type , 5 per type per rarity), so i need to mod that as well to get some more variety.

 

The second part is those Restore and Secure functions, i thought i understood them, but can't seem to get it working.

This is the setup:

function TurretFactory.restore(data)
local station = Entity()
local settings = GameSettings()
TheList = data
SeedMod = TheList[settings.seed .. "_" .. station.index.number]
end

function TurretFactory.secure()
local station = Entity()
local settings = GameSettings()
if SeedMod ~= 0 then
TheList[settings.seed .. "_" .. station.index.number] = SeedMod
end
local data = TheList
    return data
end

 

My understanding is that Secure and Restore  manipulates a single table associated with the namespace.

I store my modifying value at the [Gameseed_StationIndex]'th index of tha table, so i'm able to store a value for each factory.

Again, working on the assumption that there is a table for each namespace, and not for each instance of the script.

 

Another assumption is that global variables work the way i think they do.

My SeedMod and TheTable are just placed at the top of my mod file, outside any function.

 

Writing this, i'm also realizing that if the  secure/restore table is for the namespace and not each instance, they would be overwriting eachother on secure, so that mustn't be the case.. hmm.

 

Sorry for the long post, but can you see what my probably blantant mistake is? :)

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...