[MOD 0.17] VehicleSnap

Topics and discussion about specific mods
Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Rseding91 »

Zaflis wrote:Current start of the script is now:

Code: Select all

global.lastorientation = {}
global.player_ticks = {}
global.tick = 2

script.on_configuration_changed(function(data)
  if data.mod_changes == nil then return end
  if global.lastorientation == nil then global.lastorientation = {} end
  if global.player_ticks == nil then global.player_ticks = {} end
  if global.tick == nil then global.tick = 2 end
end)
Unless you convince me to put first 3 lines inside on_init, i'd consider it solved :) It worked in all test cases i could think of, but obviously i cannot test multiplayer sync.

Also the mod is using the game.players directly. Say your player index is 4 and you're driving a car. If player index 3 leaves the game, you will now be index 3, no? If that happens you might see your snap variable reset.
That's fine to put them there. The game overwrites the global values on load so it's save/load safe.

It wouldn't hurt to put them in on_init but it doesn't hurt to have them here either.
If you want to get ahold of me I'm almost always on Discord.

Arumba
Long Handed Inserter
Long Handed Inserter
Posts: 62
Joined: Sat Aug 29, 2015 6:46 pm
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Arumba »

So for the next MP session we do, should we leave it disabled, manually modify and share a version of it based on the previous comments, or is it going to be updated on the portal? I'm more than willing to provide a solid MP testing ground for it. I can get ~50+ players in a game very quickly if it needs to be stress tested or something.

Zaflis
Filter Inserter
Filter Inserter
Posts: 414
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Zaflis »

Would you test with the version i uploaded in previous page? download/file.php?id=19401
If that makes a difference i'll upload it to mod portal.

No, you don't need to disable it. The recent 1.14.21 version seemed to fix all the errors even related to mod updating.

Arumba
Long Handed Inserter
Long Handed Inserter
Posts: 62
Joined: Sat Aug 29, 2015 6:46 pm
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Arumba »

Zaflis wrote:Would you test with the version i uploaded in previous page? download/file.php?id=19401
If that makes a difference i'll upload it to mod portal.

No, you don't need to disable it. The recent 1.14.21 version seemed to fix all the errors even related to mod updating.
Okay, will try it with MASA session and then later tonight with the large scale MP session we've been running this week. Thanks! Will report back if it breaks the whole world.

*Edit*

We recorded ~3 hours today without any issues. Then again we had no issues in our previous session, but still, things look good on this end.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Nexela »

Zaflis wrote:Current start of the script is now:
Also the mod is using the game.players directly. Say your player index is 4 and you're driving a car. If player index 3 leaves the game, you will now be index 3, no? If that happens you might see your snap variable reset.
The player index will stay the same

Zaflis
Filter Inserter
Filter Inserter
Posts: 414
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Zaflis »

Good to know. I'll upload it to portal.

MainTango
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Tue Oct 27, 2015 12:22 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by MainTango »

This mod is absolutely blissful. I have a request but I don't know if it's possible or not. Would you consider adding a hotkey to toggle the mod's functionality on/off during gameplay?

Zaflis
Filter Inserter
Filter Inserter
Posts: 414
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Zaflis »

It seems possible: viewtopic.php?f=25&t=30644

Any key suggestions? It might be that to change keys one would have to open the zip file and edit a file. Shift-V is 1 option that comes to mind.

Also since it's multiplayer compatible mod, i'd have to globally sync the snapping state per player and finding which one is the local self. I just hope it would be simple...

MainTango
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Tue Oct 27, 2015 12:22 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by MainTango »

Zaflis wrote:It seems possible: viewtopic.php?f=25&t=30644

Any key suggestions? It might be that to change keys one would have to open the zip file and edit a file. Shift-V is 1 option that comes to mind.

Also since it's multiplayer compatible mod, i'd have to globally sync the snapping state per player and finding which one is the local self. I just hope it would be simple...
I wish I could be of assistance with the multiplayer thing but I'm just garbage with these things.
As far as key suggestions, shift+V sounds good. You could even do shift+W if you ask me. No idea whether other mods already use that.
Users can remap it should there be any conflicts. The control settings menu even has a Mods tab nowadays :D

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [MOD 0.14] VehicleSnap

