Setting dependent character animations

Place to get help with not working mods / modding interface.
jimmy_1283
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Mon Oct 17, 2016 12:55 pm
Contact:

Setting dependent character animations

Post by jimmy_1283 »

So I'm hoping to include a setting in my Power Armor MK3 mod which changes the PAMK4 armor into a mech armor, complete with all the bells an whistles, including the animations (it looks quite silly without them). I've managed to get everything to work except for the appearance/animations.

I'm currently using the following to use Vanilla sprites for my armors. This is done in the Prototype stage.

Code: Select all

for _, animation in ipairs(data.raw["character"]["character"]["animations"]) do
  if animation.armors then
    for _, armor in ipairs(animation.armors) do
      if armor == "power-armor-mk2" then
        animation.armors[#animation.armors + 1] = "pamk3-pamk3"		
        animation.armors[#animation.armors + 1] = "pamk3-pamk4"
        break
      end
       if armor == "light-armor" then
        animation.armors[#animation.armors + 1] = "pamk3-lvest"
        break
      end
      if armor == "heavy-armor" then
        animation.armors[#animation.armors + 1] = "pamk3-hvest"
        break
      end
    end
  end
end
What I want to do is check if both Space Age is enabled and the setting is enabled, then switch over to the Mech Armor sprites, below is my current attempt to do so. I've tried this in both data and Data-updates stage.

Code: Select all

if settings.startup["pam3-ma2"].value and mods["space-age"] then
  local simulations = require("__space-age__.prototypes.factoriopedia-simulations")
  data.raw["armor"]["pamk3-pamk4"].factoriopedia_simulation = simulations.factoriopedia_mech_armor
  data.raw["armor"]["pamk3-pamk4"].provides_flight = true
  data.raw["armor"]["pamk3-pamk4"].takeoff_sound = {filename = "__space-age__/sound/entity/mech-armor/mech-armor-takeoff.ogg", volume = 0.2, aggregation = {max_count = 2, remove = true}}
  data.raw["armor"]["pamk3-pamk4"].landing_sound = {filename = "__space-age__/sound/entity/mech-armor/mech-armor-land.ogg", volume = 0.3, aggregation = {max_count = 2, remove = true, count_already_playing = true}}
  data.raw["armor"]["pamk3-pamk4"].flight_sound = {sound={filename = "__space-age__/sound/entity/mech-armor/mech-armor-flight.ogg", volume = 0.2}}
  for _, animation in ipairs(data.raw["character"]["character"]["animations"]) do
  if animation.armors then
    for _, armor in ipairs(animation.armors) do
      if armor == "mech-armor" then
        animation.armors[#animation.armors + 1] = "pamk3-pamk4"
        break
    end
  end
end
end
end
It obviously doesn't work, the animations at least, and with my mediocre coding talents I'm stuck. If anyone could provide some help, or even a solution, I'd be grateful.

Thanks in advance to any help given.
Muche
Smart Inserter
Smart Inserter
Posts: 1006
Joined: Fri Jun 02, 2017 6:20 pm
Contact:

Re: Setting dependent character animations

Post by Muche »

Maybe the issue is that character.animations now has two references to pamk3-pamk4 - one next to power-armor-mk2, and one next to mech-armor?
jimmy_1283
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Mon Oct 17, 2016 12:55 pm
Contact:

Re: Setting dependent character animations

Post by jimmy_1283 »

I'm honestly not sure how that works, I had assumed it would overwrite, but when that didn't work I separated MK4 into it's own loop, where it was referenced only once. The MK2 armor sprites worked as intended, but when I switched the option to true, it appeared as if there were no armor at all. I had assumed that the mech armor was on the same array, but using the same command, even on updates or final didn't work.
jimmy_1283
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Mon Oct 17, 2016 12:55 pm
Contact:

Re: Setting dependent character animations

Post by jimmy_1283 »

I ended up getting it to work, in a hacky sort of way.

Code: Select all

if settings.startup["pam3-ma2"].value and mods["space-age"] then
  local simulations = require("__space-age__.prototypes.factoriopedia-simulations")
  data.raw["armor"]["pamk3-pamk4"].factoriopedia_simulation = simulations.factoriopedia_mech_armor
  data.raw["armor"]["pamk3-pamk4"].provides_flight = true
  data.raw["armor"]["pamk3-pamk4"].takeoff_sound = {filename = "__space-age__/sound/entity/mech-armor/mech-armor-takeoff.ogg", volume = 0.2, aggregation = {max_count = 2, remove = true}}
  data.raw["armor"]["pamk3-pamk4"].landing_sound = {filename = "__space-age__/sound/entity/mech-armor/mech-armor-land.ogg", volume = 0.3, aggregation = {max_count = 2, remove = true, count_already_playing = true}}
  data.raw["armor"]["pamk3-pamk4"].flight_sound = {sound={filename = "__space-age__/sound/entity/mech-armor/mech-armor-flight.ogg", volume = 0.2}}
  for _, animation in ipairs(data.raw["character"]["character"]["animations"]) do
  if animation.armors then
    for _, armor in ipairs(animation.armors) do
      if armor == "mech-armor" then
        animation.armors[#animation.armors + 1] = "pamk3-pamk4"
        break
    end
  end
end
end
else
  for _, animation in ipairs(data.raw["character"]["character"]["animations"]) do
  if animation.armors then
    for _, armor in ipairs(animation.armors) do
      if armor == "power-armor-mk2" then
        animation.armors[#animation.armors + 1] = "pamk3-pamk4"
        break
    end
  end
end
end
end
Not ideal, but I literally couldn't get it to work any other way, unfortunately. My biggest concern is the second line, does anyone know for sure if that is likely to cause issues?
Post Reply

Return to “Modding help”