Page 1 of 1

LuaControl / LuaEntity should expose more player actions

Posted: Sun Mar 12, 2017 12:59 am
by Madsy
I want to create a player AI mod where the AI opponent make their own bases, defenses and do mining. However, while you can create 'zombie' character entities with no associated LuaPlayer, a lot of reasonable character actions are not exposed in the LuaControl interface.

Example:

Code: Select all

BOT = game.surfaces[1].create_entity{name = "player", position = {0, 0}, force=game.forces.enemy }
function bot_mine(x,y)
        BOTt.teleport(x, y-1)
	script.on_event(defines.events.on_tick, function(event) BOT.mining_state = {mining = true, position = {x, y}} end)
end
The mining state is only modified for a single tick, hence I tested it in the on_tick callback. While this works for character entities with a connected player, this has no effect on 'zombie' character entities.
However, LuaControl.walking_state *does* work. With walking set to true, and with a direction defined, the 'zombie' character does walk in the specified direction.

So my request is:
  • It would be nice if LuaControl.mining_state, and all the other xxx_states worked for the player prototype where the character entity is not associated with a connected client.
  • Implement a firing_state: LuaControl.firing_state = {firing = true, position = {x,y}} where position would be where the conceptual cursor is. A direction wouldn't work, because the radius is important when using capsules and grenades.
  • Implement functions in LuaControl which lets the entity pick up and drop items.
For all of these features, there are workarounds. For instance, one could manually decrease the ore count on a patch and then manually insert an ore item in the entity's inventory. But it's pretty hacky and you don't get the mining animation.
Similar workarounds would work for firing weapons (spawn projectiles or use invisible turrets) and pick up / drop items, but with the same shortcomings.

Re: LuaControl / LuaEntity should expose more player actions

Posted: Sun Mar 12, 2017 1:09 am
by Rseding91
You misunderstand how the API works.

It's not persisting the mining state because you haven't set the selected entity for the player so it updates and sees "the player is no longer selecting the thing he was mining, stop mining".

You need to use: http://lua-api.factorio.com/latest/LuaC ... ted_entity to set the thing being mined.

Mining state does work on a standalone player. "firing_state" and "shooting_state" aren't exposed to the API - I'll add those for 0.15.

Re: LuaControl / LuaEntity should expose more player actions

Posted: Sun Mar 12, 2017 1:14 am
by Madsy
Wow, talk about a quick reply. Thank you so much :)

Re: LuaControl / LuaEntity should expose more player actions

Posted: Sun Mar 12, 2017 2:20 am
by Rseding91
Added the other things for 0.15.