26304 Posts in 4431 Topics - by 9750 Members - Latest Member: Gethe1975

Author Topic: Custom Races/factions [wip - proof of concept]  (Read 2428 times)

LogicSocket

  • Jr. Member
  • **
  • Posts: 76
  • Necessity is the mother of invention.
    • View Profile
Custom Races/factions [wip - proof of concept]
« on: February 19, 2017, 11:19:28 PM »
So I created a custom races/faction modeled after examining the Xsotan files.
"The Dweenle" (Old Starflight game alien race)
I had to use my own command to spawn them but it works. Next I'll have to figure out how to randomly have them living
throughout the galaxy. Stay tuned. This would be a good thing to have a template for all modders so as to create custom galaxies with our own races and factions. They have their own custom ship that i created then placed in the plans folder.

« Last Edit: February 19, 2017, 11:20:59 PM by LogicSocket »

Devious

  • Hero Member
  • *****
  • Posts: 515
    • View Profile
    • Rusty's Galaxies and Community
Re: Custom Races/factions [wip - proof of concept]
« Reply #1 on: February 20, 2017, 07:27:44 PM »
It would indeed be cool if a custom faction could spawn throughout the galaxy,
Looking forward to your progress!

Joe70

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Custom Races/factions [wip - proof of concept]
« Reply #2 on: February 21, 2017, 07:21:22 AM »
Great ! Looking forward for this ! Would be very cool to edit Factions and there Ships and Stations

picklelord

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Custom Races/factions [wip - proof of concept]
« Reply #3 on: February 22, 2017, 03:34:26 AM »
This would be awesome, and has a lot of potential!
I have been looking at modding some stuff too and this idea was on my list! =D 
I have mostly been looking at ways to make what you receive more random, like the secret stashes.

It would be awesome if the factions could be dynamically added to, so like the upgrade systems all being picked up from a folder, the custom factions could have a folder so other custom factions could be easily dropped in.

How are you getting the Ship Plan in there?

LogicSocket

  • Jr. Member
  • **
  • Posts: 76
  • Necessity is the mother of invention.
    • View Profile
Re: Custom Races/factions [wip - proof of concept]
« Reply #4 on: February 22, 2017, 03:32:20 PM »
Hi picklelord,
sure i'll post the code so you and others can play around.

to define the new faction:
Code: [Select]
local Dweenle = {}

function Dweenle.getFaction()
    local name = "The Dweenle"%_T

    local galaxy = Galaxy()
    local faction = galaxy:findFaction(name)
    if faction == nil then
        faction = galaxy:createFaction(name, 0, 0)
        faction.initialRelations = 100000
        faction.initialRelationsToPlayer = 0
        faction.staticRelationsToPlayers = true

        for trait, value in pairs(faction:getTraits()) do
            faction:setTrait(trait, 0) -- completely neutral / unknown
        end
    end

    return faction
end

Create ship function for the new faction:
Code: [Select]
function Dweenle.createShip(position, volumeFactor)
    position = position or Matrix()
    local volume = Balancing_GetSectorShipVolume(Sector():getCoordinates())

    volume = volume * (volumeFactor or 1)
    volume = volume * 0.5 -- Dweenle ships aren't supposed to be very big

    local x, y = Sector():getCoordinates()
    local probabilities = Balancing_GetMaterialProbability(x, y)
    local material = Material(getValueFromDistribution(probabilities))
    local faction = Dweenle.getFaction()
    local plan = LoadPlanFromFile("data/plans/Dweenle.xml")
    local ship = Sector():createShip(faction, "", plan, position)

    Dweenle.infectShip(ship)

    -- Dweenle have random turrets
    TurretGenerator.initialize(random():createSeed())
    local turret = TurretGenerator.generateArmed(x, y)
    local numTurrets = math.max(2, Balancing_GetEnemySectorTurrets(x, y) * 0.75)

    ShipUtility.addTurretsToCraft(ship, turret, numTurrets)

    ship:setTitle("Dweenle ${ship}", {ship = ShipUtility.getMilitaryNameByVolume(ship.volume)})
    ship.crew = ship.minCrew
    ship.shieldDurability = ship.shieldMaxDurability

    AddDefaultShipScripts(ship)

    ship:addScript("ai/patrol.lua")
ship:addScript("antismuggle.lua")
    ship:addScript("story/Dweenlebehaviour.lua")
    ship:setValue("is_xsotan", 1)

    return ship
end

Code that will spawn the new ships:
Code: [Select]
function onSpawnDweenleButtonPressed()
    if onClient() then
        invokeServerFunction("onSpawnDweenleButtonPressed")
        return
    end

    local x, y = Sector():getCoordinates()

    local faction = Dweenle.getFaction()

    local right = Entity().right
    local dir = Entity().look
    local up = Entity().up
    local position = Entity().translationf

    local pos = position + dir * 100
  for i = -3, 3 do
    Dweenle.createShip()
    Placer.resolveIntersections()
end
end

To answer your question about how I got the ship plan is this bit:
LoadPlanFromFile("data/plans/Dweenle.xml")

you can build a ship, and save it then copy that xml and place it in data/plans/ folder.

Hope this helps!
-LS

Devious

  • Hero Member
  • *****
  • Posts: 515
    • View Profile
    • Rusty's Galaxies and Community
Re: Custom Races/factions [wip - proof of concept]
« Reply #5 on: February 22, 2017, 07:28:51 PM »
Nice, good work!
I have two questions, the first being what the reference to the Dweenlebehaviour.lua does.
And second, if it would also be possible to create a faction but let the game generate the ships for them.

I'm also curious wether it is possible to control how they spawn through the galaxy, for example their population density or how close to the center they spawn.

I think I understand how your file structure is so I will have a look at it myself but others could use some instructions on how to implement your code.
« Last Edit: February 22, 2017, 07:33:05 PM by Devious »

SiotiK

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Custom Races/factions [wip - proof of concept]
« Reply #6 on: May 23, 2018, 08:11:01 PM »
hallo an alle :)

ich habe eine frage.

Ich habe den Xsotan einen Schiffsbauplan zugeordnet und das hat auch wunderbar funktioniert.

Das schiff besitzt einen Hangar und genug platz für viele Jäger.

kann ich den schiffen noch Jäger hinzufügen ?



Hello everyone :)

I have a question.

I have assigned the Xsotan a shipbuilding plan and that worked fine too.

The ship has a hangar and enough space for many fighters.

Can I still add fighters to the ships?

SpaceBusBimbles

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Custom Races/factions [wip - proof of concept]
« Reply #7 on: June 14, 2018, 06:13:11 PM »
I have no clue how to install the code.   I would love to see a faction flying about using buses or WW2 ships :P
making bus saves for Avorion and its steam workshop

Kamo

  • Full Member
  • ***
  • Posts: 187
  • Cuddles float better in space~
    • View Profile
Re: Custom Races/factions [wip - proof of concept]
« Reply #8 on: June 14, 2018, 06:54:36 PM »
Someone is doing a mod of the same kind ! Maybe you could exchange faction creating tips :D.
I guess the Dweenle scripts come from the Xsotan ones.
Also nice ship LogicSocket :) !
Colorize messages, with the colors of materials (from wiki) !
Ir #FFB380 Ti #FFFFFF Na #4DFF4D Tr #4D9AFF Xa #FFFF4D Og #FF8133 Av #FF2626