Post by Nexela »

control.lua
Last edited by Nexela on Tue May 02, 2017 10:49 am, edited 4 times in total.

Zaflis
Filter Inserter
Filter Inserter
Posts: 414
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: [MOD 0.15] VehicleSnap

Post by Zaflis »

That's really nice code. You changed so much though that i don't know for sure if things still work or not. I had checks to ensure that mod works even in the case that it's added after the world was created, or if mod was updated.

Code: Select all

if pdata.player_ticks > 1 then
That's first reference to player_ticks. Is it safe to compare it to number if it doesn't exist yet? I used to have some crashes in my testing with similar code. I may not have time to test today.

Zaflis
Filter Inserter
Filter Inserter
Posts: 414
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: [MOD 0.15] VehicleSnap

Post by Zaflis »

I knew it, they need to be initialized somewhere

Code: Select all

Error while running event VehicleSnap::on_tick (ID 0)
__VehicleSnap__/control.lua:46: attempt to perform arithmetic on field 'lastorientation' (a nil value)
I also need to add data.lua

Code: Select all

data:extend({
  {
    type = "custom-input",
    name = "VehicleSnap-toggle",
    key_sequence = "SHIFT + V",
    consuming = "script-only"
  }
})
and related locale for controls menu. Will see how goes...

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [MOD 0.15] VehicleSnap

Post by Nexela »

Zaflis wrote:That's really nice code. You changed so much though that i don't know for sure if things still work or not. I had checks to ensure that mod works even in the case that it's added after the world was created, or if mod was updated.

Code: Select all

if pdata.player_ticks > 1 then
That's first reference to player_ticks. Is it safe to compare it to number if it doesn't exist yet? I used to have some crashes in my testing with similar code. I may not have time to test today.
Oooops good catch, fixed above

Looks like I forgot the on_init, The above code is fixed and should handle everything correctly.

All of it is untested though, I will leave that up to you. :)

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [MOD 0.15] VehicleSnap

Post by Nexela »

Just noticed some spots say lastorientation and others say last_orientation fixing above so they are consistent :)

Zaflis
Filter Inserter
Filter Inserter
Posts: 414
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: [MOD 0.15] VehicleSnap

Post by Zaflis »

Yeah i noticed those earlier too, also i needed to use the snap variable in player loop for toggle functionality. I got everything working as far as i can tell, so 1.15.1 is released. I only tested in singleplayer and private multiplayer without others. The mod toggle key can be changed from Factorio's controls menu. And thanks for helps :)

MainTango
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Tue Oct 27, 2015 12:22 am
Contact:

Re: [MOD 0.15] VehicleSnap

Post by MainTango »

Hotkey works like a charm for me. Thanks a lot for implementing it :D

widders
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat May 13, 2017 11:11 pm
Contact:

Re: [MOD 0.15] VehicleSnap

Post by widders »

Hey, love the mod although it still can't make up for my inept driving.

One thing I noticed in 0.15.28-30 at least it doesn't work when driving backwards. I don't know if that was intentional but it's a bit annoying sometimes.

widders
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat May 13, 2017 11:11 pm
Contact:

Re: [MOD 0.15] VehicleSnap

Post by widders »

I thought I'd have a look and I found the problem. Line 51 of control.lua:

Code: Select all

if player.vehicle.speed > 0.1 then
needs a math.abs(player.vehicle.speed) to cover backwards as well, I tried it seems to work fine :p

Zaflis
Filter Inserter
Filter Inserter
Posts: 414
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: [MOD 0.15] VehicleSnap

Post by Zaflis »

It was a little delicate subject, in the end i thought reverse is so slow and rarely used that it wouldn't benefit much of snapping. Did you test if tanks reach reverse speed of -0.1? If the number is put too low, one old bug would resurface... That was a tricky one too, that vehicle gets stuck on anything solid such as structures or shoreline. That's why i had to not snap in low speeds.

sarcolopter
Long Handed Inserter
Long Handed Inserter
Posts: 56
Joined: Sun Jul 26, 2015 5:08 pm
Contact:

Re: [MOD 0.15] VehicleSnap

Post by sarcolopter »

just updated, looks like that broke it

Post Reply

Return to “Mods”