Page 1 of 1
Add custom Train driving animation
Posted: Sun Aug 14, 2022 1:48 pm
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.
Re: Add custom Train driving animation
Posted: Mon Aug 15, 2022 12:45 am
by FuryoftheStars
As far as I’m aware, they don’t support that type of animation:
https://wiki.factorio.com/Prototype/Locomotive
Re: Add custom Train driving animation
Posted: Mon Aug 15, 2022 6:24 am
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?
Re: Add custom Train driving animation
Posted: Mon Aug 15, 2022 6:31 am
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

Re: Add custom Train driving animation
Posted: Mon Aug 15, 2022 6:51 am
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?
Re: Add custom Train driving animation
Posted: Mon Aug 15, 2022 2:57 pm
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.