LuaControl / LuaEntity should expose more player actions

Madsy
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Jul 05, 2016 3:10 pm
Contact:

LuaControl / LuaEntity should expose more player actions

Post 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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14913
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaControl / LuaEntity should expose more player actions

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Madsy
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Jul 05, 2016 3:10 pm
Contact:

Re: LuaControl / LuaEntity should expose more player actions

Post by Madsy »

Wow, talk about a quick reply. Thank you so much :)
Rseding91
Factorio Staff
Factorio Staff
Posts: 14913
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaControl / LuaEntity should expose more player actions

Post by Rseding91 »

Added the other things for 0.15.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Implemented mod requests”