Stavinsky Posted May 18, 2017 Share Posted May 18, 2017 I must say that I first took a bit of time and tried to figure out a way to add more turrets to stations and did hit a wall by not finding any information that could help me. If anyone could point me to a list of the variables in stations that I could mess with I would be very thankful. But if those are too 'complicated' arcane for my small modding abilities, I would also ask if anyone has already though about adding systems to the stations, as it would solve the problem I have actually on the server I use with friends, as the usual 1 armed, 1 all around and 1 unarmed turret limit is not enough. So is it possible possible to do a flat increase of a Station number of Armed, Unarmed, and those 'All Turret Type' numbers, or even possibly add a number of turrets depending on the station Volume perhaps mirroring the way upgrades change with the volume ? If the volume idea could be done, it would be nice to have a range of 3 to 15 turrets, so the stations would be able to defend themselves and fend off normal waves of attackers, but still need some help when having bigger waves coming. Pushing the idea a bit further, those turret slots added should be of the "any turret type" that way a player would be free to set the station with various turrets depending on it's job. A military station would be all guns (except for the basic unarmed turret), and a repair dock could get a few armed turret to cover it's various arcs and concentrate a couple of Hull repair turrets in it's "repair dock". Any way to accomplish this easily ? And I just though, if we could do that for player owned stations, why not add it to pirates stations out there ? As pirate shipyard and such stations are surely not going to be left 'defenseless' against potential raids, and that could add a bit more of challenge to those pirate sectors, when all the ships are destroyed and not make the "station" fights being a "boring afk shooting contest". Link to comment Share on other sites More sharing options...
Laserzwei Posted May 18, 2017 Share Posted May 18, 2017 I added this exact functionality in my Complexes Mod. You can use it as a reference. Everything related to it is in /entity/complexManager.lua. (However: Most of the code in it has nothing to do with adding turrets-for obvious reasons ;D). What you want is to use one of these Methods from the Entity()-Object (in your case your station): function var addBaseMultiplier(int type, float factor) function var addMultiplier(int type, float factor) function var addMultiplyableBias(int type, float factor) function var addAbsoluteBias(int type, float factor) function var addKeyedBaseMultiplier(int type, int key, float factor) function var addKeyedMultiplier(int type, int key, float factor) function var addKeyedMultiplyableBias(int type, int key, float factor) function var addKeyedAbsoluteBias(int type, int key, float factor) function removeBonus(int key) where type is an enum StatsBonuses. and one of these: ArbitraryTurrets UnarmedTurrets ArmedTurrets You have to renew the statbonus whenever the sector is loaded(including a restart of the game). Happy modding! Link to comment Share on other sites More sharing options...
Stavinsky Posted May 18, 2017 Author Share Posted May 18, 2017 Thanks Laserzwei, Took a look at your complex system, and found the addition in the update method. Not sure if I did understood how you do the whole thing. If you don't mind correcting me, but if I do understand right, I will have to add something like if onServer() == true then Entity():removeBonus(9988776) Entity():addKeyedAbsoluteBias(StatsBonuses.ArbitraryTurrets,9988776,3) end to the update(timestep) method of each kind of Stations I want to see having an additional 3 "all turret" bonus ? And have a different block ID for every stations file I modify of course ? And if that's right, I then can start to look how to get the volume value of a station and find a math formula to add a turret for every 10 millions cubic meter with a max addition of 12 turret to reach the 15 I though would be an 'not too op' value for the max amount of turrets on a station. Thanks in advance Link to comment Share on other sites More sharing options...
Laserzwei Posted May 18, 2017 Share Posted May 18, 2017 Thanks Laserzwei, Took a look at your complex system, and found the addition in the update method. Not sure if I did understood how you do the whole thing. If you don't mind correcting me, but if I do understand right, I will have to add something like if onServer() == true then Entity():removeBonus(9988776) Entity():addKeyedAbsoluteBias(StatsBonuses.ArbitraryTurrets,9988776,3) end to the update(timestep) method of each kind of Stations I want to see having an additional 3 "all turret" bonus ? And have a different block ID for every stations file I modify of course ? Thanks in advance You can use the same key for different stations. But don't use the same key for different kinds of statboni on the same entity. And if that's right, I then can start to look how to get the volume value of a station and find a math formula to add a turret for every 10 millions cubic meter with a max addition of 12 turret to reach the 15 I though would be an 'not too op' value for the max amount of turrets on a station. Simple Math: local key = 666 station:removeBonus(key) local volume = station.volume -- also possible Entity().mass local turretNum = math.min(volume / 1e7, 12) if turretNum > 0 then station:addKeyedAbsoluteBias(StatsBonuses.ArbitraryTurrets, key, turretNum) end where key can be any number. 1e7 is short for 10^7 = 10,000,000. math. min selects values smaller or equal to 12. The if is to prevent adding an uneccessary bonus, if zero turrets would be added. Link to comment Share on other sites More sharing options...
Stavinsky Posted May 19, 2017 Author Share Posted May 19, 2017 Thanks a lot Laserzwei. With your help I managed to add turrets to most of the factories I need to get armed in the game. Your example and code were perfect, but the game store the volume in a way that needed a bit of tweaking of the volumeStep divider you provided. Thanks to darkconsole and his event balancer, I had read about that tiny bit of information while tweaking his mod for our server. So the 'shipyard' code look like this local station = Entity() local key = 6789 -- The blockID that should not be in use. local turretNum = 0 local volumeStep = 1.75e4 -- 15000 that translate in 15M m^3 local maxTurret = 18 -- Making 20 armed turret at 315M m^3. station:removeBonus(key) turretNum = math.min(station.volume / volumeStep, maxTurret) if turretNum > 0 then Entity():addKeyedAbsoluteBias(StatsBonuses.ArbitraryTurrets, key, turretNum) end and I insert that code in the various stations function update(timeStep) methods and I change the values of the volumestep and maxturret depending on the station job. Like for the Repair Dock that get a fixed number of unarmed turrets slot, and a variable amount of "all turret type" slot. local station = Entity() local key = 6789 -- The blockID that should not be in use. local turretNum = 0 local volumeStep = 7.5e3 -- Smaller steps local maxTurret = 8 -- Up to 10 armed turrets should be enough in a repair dock. station:removeBonus(key) turretNum = math.min(station.volume / volumeStep, maxTurret) if turretNum > 0 then Entity():addKeyedAbsoluteBias(StatsBonuses.ArbitraryTurrets, key, turretNum) end -- Being a Repair Dock, it get some extra unarmed turret slot for repair equipement local repairDockExtraUnarmedTurrets = 6 local repairDockKey = 67899 -- The blockID that should not be in use. Entity():removeBonus(repairDockKey) Entity():addKeyedAbsoluteBias(StatsBonuses.UnarmedTurrets, repairDockKey, repairDockExtraUnarmedTurrets) The only 2 stations that I have to left out of that for now are the Research station and equipment dock. Both are missing the update method, and when I tried to add the code in various areas, or write a new update method with the ggetUpdateInterval() I both those stations started to lose some of their Menus (the research one and the Systems sell and buy one). So for now and until I figure a way to add those turrets, we will keep with what we already have and that will help our team survive better in the core, as we upped the difficulty there. So thanks a lot again Laserzwei, as you really pointed me in the right direction and helped me achieve that change. I'm so 'rusty' with modding and coding, that I really needed and appreciated the help. Link to comment Share on other sites More sharing options...
Laserzwei Posted May 19, 2017 Share Posted May 19, 2017 iirc every script that runs on an Entity will call the update(timestep) method every gametick- if there is no update method it simply gets skipped. So once an update method is inserted into the code it should be called. Link to comment Share on other sites More sharing options...
Stavinsky Posted May 19, 2017 Author Share Posted May 19, 2017 Yes I saw that. But strangely if I do add the 2 methods (update and the get update interval) that's when the Research and the Equipment Dock start to act strangely and lose their menus. So I must do some testing to see why it act that way. Still can't understand why something added in the update would remove the Research menu in the Research station and the System sell/buy option in the equipment dock. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now