Gizmos Car Keys (improved)

by Pi-C

Tired of running to your vehicle? Then let it come to you! This mod is based on "Gizmos Car Keys" by aodgizmo. It works with most modded car and spider-vehicle prototypes -- not just vanilla cars.

Content
2 months ago
0.17 - 1.1
12.6K
Transportation

i [Implemented] Match character direction when placed

4 months ago
(updated 4 months ago)

I don´t know if this is possible, but I would like following:

Looks like now the car keeps the direction from last position - much better will be to rotate it to the same direction as characer, when placed with keys.
I often "call" the car on a narrow path and then I must rotate the car while driving and it takes quite space for it.

A have managed it by adding

if not owner.driving then
  vehicle.orientation = owner.character.orientation
end

but I consider it unsafe, because there is no check if the rotation cause collision with another entity :/
I did not find any similar methods like teleport to rotate the car and the teleport method does not support setting the orientation

4 months ago
(updated 4 months ago)

Thanks for the suggestion! What do you think, should I make that a per-player setting? Another idea would be to check whether ALT, CONTROL, or SHIFT was pressed while summoning the vehicle.

A have managed it by adding

if not owner.driving then
  vehicle.orientation = owner.character.orientation
end

but I consider it unsafe, because there is no check if the rotation cause collision with another entity :/

EDIT: This is not as simple as I originally thought. I use LuaSurface::can_place_entity() to check whether the vehicle fits at the target position. However, there currently is no way to add orientation to the arguments. While can_place_entity() has an optional argument direction, car prototypes do not support direction at all.

I've bumped a modding interface request for adding orientation to LuaSurface::can_place_entity(). If that gets implemented, I could easily add the feature.

4 months ago

Thanks for the suggestion! What do you think, should I make that a per-player setting? Another idea would be to check whether ALT, CONTROL, or SHIFT was pressed while summoning the vehicle.

I think mix of both
- without CRTL = no rotation, with CTRL = rotation
- per-player setting to revert the logic

EDIT: This is not as simple as I originally thought. I use LuaSurface::can_place_entity() to check whether the vehicle fits at the target position. However, there currently is no way to add orientation to the arguments. While can_place_entity() has an optional argument direction, car prototypes do not support direction at all.

I've bumped a modding interface request for adding orientation to LuaSurface::can_place_entity(). If that gets implemented, I could easily add the feature.

I came to same conclusion, so for now I will use my patch, keeping in my mind to summon the car in safe distance of any entity. Maybe for car shaped nearly to square is this not so big issue, as for vehicles with bigger difference length vs width.

Btw I have tried to position the car to the "wrong" position with no success. Do you know what will happen in this case (game crash / destruction of car or other entity) ?

4 months ago

Thanks for the suggestion! What do you think, should I make that a per-player setting? Another idea would be to check whether ALT, CONTROL, or SHIFT was pressed while summoning the vehicle.

I think mix of both
- without CRTL = no rotation, with CTRL = rotation
- per-player setting to revert the logic

What I meant was using the setting to enable/disable the rotation completely, and to check for pressed keys only if rotation is enabled.

EDIT: This is not as simple as I originally thought. I use LuaSurface::can_place_entity() to check whether the vehicle fits at the target position. However, there currently is no way to add orientation to the arguments. While can_place_entity() has an optional argument direction, car prototypes do not support direction at all.

I came to same conclusion, so for now I will use my patch, keeping in my mind to summon the car in safe distance of any entity. Maybe for car shaped nearly to square is this not so big issue, as for vehicles with bigger difference length vs width.

There may be another way: Use LuaSurface::can_place_entity() first. If we find a non-colliding position, check LuaSurface:find_entities_filtered(), passing on area (which contains the top-left and bottom-right coordinates of a bounding box and, since Factorio 1.1.85, optionally orientation of the box). I'm already using find_entities_filtered in Autodrive for determining whether a vehicle was crashing at the front or back. It's easier there because I know the other entity I'm looking for. Here, I still have to figure out what other filters to use. I guess this may work, but of course it would be more efficient if we could use orientation with can_place_entity.

Btw I have tried to position the car to the "wrong" position with no success. Do you know what will happen in this case (game crash / destruction of car or other entity) ?

I managed to place the car at a bad position! There was a combinator. My character was standing northwest of it, facing westwards. I then tried to summon a car directly to the right of the combinator, getting the message that there was no space. I then moved the cursor slightly right until the car could be summoned -- and it was overlapping the combinator a bit. As soon as I started to drive the car, the combinator would be damaged; but nothing bad would happen to combinator or car if the car was summoned to another position. However, the game won't complain about it, so the worst that can happen is that you'd damage another entity.

3 months ago
(updated 3 months ago)

Another idea would be to check whether ALT, CONTROL, or SHIFT was pressed while summoning the vehicle.

I think mix of both
- without CRTL = no rotation, with CTRL = rotation
- per-player setting to revert the logic

Made another mistake, keypresses are registered for GUI clicks, not selection tools! But I've found a way:

  1. By default, using the keys in normal mode will summon the vehicle without rotating it.
  2. Using alt_select (holding SHIFT while clicking) will summon the vehicle and use
  • player.orientation (if the player has a valid character and is not in a vehicle),
  • player.vehicle.orientation (if the player is inside another vehicle supported by GCKI), or
  • vehicle.orientation as fallback if none of the above applies.

This already seems to work, now I'm adding the per-player setting to toggle the meaning of normal and alternative selection.

3 months ago

Please try version 1.1.11!

New response