Page 1 of 1
Is there a way to activate a console commad in lua script?
Posted: Sat Oct 06, 2018 2:58 pm
by DDDGamer
The game has a bunch of cammand available like:
https://wiki.factorio.com/Console#Multiplayer_commands
What i am asking is if you can activate one from within a script like:
Code: Select all
-- Pseudocode
game.activate_command("/admins")
game.activate_command("/mute player_name")
game.activate_command("/promote player_name")
game.activate_command("/o player_name")
-- etc...
Re: Is there a way to activate a console commad in lua script?
Posted: Sat Oct 06, 2018 5:34 pm
by quyxkh
Headless servers read from their standard input, so start the server with e.g. `mymodreader | factorio --start-server-load-latest` where your mod reader watches a file in .factorio/script-output, then your mod can write to that file and that cycle is complete.
Re: Is there a way to activate a console commad in lua script?
Posted: Sat Oct 06, 2018 5:50 pm
by DaveMcW
There is a game.do_stuff() command for most of them. No need for complicated console callbacks.
https://lua-api.factorio.com/latest/Lua ... ick_player
If you can't find a matching API command, you should post in Modding Interface Requests.
Re: Is there a way to activate a console commad in lua script?
Posted: Sun Oct 07, 2018 3:12 am
by DDDGamer
I dont think neither of those options work in my case. (Might have to request an api call)
I'll be more specific:
If you type in /kick playername
that does correspond with the kick command in the API as you linked
https://lua-api.factorio.com/latest/Lua ... ick_player
however if you type in /o player_name or /open player_name
this opens up a pre made window that show players inventory
There is the get_main_inventory or get_inventory commands, but they return data, not open up a gui window like the /open command
https://lua-api.factorio.com/latest/Lua ... _inventory
Code: Select all
/c game.print(serpent.block(game.players[1].get_main_inventory().get_contents()))
returns a list of items in the main inventory for example
So I guess my question is could i call that pre-made gui windows somehow, or do i need to either recreate it or ask for an api hook?
Re: Is there a way to activate a console commad in lua script?
Posted: Sun Oct 07, 2018 8:49 am
by eradicator
DDDGamer wrote: Sat Oct 06, 2018 2:58 pm
Is there a way to activate a console commad in lua script?
No, there isn't. You have to manually implement the behavior via the API. Not sure if it's possible for all commands. /open works like this:
Code: Select all
game.players['player1-name'].opened = game.players['player2-name']
Re: Is there a way to activate a console commad in lua script?
Posted: Sun Oct 07, 2018 2:34 pm
by DDDGamer
Thanks eradicator that works perfectly!