Updated the structure of the project.
I splitted the one file I had into many files so that it would be easier in the future to easly edit things. I plan to keep this structure where everything is just called from init.lua.master
parent
092e90fa2c
commit
c51a4f58d3
33
conf.lua
33
conf.lua
|
@ -1,11 +1,10 @@
|
||||||
--[[ What do you want to be loaded? ]]--
|
--[[ What do you want to be loaded? ]]--
|
||||||
|
useList = true -- List command
|
||||||
|
useMSG = true -- MSG command
|
||||||
|
useKill = true -- Kill command
|
||||||
|
useReply = true -- Reply command
|
||||||
|
|
||||||
useList = true -- List command
|
useMOTD = true -- Message of the day
|
||||||
useMSG = true -- MSG command
|
|
||||||
useKill = true -- Kill command
|
|
||||||
useReply = true -- Reply command
|
|
||||||
|
|
||||||
useMOTD = true -- Message of the day
|
|
||||||
useDeathMSG = true -- Death messages
|
useDeathMSG = true -- Death messages
|
||||||
useReviveMSG = true -- Revive messages
|
useReviveMSG = true -- Revive messages
|
||||||
|
|
||||||
|
@ -13,18 +12,18 @@ useReviveMSG = true -- Revive messages
|
||||||
careLetters = true -- Care about small and BIG letters?
|
careLetters = true -- Care about small and BIG letters?
|
||||||
|
|
||||||
--[[ Privleges ]]--
|
--[[ Privleges ]]--
|
||||||
listprivs = {shout = true} -- List privleges
|
listprivs = {shout = true} -- List privleges
|
||||||
killprivs = {shout = true} -- kill privleges
|
killprivs = {shout = true} -- kill privleges
|
||||||
msgprivs = {shout = true} -- msg privleges
|
msgprivs = {shout = true} -- msg privleges
|
||||||
replyprivs = {shout = true} -- reply privleges
|
replyprivs = {shout = true} -- reply privleges
|
||||||
|
|
||||||
--[[ Message strings ]]--
|
--[[ Message strings ]]--
|
||||||
MOTD = "Welcome %s! This is the default MOTD." -- Message of the day
|
MOTD = "Welcome %s! This is the default MOTD." -- Message of the day
|
||||||
DEATH_MSG = "%s left this world :(" -- Death message
|
DEATH_MSG = "%s left this world :(" -- Death message
|
||||||
REVIVE_MSG = "Like a Phonix %s rises from the ashes." -- Revive message
|
REVIVE_MSG = "Like a Phonix %s rises from the ashes." -- Revive message
|
||||||
|
|
||||||
--[[ What do you want after the / ]]--
|
--[[ What do you want after the / ]]--
|
||||||
listcmd = "list"
|
listcmd = "list"
|
||||||
msgcmd = "msg"
|
msgcmd = "msg"
|
||||||
killcmd = "kill"
|
killcmd = "kill"
|
||||||
replycmd = "reply"
|
replycmd = "reply"
|
|
@ -0,0 +1,29 @@
|
||||||
|
--[[
|
||||||
|
All code that is triggered when an event happens should reside
|
||||||
|
here :D
|
||||||
|
]]--
|
||||||
|
|
||||||
|
-- !!! EVENTS !!! --
|
||||||
|
|
||||||
|
--[[ What happens when a player joins? ]]--
|
||||||
|
if useMOTD then
|
||||||
|
minetest.register_on_joinplayer( function(player)
|
||||||
|
minetest.after( 2.0, function(param)
|
||||||
|
minetest.chat_send_player(player:get_player_name(), string.format(MOTD, player:get_player_name()))
|
||||||
|
end )
|
||||||
|
end )
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ What happens when a player die? ]]--
|
||||||
|
if useDeathMSG then
|
||||||
|
minetest.register_on_dieplayer( function(player)
|
||||||
|
minetest.chat_send_all(string.format(DEATH_MSG, player:get_player_name()))
|
||||||
|
end )
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ What happens when a player respawn ]]--
|
||||||
|
if useReviveMSG then
|
||||||
|
minetest.register_on_respawnplayer( function(player)
|
||||||
|
minetest.chat_send_all(string.format(REVIVE_MSG, player:get_player_name()))
|
||||||
|
end )
|
||||||
|
end
|
|
@ -0,0 +1,26 @@
|
||||||
|
-- !!! FUNCTIONS !!! --
|
||||||
|
-- Getting the player object.
|
||||||
|
function get_player_obj (name)
|
||||||
|
goodname = string.match(name, "^([^ ]+) *$")
|
||||||
|
if goodname == nil then
|
||||||
|
print("ERROR!")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Looping trough all the players currently online
|
||||||
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
local name = player:get_player_name()
|
||||||
|
|
||||||
|
-- Caring about letters or not?
|
||||||
|
if not careLetters then
|
||||||
|
if string.lower(name) == string.lower(goodname) then
|
||||||
|
return player
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if name == goodname then
|
||||||
|
return player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
|
@ -0,0 +1,33 @@
|
||||||
|
--[[ Single functions or non set commands should go in here ]]--
|
||||||
|
|
||||||
|
-- !!! COMMANDS !!! --
|
||||||
|
--[[ List function. ]]--
|
||||||
|
if useList then
|
||||||
|
minetest.register_chatcommand(listcmd, {
|
||||||
|
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("\nCurrent players online: %d\nNames: \[%s\]", count, namelist))
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Kill command ]]---
|
||||||
|
if useKill then
|
||||||
|
minetest.register_chatcommand(killcmd, {
|
||||||
|
params = "",
|
||||||
|
description = "Kills you :(",
|
||||||
|
privs = killprivs,
|
||||||
|
func = function(name, param)
|
||||||
|
local player = get_player_obj(name)
|
||||||
|
player:set_hp(0.0)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
151
init.lua
151
init.lua
|
@ -1,144 +1,11 @@
|
||||||
|
--[[ This mod was made by Teodor Spæren (TheRedMood) ]]--
|
||||||
|
|
||||||
|
-- Let the loading begin
|
||||||
|
|
||||||
|
-- Essential components
|
||||||
dofile(minetest.get_modpath("redsand").."/conf.lua")
|
dofile(minetest.get_modpath("redsand").."/conf.lua")
|
||||||
lastspoke = {}
|
dofile(minetest.get_modpath("redsand").."/functions.lua")
|
||||||
|
|
||||||
-- !!! FUNCTIONS !!! --
|
dofile(minetest.get_modpath("redsand").."/messages.lua")
|
||||||
|
dofile(minetest.get_modpath("redsand").."/events.lua")
|
||||||
-- Getting the player object.
|
dofile(minetest.get_modpath("redsand").."/general.lua")
|
||||||
function get_player_obj (name)
|
|
||||||
goodname = string.match(name, "^([^ ]+) *$")
|
|
||||||
if goodname == nil then
|
|
||||||
print("ERROR!")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Looping trough all the players currently online
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
|
||||||
local name = player:get_player_name()
|
|
||||||
|
|
||||||
-- Caring about letters or not?
|
|
||||||
if not careLetters then
|
|
||||||
if string.lower(name) == string.lower(goodname) then
|
|
||||||
return player
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if name == goodname then
|
|
||||||
return player
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- !!! COMMANDS !!! ---
|
|
||||||
|
|
||||||
--[[ List function. ]]--
|
|
||||||
if useList then
|
|
||||||
minetest.register_chatcommand(listcmd, {
|
|
||||||
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(killcmd, {
|
|
||||||
params = "",
|
|
||||||
description = "Kills you :(",
|
|
||||||
privs = killprivs,
|
|
||||||
func = function(name, param)
|
|
||||||
local player = get_player_obj(name)
|
|
||||||
player:set_hp(0.0)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[ MSG command ]]---
|
|
||||||
if useMSG then
|
|
||||||
minetest.register_chatcommand(msgcmd, {
|
|
||||||
params = "<target> <text>",
|
|
||||||
description = "Talk to someone!",
|
|
||||||
privs = msgprivs,
|
|
||||||
func = function(name, param)
|
|
||||||
if string.match(param, "([^ ]+) (.+)") == nil then
|
|
||||||
minetest.chat_send_player(name, "Missing parameters")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Generating the variables out of the parameters
|
|
||||||
local targetName, msg = string.match(param, "([^ ]+) (.+)")
|
|
||||||
target = get_player_obj(targetName)
|
|
||||||
|
|
||||||
-- Checking if the target exists
|
|
||||||
if not target then
|
|
||||||
minetest.chat_send_player(name, "The target was not found")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Sending the message
|
|
||||||
minetest.chat_send_player(target:get_player_name(), string.format("From %s: %s", name, msg))
|
|
||||||
-- Register the chat in the target persons lastspoke tabler
|
|
||||||
lastspoke[target:get_player_name()] = name
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[ REPLY command]] --
|
|
||||||
if useReply then
|
|
||||||
minetest.register_chatcommand(replycmd, {
|
|
||||||
params = "<text>",
|
|
||||||
description = "Reply the last peron that messaged you.",
|
|
||||||
privs = replyprivs,
|
|
||||||
func = function(name, param)
|
|
||||||
-- We need to get the target
|
|
||||||
target = lastspoke[name]
|
|
||||||
|
|
||||||
-- Make sure I don't crash the server.
|
|
||||||
if not target then
|
|
||||||
minetest.chat_send_player(name, "No one has spoke to you :(")
|
|
||||||
elseif param == "" then
|
|
||||||
minetest.chat_send_player(name, "You need to say something.")
|
|
||||||
else
|
|
||||||
-- We need to send the message and update the targets lastspoke[] status.
|
|
||||||
minetest.chat_send_player(target, string.format("From %s: %s", name, param))
|
|
||||||
lastspoke[target] = name
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- !!! EVENTS !!! --
|
|
||||||
|
|
||||||
--[[ What happens when a player joins? ]]--
|
|
||||||
if useMOTD then
|
|
||||||
minetest.register_on_joinplayer( function(player)
|
|
||||||
minetest.after( 2.0, function(param)
|
|
||||||
minetest.chat_send_player(player:get_player_name(), string.format(MOTD, player:get_player_name()))
|
|
||||||
end )
|
|
||||||
end )
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[ What happens when a player die? ]]--
|
|
||||||
if useDeathMSG then
|
|
||||||
minetest.register_on_dieplayer( function(player)
|
|
||||||
minetest.chat_send_all(string.format(DEATH_MSG, player:get_player_name()))
|
|
||||||
end )
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[ What happens when a player respawn ]]--
|
|
||||||
if useReviveMSG then
|
|
||||||
minetest.register_on_respawnplayer( function(player)
|
|
||||||
minetest.chat_send_all(string.format(REVIVE_MSG, player:get_player_name()))
|
|
||||||
end )
|
|
||||||
end
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
--[[ All code around the messaging system should be kept here. ]]--
|
||||||
|
lastspoke = {}
|
||||||
|
|
||||||
|
--[[ MSG command ]]---
|
||||||
|
if useMSG then
|
||||||
|
minetest.register_chatcommand(msgcmd, {
|
||||||
|
params = "<target> <text>",
|
||||||
|
description = "Talk to someone!",
|
||||||
|
privs = msgprivs,
|
||||||
|
func = function(name, param)
|
||||||
|
if string.match(param, "([^ ]+) (.+)") == nil then
|
||||||
|
minetest.chat_send_player(name, "Missing parameters")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Generating the variables out of the parameters
|
||||||
|
local targetName, msg = string.match(param, "([^ ]+) (.+)")
|
||||||
|
target = get_player_obj(targetName)
|
||||||
|
|
||||||
|
-- Checking if the target exists
|
||||||
|
if not target then
|
||||||
|
minetest.chat_send_player(name, "The target was not found")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Sending the message
|
||||||
|
minetest.chat_send_player(target:get_player_name(), string.format("From %s: %s", name, msg))
|
||||||
|
-- Register the chat in the target persons lastspoke tabler
|
||||||
|
lastspoke[target:get_player_name()] = name
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ REPLY command]] --
|
||||||
|
if useReply then
|
||||||
|
minetest.register_chatcommand(replycmd, {
|
||||||
|
params = "<text>",
|
||||||
|
description = "Reply the last peron that messaged you.",
|
||||||
|
privs = replyprivs,
|
||||||
|
func = function(name, param)
|
||||||
|
-- We need to get the target
|
||||||
|
target = lastspoke[name]
|
||||||
|
|
||||||
|
-- Make sure I don't crash the server.
|
||||||
|
if not target then
|
||||||
|
minetest.chat_send_player(name, "No one has spoke to you :(")
|
||||||
|
elseif param == "" then
|
||||||
|
minetest.chat_send_player(name, "You need to say something.")
|
||||||
|
else
|
||||||
|
-- We need to send the message and update the targets lastspoke[] status.
|
||||||
|
minetest.chat_send_player(target, string.format("From %s: %s", name, param))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
Loading…
Reference in New Issue