function getPlayerFromPartialName(name)
local name = name and string.lower(string.gsub(name, "#%x%x%x%x%x%x", "")) or nil
if name then
for _, player in ipairs(getElementsByType("player")) do
local name_ = string.lower(string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", ""))
if string.find(name_, name, 1, true) then
return player
end
end
end
return false
end
function privateMessage(thePlayer, _, sendToName, ...)
local message = table.concat({...}, " ")
if sendToName then
toPlayer = getPlayerFromPartialName(sendToName)
if isElement ( toPlayer ) then
if toPlayer ~= thePlayer then
if message ~= "" and #message > 0 then
outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0)
outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0)
setElementData(thePlayer, "pmPartner", toPlayer)
setElementData(toPlayer, "pmPartner", thePlayer)
else
outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0)
return false
end
else
outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0)
return false
end
else
outputChatBox("Player not found.", thePlayer, 255, 0, 0)
return false
end
else
outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0)
return false
end
end
addCommandHandler("pm", privateMessage)