Hello everyone,
I'm trying to destroy a train and spawn it somewhere else in space, time and even save file.
So far I have run into three problems I have yet to solve:
1. How do I get the direction of locomotives (conveniently)? And how do I set this direction when creating the locomotive entities? A binary direction suffices, since I can do the rest by checking the direction of the station that the train is at.
It seems the 'direction' field of the locomotive entities is always north. To obtain the direction I could do some magic involving the direction of the station or rail, and whether locomotive is a front or rear carriage. This would be a little wacky since I would need to find the station based on the location of the train and the name of the station, as the schedule does not include a reference to the station, only a name. But this does not solve the question on how to spawn the locomotives in different directions, since my tests also show that the 'direction' field has no effect on spawning the locomotive.
2. How do I get the name of the locomotive? The 'name' field is nil, even though the locomotive has the name of a backer. I can get things to work without storing the name, but it would be nice to to also copy the name.
3. Is there a way to access the remaining fuel level of a locomotive? It is possible to get the efficiency bonus percentage, but I did not see where to access the remaining fuel level. Again, this is just a nice-to-have as the player should be able to live with some fuel losses.
Train spawning
Re: Train spawning
tryRednax wrote: 1. How do I get the direction of locomotives (conveniently)? And how do I set this direction when creating the locomotive entities? A binary direction suffices, since I can do the rest by checking the direction of the station that the train is at.
It seems the 'direction' field of the locomotive entities is always north.
Code: Select all
local direction = round(locomotive.orientation * 8)
use locomotive.backer_name2. How do I get the name of the locomotive? The 'name' field is nil, even though the locomotive has the name of a backer. I can get things to work without storing the name, but it would be nice to to also copy the name.
The fuel in the buffer? I don't think that's poosible3. Is there a way to access the remaining fuel level of a locomotive? It is possible to get the efficiency bonus percentage, but I did not see where to access the remaining fuel level. Again, this is just a nice-to-have as the player should be able to live with some fuel losses.
Aaaaaand, since when does creating locos/wagons work? Last time i tried it didn't (might have been 0.12)
Re: Train spawning
Many thanks!
I totally overlooked the orientation and did not consider the backer_name.
The documentation does not mention that orientation is also available for create_entity. Will have to check if that works too.
I totally overlooked the orientation and did not consider the backer_name.
The documentation does not mention that orientation is also available for create_entity. Will have to check if that works too.
- Arch666Angel
- Smart Inserter
- Posts: 1636
- Joined: Sun Oct 18, 2015 11:52 am
- Contact:
Re: Train spawning
If I remember correctly there was a mod which put trains and wagons on track automatically.Choumiko wrote:tryRednax wrote: 1. How do I get the direction of locomotives (conveniently)? And how do I set this direction when creating the locomotive entities? A binary direction suffices, since I can do the rest by checking the direction of the station that the train is at.
It seems the 'direction' field of the locomotive entities is always north.round is an actual rounding function, not math.ceil/floor (ceil/floor might work if you don't care about locomotives on curves)Code: Select all
local direction = round(locomotive.orientation * 8)
use locomotive.backer_name2. How do I get the name of the locomotive? The 'name' field is nil, even though the locomotive has the name of a backer. I can get things to work without storing the name, but it would be nice to to also copy the name.
The fuel in the buffer? I don't think that's poosible3. Is there a way to access the remaining fuel level of a locomotive? It is possible to get the efficiency bonus percentage, but I did not see where to access the remaining fuel level. Again, this is just a nice-to-have as the player should be able to live with some fuel losses.
Aaaaaand, since when does creating locos/wagons work? Last time i tried it didn't (might have been 0.12)
Angels Mods
I. Angel's Mods Subforum
II. Development and Discussion
III. Bugs & FAQ
"should be fixed"
I. Angel's Mods Subforum
II. Development and Discussion
III. Bugs & FAQ
"should be fixed"
Re: Train spawning
The carriages already snap to the rail, even if your location is slightly off, similar to how the placement works for the player. Carriages also auto-connect when placed by a lua script in the same way they do for the player. Not sure what this mod would add to this.Arch666Angel wrote:Choumiko wrote:
If I remember correctly there was a mod which put trains and wagons on track automatically.
- DedlySpyder
- Filter Inserter
- Posts: 253
- Joined: Fri Jun 20, 2014 11:42 am
- Contact:
Re: Train spawning
I don't know if there was another, but I made a mod that could place entities in general, so it could place locos if one wanted to (I originally made it to compliment another mod of mine, but just incorporated it basically)Rednax wrote:The carriages already snap to the rail, even if your location is slightly off, similar to how the placement works for the player. Carriages also auto-connect when placed by a lua script in the same way they do for the player. Not sure what this mod would add to this.Arch666Angel wrote:Choumiko wrote:
If I remember correctly there was a mod which put trains and wagons on track automatically.