Added /kill and more options.

master
Teodor Spæren 2012-10-14 13:14:16 +02:00
parent bf827ffa29
commit cda8a7545b
2 changed files with 52 additions and 15 deletions

View File

@ -1,6 +1,11 @@
-- List command
useList = true
listprivs = {shout=true}
-- Kill command
useKill = true
killprivs = {shout=true}
--MOTD
useMOTD = true
MOTD = "Welcome %s! This is the default MOTD."

View File

@ -1,24 +1,56 @@
dofile(minetest.get_modpath("redsand").."/conf.lua")
-- !!! FUNCTIONS !!! --
-- Getting the player object.
function get_player_obj (name)
goodname = string.match(name, "^([^ ]+) *$")
if goodname == nil then
print("ERROR!")
return
end
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
if name == goodname then
return player
end
end
end
-- !!! COMMANDS !!! ---
--[[ List function. ]]--
minetest.register_chatcommand("list", {
params = "", -- short parameter description
description = "List connected players", -- full description
privs = listprivs, -- require the "privs" privilege to run
func = function(name, param)
local namelist, count = "", 0
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
namelist = namelist .. string.format("%s, ", name)
count = count + 1
end
minetest.chat_send_player(name, string.format("Current players online: %d", count))
minetest.chat_send_player(name, string.format("Names: \[%s\]", namelist))
end,
})
if useList then
minetest.register_chatcommand("list", {
params = "", -- short parameter description
description = "List connected players", -- full description
privs = listprivs, -- require the "privs" privilege to run
func = function(name, param)
local namelist, count = "", 0
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
namelist = namelist .. string.format("%s, ", name)
count = count + 1
end
minetest.chat_send_player(name, string.format("Current players online: %d", count))
minetest.chat_send_player(name, string.format("Names: \[%s\]", namelist))
end,
})
end
--[[ Kill command ]]---
if useKill then
minetest.register_chatcommand("kill", {
params = "",
description = "Kills you :(",
privs = killprivs,
func = function(name, param)
local player = get_player_obj(name)
player:set_hp(0.0)
end,
})
end
-- !!! EVENTS !!! --
--[[ What happens when a player joins? ]]--