Add custom Train driving animation

Place to get help with not working mods / modding interface.
Cyberpro_
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Aug 14, 2022 1:25 pm
Contact:

Add custom Train driving animation

Post by Cyberpro_ »

So i want to make a mod that contains steam engins with animated siderods. i tried to make the train switch throgh several test animations, but everything i try just prevents the game from loading. i thoght about coding a custmo script that replaces renders an animation on top of the train, but i cant figure out how to get the orientation and speed of a lokomotive. I'm not the best with code so if some more expirienced coders could help me, i'd aprecieate it.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2767
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Add custom Train driving animation

Post by FuryoftheStars »

As far as I’m aware, they don’t support that type of animation:
https://wiki.factorio.com/Prototype/Locomotive
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
Cyberpro_
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Aug 14, 2022 1:25 pm
Contact:

Re: Add custom Train driving animation

Post by Cyberpro_ »

But is there a way to create a script that gets the rotation and speed of the locomotive, and then places a animated image on top of the locomotive?
Xorimuth
Filter Inserter
Filter Inserter
Posts: 722
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Add custom Train driving animation

Post by Xorimuth »

Cyberpro_ wrote: Mon Aug 15, 2022 6:24 am But is there a way to create a script that gets the rotation and speed of the locomotive, and then places a animated image on top of the locomotive?
Yes:
https://lua-api.factorio.com/latest/Lua ... rientation
https://lua-api.factorio.com/latest/Lua ... tity.speed

I'd recommend joining #mod-making on the Factorio Discord for modding help :)
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Cyberpro_
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Aug 14, 2022 1:25 pm
Contact:

Re: Add custom Train driving animation

Post by Cyberpro_ »

i tried making a simple scrip that should print directio but it only returns "unkonwn key 0"

Code: Select all

script.on_event(defines.events.on_tick , function(event) game.print(defines.riding.direction) end)
. Is ther a problem with my code or where is the problem?
robot256
Smart Inserter
Smart Inserter
Posts: 1076
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Add custom Train driving animation

Post by robot256 »

defines.riding.direction is a list of constants. It is not a variable representing any state in the game.

What you want is to read the "game.players[1].riding_state.direction" (if you want player #1) and then use IF-ELSE to see if it is equal to either "defines.riding.direction.left", "defines.riding.direction.straight", or "defines.riding.direction.right". For each case you write a separate game.print statement with the matching direction being printed.
Post Reply

Return to “Modding help”