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,
[0.18.34] Creating a player/character from RCON
Re: [0.18.34] Creating a player/character from LUA
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
"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".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?

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!
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [0.18.34] Creating a player/character from LUA
It's not just close enough, it's exactly the same. Was renamed a while back:franck wrote: Wed Jul 08, 2020 10:18 pm "character" does exist though and is close enough to what I need,
Are you setting walking state every tick? Setting it for just one tick won't work.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.
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: [0.18.34] Creating a player/character from RCON
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:
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:
From my quick test the character just keeps going; maybe worth checking? (This is all in 0.18.35)
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})

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}
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [0.18.34] Creating a player/character from RCON
Yea, because you're colliding on all sides. You can't walk through buildings either.franck wrote: Thu Jul 09, 2020 6:33 pm then moving (using normal wasd keys) seems impossible on my computer at least :)
Non-player controlled characters indeed seem to continue moving. That's unrelated to "being created by lua".franck wrote: Thu Jul 09, 2020 6:33 pm but for some reason that does not seem necessary for characters created using 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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.