1 minetest.register_chatcommand("spawn", {
3 description = "Spawn x amount of a mob, used as /spawn 'mob' 10 or /spawn 'mob' for one",
4 privs = {server = true},
5 func = function( name, mob)
10 --checks if a player put a number of mobs
11 local number_of_mobs = string.find(str, "%s%d+")
14 --remove spaces from the string
15 if number_of_mobs == nil then
20 amount = tonumber(str:match("^.-%s(.*)"))
21 str = "mob:"..str:match("(.*)%s")
24 if amount == nil or str == nil then
25 minetest.chat_send_player(name, "Format as /spawn 'mob' 20 ... or /spawn 'mob'")
28 --add amount of entities if registered
29 if minetest.registered_entities[str] ~= nil then
30 local pos = minetest.get_player_by_name(name):get_pos()
32 --add in amount through loop
35 minetest.add_entity(pos,str)
38 minetest.add_entity(pos,str)
40 else --tell player the mob doesn't exist if not a registered entity
41 minetest.chat_send_player(name, str:match("^.-:(.*)"):gsub("^%l", string.upper).." is not a mob.")