Page 1 of 1
[0.18.34] Creating a player/character from RCON
Posted: Sun Jul 05, 2020 6:09 pm
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,
Re: [0.18.34] Creating a player/character from LUA
Posted: Wed Jul 08, 2020 10:18 pm
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?
Re: [0.18.34] Creating a player/character from LUA
Posted: Thu Jul 09, 2020 12:01 pm
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".
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.

Re: [0.18.34] Creating a player/character from LUA
Posted: Thu Jul 09, 2020 1:18 pm
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.
Re: [0.18.34] Creating a player/character from RCON
Posted: Thu Jul 09, 2020 6:33 pm
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)
Re: [0.18.34] Creating a player/character from RCON
Posted: Thu Jul 09, 2020 7:53 pm
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