Is there a way to activate a console commad in lua script?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
DDDGamer
Inserter
Inserter
Posts: 30
Joined: Mon Oct 17, 2016 2:16 pm
Contact:

Is there a way to activate a console commad in lua script?

Post by DDDGamer » Sat Oct 06, 2018 2:58 pm

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...

quyxkh
Filter Inserter
Filter Inserter
Posts: 787
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Is there a way to activate a console commad in lua script?

Post by quyxkh » Sat Oct 06, 2018 5:34 pm

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.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3014
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Is there a way to activate a console commad in lua script?

Post by DaveMcW » Sat Oct 06, 2018 5:50 pm

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.

User avatar
DDDGamer
Inserter
Inserter
Posts: 30
Joined: Mon Oct 17, 2016 2:16 pm
Contact:

Re: Is there a way to activate a console commad in lua script?

Post by DDDGamer » Sun Oct 07, 2018 3:12 am

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?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3772
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Is there a way to activate a console commad in lua script?

Post by eradicator » Sun Oct 07, 2018 8:49 am

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']
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.


Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users