/slap 5

Place to get help with not working mods / modding interface.
Post Reply
mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

/slap 5

Post by mophydeen »

I'd like to add slap command and slay command to a automod (savefile).

Is there a way to capture messages from chat?

eg. /slap 5 /slap 30 /slap d /slay


slap would be a few teleportations.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: /slap 5

Post by Rseding91 »

For 0.15 you can register your own console commands in mods.
If you want to get ahold of me I'm almost always on Discord.

Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

Re: /slap 5

Post by Articulating »

Rseding91 wrote:For 0.15 you can register your own console commands in mods.
Will this be available in scenarios? Or will it have to be registered in the data section?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: /slap 5

Post by Rseding91 »

Articulating wrote:
Rseding91 wrote:For 0.15 you can register your own console commands in mods.
Will this be available in scenarios? Or will it have to be registered in the data section?
It's done the same way custom events are done now.
If you want to get ahold of me I'm almost always on Discord.

User avatar
cpeosphoros
Inserter
Inserter
Posts: 40
Joined: Fri Dec 23, 2016 10:57 pm
Contact:

Re: /slap 5

Post by cpeosphoros »

Rseding91 wrote:
Articulating wrote:
Rseding91 wrote:For 0.15 you can register your own console commands in mods.
Will this be available in scenarios? Or will it have to be registered in the data section?
It's done the same way custom events are done now.
Nice!

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: /slap 5

Post by darkfrei »

Rseding91 wrote:For 0.15 you can register your own console commands in mods.
Can mods write to chat/console? And read any text from it?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: /slap 5

Post by Rseding91 »

darkfrei wrote:
Rseding91 wrote:For 0.15 you can register your own console commands in mods.
Can mods write to chat/console? And read any text from it?
Write: yes - player.print()

Read: no - why would you want to read from the console? It's going to be boring player conversation 99% of the time or localized string keys: "item-name.copper-ore".
If you want to get ahold of me I'm almost always on Discord.

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: /slap 5

Post by Mooncat »

Rseding91 wrote:
darkfrei wrote:
Rseding91 wrote:For 0.15 you can register your own console commands in mods.
Can mods write to chat/console? And read any text from it?
Write: yes - player.print()

Read: no - why would you want to read from the console? It's going to be boring player conversation 99% of the time or localized string keys: "item-name.copper-ore".
Maybe he want to check if the last message starts with "slap". If so, then phase the number next to it as the slap count. So this will allow custom slap count other than the registered numbers.
I have a similar idea too before. :lol:

mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

Re: /slap 5

Post by mophydeen »

For now I added an extra console under a top button.

Code: Select all

function gui_send_command(player)
	local textbox = player.gui.left["sl-extended-frame"]["sl-extended-frame-a"]["sl-extended-input-text"]
	local text = trim(textbox.text)

	local split = splitString(text, nil)

	if split[1] == "/slap" then
		if game.players[split[2]] then
			if game.players[split[2]].connected then
                local amount = tonumber(split[3])

    			if amount and amount > 0 and amount <= 25 then
    				startSlapping(game.players[split[2]], player, amount)
    			else
                    startSlapping(game.players[split[2]], player, SLAP_DEFAULT_AMOUNT)
    			end
            else
                slSays(player, game.players[split[2]].name .. " is not online")
            end
		else
			slSays(player, "Player not found")
		end
    elseif split[1] == "/commands" or split[1] == "/command" then
        slShowCommandsText(player)
    elseif split[1] == "/up" then
        slShowUpText(player)
    elseif split[1] == "/host" then
        slShowHostText(player)
    elseif split[1] == "/online" then
        slShowOnlineText(player)
    elseif split[1] == "/afk" then
        slShowAfkText(player)
	else
		slSays(player, "Unknown command: /commands for all commands")
	end


	textbox.text = ""
end

User avatar
LotA
Fast Inserter
Fast Inserter
Posts: 117
Joined: Fri Oct 10, 2014 11:41 am
Contact:

Re: /slap 5

Post by LotA »

