Emulation of a Player

Place to get help with not working mods / modding interface.
dfghjzx
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Dec 30, 2019 6:07 pm
Contact:

Emulation of a Player

Post by dfghjzx »

I have been unable to find a way to successfully emulate player input on a tick by tick basis, I was hoping to make a more accurate version of tas tools but haven't found any way to do so. Is this a possibility to do or have I just been looking for something that isn't possible.
Bilka
Factorio Staff
Factorio Staff
Posts: 3464
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Emulation of a Player

Post by Bilka »

https://github.com/gotyoke/Factorio-AnyPct-TAS

https://github.com/Bilka2/factorio-tas-playback

Both somewhat outdated and my fork definitely isn't feature complete. Good luck.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
dfghjzx
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Dec 30, 2019 6:07 pm
Contact:

Re: Emulation of a Player

Post by dfghjzx »

I'm still trying to figure out how you got movement to work :D
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Emulation of a Player

Post by eradicator »

Bilka wrote: Mon Dec 30, 2019 6:39 pm https://github.com/gotyoke/Factorio-AnyPct-TAS

https://github.com/Bilka2/factorio-tas-playback

Both somewhat outdated and my fork definitely isn't feature complete. Good luck.
Did you ever test that in Multiplayer? I guess for speedruns that's not a relevant criteria?
Just wondering if walking_state actually is meaningfully usable outside of a 0-ms-ping context now.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Bilka
Factorio Staff
Factorio Staff
Posts: 3464
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Emulation of a Player

Post by Bilka »

eradicator wrote: Thu Jan 02, 2020 3:11 pm
Did you ever test that in Multiplayer? I guess for speedruns that's not a relevant criteria?
Just wondering if walking_state actually is meaningfully usable outside of a 0-ms-ping context now.
My fork works in multiplayer if the runner is the host. That means you could host the tas and have spectators. It doesn't work for joining players, because the latency/multiplayer logic can randomly delay actions a few ticks (usually when latency changes), most meaningful of those actions are crafting, mining and walking. Since the mod just does "x task at y tick", just a 1 tick delay in for example mining means that the mining isn't finished and everything goes wrong. A true multiplayer version would have to be more dynamic and work with events etc. However, there is another flaw to multiplayer: players joining messes with the rng, so the rng "manipulation" used for mining coal rocks doesn't work. For that reason, I never looked into making the mod dynamic.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Emulation of a Player

Post by eradicator »

