Page 1 of 1

add_command name + Parameters

Posted: Sun Apr 30, 2017 10:14 am
by mophydeen
add_command currently only supports commands.
I'd like to have access to parameters.

eg. /slap someplayername

Re: add_command name + Parameters

Posted: Sun Apr 30, 2017 6:30 pm
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.

Re: add_command name + Parameters

Posted: Sun Apr 30, 2017 9:53 pm
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)