add_command name + Parameters

Things that already exist in the current mod API
Post Reply

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

Re: add_command name + Parameters

Post by Rseding91 »

It already supports parameters. You get the parameters in the event callback as "parameter".

Each command callback gets:
  • name
  • tick
  • player_index (optional)
  • parameter (optional)
Although I do see now the docs for what the callback contains aren't being generated so I'll work on fixing that.
If you want to get ahold of me I'm almost always on Discord.

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

Re: add_command name + Parameters

Post by mophydeen »

thank you


example for who is looking:

Code: Select all

----------------------------------------
-- Custom commands
----------------------------------------
commands.add_command("slap", "Slap a player. (usage: /slap somePlayerName)", function(param)
	local player = game.players[param.player_index]
 	if param.parameter then
		local victim = game.players[param.parameter]
		if victim then
			if victim.connected then
	            startSlapping(victim, player, SLAP_DEFAULT_AMOUNT)
	        else
	            slSays(player, victim.name .. " is not online")
	        end
		else
			slSays(player, "Player not found: (" .. param.parameter .. ")")
		end
 	else
		slSays(player, "Player name needed. (usage: /slap somePlayerName)")
	end    
end)

Post Reply

Return to “Already exists”