Bilka wrote: Thu Jan 02, 2020 4:03 pm My fork works in multiplayer if the runner is the host. [...] It doesn't work for joining players
Ah yes, that would be exactly the experience i had :(. Thanks for confirming. Wish i could just issue a unit-style move command to the player.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Emulation of a Player

Post by Klonan »

eradicator wrote: Fri Jan 03, 2020 4:07 am Wish i could just issue a unit-style move command to the player.

Merry Christmas:
character_interface.zip
(18.91 KiB) Downloaded 78 times
I made this script a few months ago for an experiment I was working on, its probably still rough around the edges.

I also made this tiny scenario to demonstrate it, (not sure if it still works):
Interface_Example.zip
(333.84 KiB) Downloaded 79 times
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Emulation of a Player

Post by eradicator »

Klonan wrote: Fri Jan 03, 2020 12:07 pm
eradicator wrote: Fri Jan 03, 2020 4:07 am Wish i could just issue a unit-style move command to the player.
I made this script a few months ago for an experiment I was working on, its probably still rough around the edges.
Can't currently test that. But if it's just an on_tick manipulation of walking_state wouldn't it still look shitty to the player who's "being walked" when lag-hiding does it's thing in a laggy mp game?

Edit: Original post here viewtopic.php?t=58090
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Emulation of a Player

Post by Klonan »

eradicator wrote: Fri Jan 03, 2020 12:40 pm
Klonan wrote: Fri Jan 03, 2020 12:07 pm
eradicator wrote: Fri Jan 03, 2020 4:07 am Wish i could just issue a unit-style move command to the player.
I made this script a few months ago for an experiment I was working on, its probably still rough around the edges.
Can't currently test that. But if it's just an on_tick manipulation of walking_state wouldn't it still look shitty to the player who's "being walked" when lag-hiding does it's thing in a laggy mp game?

Edit: Original post here viewtopic.php?t=58090
I don't see why it would look shitty, the script will execute on_tick for the client, and latency hiding won't have any effect unless you start pressing the movement keys

Ping would only have an effect if some command was being sent from the server each tick, but this is all controlled inside the Lua script of the game, so MP or not won't make a difference
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Emulation of a Player

Post by eradicator »

Klonan wrote: Fri Jan 03, 2020 1:41 pm Ping would only have an effect if some command was being sent from the server each tick, but this is all controlled inside the Lua script of the game, so MP or not won't make a difference
That was also my expectation when i first tried this 2 years ago, but at the time (possibly to lacking experience) i found no way to make it work properly in mp. And it'll be a few weeks until i can test this.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Bilka
Factorio Staff
Factorio Staff
Posts: 3464
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Emulation of a Player

Post by Bilka »

Klonan wrote: Fri Jan 03, 2020 1:41 pm I don't see why it would look shitty, the script will execute on_tick for the client, and latency hiding won't have any effect unless you start pressing the movement keys

Ping would only have an effect if some command was being sent from the server each tick, but this is all controlled inside the Lua script of the game, so MP or not won't make a difference
Did you read my post?
Bilka wrote:It doesn't work for joining players, because the latency/multiplayer logic can randomly delay actions a few ticks (usually when latency changes), most meaningful of those actions are crafting, mining and walking.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Emulation of a Player

Post by Klonan »

Bilka wrote: Fri Jan 03, 2020 8:05 pm
Klonan wrote: Fri Jan 03, 2020 1:41 pm I don't see why it would look shitty, the script will execute on_tick for the client, and latency hiding won't have any effect unless you start pressing the movement keys

Ping would only have an effect if some command was being sent from the server each tick, but this is all controlled inside the Lua script of the game, so MP or not won't make a difference
Did you read my post?
Bilka wrote:It doesn't work for joining players, because the latency/multiplayer logic can randomly delay actions a few ticks (usually when latency changes), most meaningful of those actions are crafting, mining and walking.
Thats not how the Lua scripting works, the Lua script isn't ever delayed, it always executes on every tick for every client and server

EDIT: So I tested it out, the jumpiness comes from the latency hiding predicting where the player will be based on the current movement at the current tick (As opposed to player input as I thought it would use for its prediction). So if the script is going to turn the guy around in 1 tick, the latency character position will be incorrect


The solution is to disable the latency hiding, which I see from this old post you have mentioned before eradicator:
viewtopic.php?t=63525
Attachments
2020-01-03_21-45-15.mp4
(8.45 MiB) Downloaded 92 times
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Emulation of a Player

Post by eradicator »

Klonan wrote: Fri Jan 03, 2020 8:11 pm The solution is to disable the latency hiding, which I see from this old post you have mentioned before eradicator:
viewtopic.php?t=63525
By setting shooting state? Certainly never thought of using it like that. Albeit that has the drawback of applying the weapons movement penalty.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Bilka
Factorio Staff
Factorio Staff
Posts: 3464
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Emulation of a Player

Post by Bilka »

Klonan wrote: Fri Jan 03, 2020 8:11 pm Thats not how the Lua scripting works, the Lua script isn't ever delayed, it always executes on every tick for every client and server
That is how lua scripting works. Here is a demonstration. On the left is the host, on the right the joining player. The joining player is commanded to craft pipes by script, and the finishing ticks of the crafts are printed into chat. You can see that the crafting takes 2 ticks longer to complete than it should (see chat history) due to a latency change.


I used crafting as the example because it is extremely easy to demonstrate the issue with it, however mining and walking (and some other stuff) exhibit the same behaviour. Here is the command in case you want to try it yourself:

Code: Select all

/c local player = game.players[2]; global.tick = game.tick; player.insert{name = "iron-plate", count = 8}; player.begin_crafting{count=8,recipe="pipe"}; script.on_event(defines.events.on_player_crafted_item, function(e) game.print(e.tick - global.tick) end)
To sum up: Latency changes can and will delay actions such as walking, crafting and mining. This is done by the multiplayer logic and happens regardless of whether Lua triggers the actions or not.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Post Reply

Return to “Modding help”