[0.18.34] Creating a player/character from RCON

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
Post Reply
franck
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Jul 05, 2020 3:56 pm
Contact:

[0.18.34] Creating a player/character from RCON

Post by franck »

Hello,

Is there a way to create a player/character from RCON using the LUA API? This would allow creating scripts that could behave like players, in order to simulate games (TAS)

Cheers,

franck
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Jul 05, 2020 3:56 pm
Contact:

Re: [0.18.34] Creating a player/character from LUA

Post by franck »

Small update, I was looking at https://github.com/yournamehere/factori ... ol.lua#L33 and playing with it. It uses entity name "player" which does not seem to exist anymore (as per. https://wiki.factorio.com/Data.raw). "character" does exist though and is close enough to what I need, but then I tried to move it and setting walking state does not move the entity, it just starts the animation. So it looks like creating a character just creates a static entity, is that incorrect? Anyone knows how to work around this?

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [0.18.34] Creating a player/character from LUA

Post by Pi-C »

franck wrote:
Wed Jul 08, 2020 10:18 pm
Small update, I was looking at https://github.com/yournamehere/factori ... ol.lua#L33 and playing with it. It uses entity name "player" which does not seem to exist anymore (as per. https://wiki.factorio.com/Data.raw). "character" does exist though and is close enough to what I need, but then I tried to move it and setting walking state does not move the entity, it just starts the animation. So it looks like creating a character just creates a static entity, is that incorrect? Anyone knows how to work around this?
"Player" and "character" are different concepts: player is a person sitting somewhere at a computer and controlling the little guy, which is an entity based on the character prototype. Although a lot is possible in Factorio, it doesn't allow prototyping players yet, therefore data.raw doesn't contain "player". :-D

If you want to control a character in game, you have to treat it like any other entity. Of course, you can "connect" a character entity to a player with player.associate_character(character_entity), and you can check if a certain character entity is connected to a player with character.player.

Hope that helps a bit. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.18.34] Creating a player/character from LUA

Post by eradicator »

franck wrote:
Wed Jul 08, 2020 10:18 pm
"character" does exist though and is close enough to what I need,
It's not just close enough, it's exactly the same. Was renamed a while back:
Changelog wrote: Version: 0.17.35
Date: 02. 05. 2019
Modding:
- Renamed the character entity type and name from "player" to "character" to make it consistent with how we call/access it in all other places.
Are you setting walking state every tick? Setting it for just one tick won't work.
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.

franck
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Jul 05, 2020 3:56 pm
Contact:

Re: [0.18.34] Creating a player/character from RCON

Post by franck »

Hey, so I figured out what was wrong! Indeed character is exactly what I need but while testing I accidentally created two characters at same position on the surface. That seems to box the characters in, which means that if I tried to set the walking state, it would animate but not change position.

This can be tested easily with own player:

Code: Select all

game.surfaces[1].create_entity({name = "character", position = {game.player.position.x, game.player.position.y}, force = game.forces.player})
This will create another character at the player's position, then moving (using normal wasd keys) seems impossible on my computer at least :)

Also I've seen mention of setting the walking state at each tick (and tas do that indeed), but for some reason that does not seem necessary for characters created using LUA, could be mistaken though because I just did a quick test. This should be possible to reproduce also by using something like:

Code: Select all

game.surfaces[1].create_entity({name = "character", position = {game.player.position.x + 5, game.player.position.y}, force = game.forces.player})
local characters = game.players[1].surface.find_entities_filtered({name = "character"})
characters[2].walking_state = {walking = true, direction = defines.direction.north}
From my quick test the character just keeps going; maybe worth checking? (This is all in 0.18.35)

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.18.34] Creating a player/character from RCON

Post by eradicator »

franck wrote:
Thu Jul 09, 2020 6:33 pm
then moving (using normal wasd keys) seems impossible on my computer at least :)
Yea, because you're colliding on all sides. You can't walk through buildings either.
franck wrote:
Thu Jul 09, 2020 6:33 pm
but for some reason that does not seem necessary for characters created using LUA
Non-player controlled characters indeed seem to continue moving. That's unrelated to "being created by lua".

Code: Select all

/c game.player.character.walking_state = {walking = true, direction = defines.direction.north} game.player.character=nil
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.

Post Reply

Return to “Technical Help”