Hi Everyone!
New starsector player here. Absolutely love the mod, it's so good! I have been trying to create the perfect star-system, and would love to include one of those fancy Artillery station for maximum shenanigans, but I'm having trouble spawning them. The old code doesn't seem to work any more:
Quote from: Enzoci on October 15, 2022, 10:17:37 AM
Is it possible to spawn the watchtowers? I'm currently trying to build a custom system, but i have no idea what the command could be.
one watchtower:
SectorEntityToken t = system.addCustomEntity(Misc.genUID(), faction.getDisplayName() + " Watchtower", "IndEvo_Watchtower", faction.getId(), null);
t.setOrbit(//Your preferred orbit);
magic method to spawn watchtowers in the default locations like they usually do:
IndEvo_ArtilleryStationPlacer.placeWatchtowers(starsystem, factionID);
runcode com.fs.starfarer.api.plugins.derelicts.IndEvo_ArtilleryStationPlacer.placeWatch
towers(Global.getSector().getStarSystem("YOUR_STAR_SYSTEM_NAME"), "FACTION_ID");
The faction ID for the normal watchtowers/artillery station is "IndEvo_derelict".
So anyways, I tried snooping around and jury-riging whatever code I could find on the forums. Came across a nice post about spawning stable locations, and tried implementing that code, with a few variables changed:
runcode SectorEntityToken _fleet = Global.getSector().getPlayerFleet();
StarSystemAPI _sys = (StarSystemAPI)_fleet.getContainingLocation();
SectorEntityToken _stable = _fleet.getContainingLocation().addCustomEntity(null, null, "IndEvo_ArtilleryStation", "neutral");
float _orbitRadius = com.fs.starfarer.api.util.Misc.getDistance(_fleet, _sys.getCenter());
float _orbitDays = _orbitRadius / (20f + new Random().nextFloat() * 5f);
float _angle = com.fs.starfarer.api.util.Misc.getAngleInDegrees(_sys.getCenter().getLocation(), _fleet.getLocation());
_stable.setCircularOrbit(_sys.getCenter(), _angle, _orbitRadius, _orbitDays);
And it almost works! Spawns the entity in the correct place, but game crashes immediately 2 seconds afterwards, when I click on it with the error code: Fatal:null. When checking the starsector.log file, it tells me the following:
java.lang.NullPointerException
at indevo.industries.artillery.entities.ArtilleryStationEntityPlugin.adjustTerrain
Range(ArtilleryStationEntityPlugin.java:462)
at indevo.industries.artillery.entities.ArtilleryStationEntityPlugin.matchTerrainR
ange(ArtilleryStationEntityPlugin.java:445)
at indevo.industries.artillery.entities.ArtilleryStationEntityPlugin.advance(ArtilleryStationEntityPlugin.java:75)
at com.fs.starfarer.campaign.CustomCampaignEntity.advance(Unknown Source)
at com.fs.starfarer.campaign.BaseLocation.advance(Unknown Source)
at com.fs.starfarer.campaign.StarSystem.advance(Unknown Source)
at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
at com.fs.starfarer.campaign.CampaignState.advance(Unknown Source)
at com.fs.starfarer.BaseGameState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher.o00000(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Could any of you coding geniuses enlighten me of my error? Or perhaps a command for spawning the artillery station + watchtowers? That would be super duper dope. Hoping for any replies
Once more, many thanks for the splendid mod, it's a blast!