Rseding91 wrote:For 0.15 you can register your own console commands in mods.
That's great ! :d
Rseding91 wrote: Read: no - why would you want to read from the console? It's going to be boring player conversation 99% of the time or localized string keys: "item-name.copper-ore".
Will the custom commands be available to all clients even with the "commands for admin only" ?
Parsing the chat is typically how modders implement their built-it permission / right management system and custom commands (often starting with "!", i'm thinking of GoldSrc/Source engine games or minecraft) as chat is available to anyone. This way you keep the native commands limited to admins yet you provide commands (or even "evolved" command-line menus) to everyone.
With this and remote calls, one could build a powerful and flexible permission system.

Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

Re: /slap 5

Post by Articulating »

Consider the /evolution or /time commands, they are commands that are open to anyone. I assume that these custom commands will fire for anybody and it will be up to the modders to check player.admin if the command is for admins only, as this is a more flexible solution in several ways.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: /slap 5

Post by Nexela »

LotA wrote:Will the custom commands be available to all clients even with the "commands for admin only" ?
I am pretty sure it will be up to the modder to check for .admin or a mod stored list of people allowed in their code.

User avatar
LotA
Fast Inserter
Fast Inserter
Posts: 117
Joined: Fri Oct 10, 2014 11:41 am
Contact:

Re: /slap 5

Post by LotA »

Articulating wrote:Consider the /evolution or /time commands, they are commands that are open to anyone. I assume that these custom commands will fire for anybody and it will be up to the modders to check player.admin if the command is for admins only, as this is a more flexible solution in several ways.
I disagree.

A permission system allow to manage different rights to different people, and even groups if needed.
the .admin boolean checks your are an "server admin" but you might want to give "random" people access to some customs commands while not allowing them to use /kick or anything "sensitive".

mophydeen
Filter Inserter
Filter Inserter
Posts: 529
Joined: Sun Nov 22, 2015 5:02 pm
Contact:

Re: /slap 5

Post by mophydeen »

LotA wrote:
Articulating wrote:Consider the /evolution or /time commands, they are commands that are open to anyone. I assume that these custom commands will fire for anybody and it will be up to the modders to check player.admin if the command is for admins only, as this is a more flexible solution in several ways.
I disagree.

A permission system allow to manage different rights to different people, and even groups if needed.
the .admin boolean checks your are an "server admin" but you might want to give "random" people access to some customs commands while not allowing them to use /kick or anything "sensitive".

The mod could keep a list of power-users.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: /slap 5

Post by Nexela »

LotA wrote:
Articulating wrote:Consider the /evolution or /time commands, they are commands that are open to anyone. I assume that these custom commands will fire for anybody and it will be up to the modders to check player.admin if the command is for admins only, as this is a more flexible solution in several ways.
I disagree.

A permission system allow to manage different rights to different people, and even groups if needed.
the .admin boolean checks your are an "server admin" but you might want to give "random" people access to some customs commands while not allowing them to use /kick or anything "sensitive".
You can do that in a mod already. (simplified a bit but..)

Code: Select all

global.allowed_because_permissions = {["Nexela"]=true ["LotA"]=true}
local allowed_players = function(player_index) return game.players[player_index].admin or (global.allowed_because_permissions[game.players[player_index].name) end

script.on_event("my_custom_command", function (event) if allowed_players(event.player_index) then dostuffhere end end
if another mod does a permission system and they have a remote.call registered for retrieving information you can get it that way.

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: /slap 5

Post by Mooncat »

A question came into my mind: what will happen if more than one mods registered the same command? Are they both triggered when user enter the command?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: /slap 5

Post by Rseding91 »

Mooncat wrote:A question came into my mind: what will happen if more than one mods registered the same command? Are they both triggered when user enter the command?
It errors the same way as if you try to have 2 mods register the same remote interface.
If you want to get ahold of me I'm almost always on Discord.

Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

Re: /slap 5

Post by Articulating »

LotA wrote:
Articulating wrote:Consider the /evolution or /time commands, they are commands that are open to anyone. I assume that these custom commands will fire for anybody and it will be up to the modders to check player.admin if the command is for admins only, as this is a more flexible solution in several ways.
I disagree.

A permission system allow to manage different rights to different people, and even groups if needed.
the .admin boolean checks your are an "server admin" but you might want to give "random" people access to some customs commands while not allowing them to use /kick or anything "sensitive".
Exactly, that's why commands should be open to anyone and the mod should have to discern who is allowed or who isn't.

Post Reply

Return to “Modding help”