From 3231ea6c74e01ac3e6041f97ade8a4d68003e3a7 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sat, 21 Jan 2017 17:34:36 +0100 Subject: [PATCH] Implemented /pm and /r for legacymod (refs #46) --- luamods/wolfadmin/commands/client/pm.lua | 63 ++++++++++++++++++++++-- luamods/wolfadmin/commands/client/r.lua | 60 +++++++++++----------- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/luamods/wolfadmin/commands/client/pm.lua b/luamods/wolfadmin/commands/client/pm.lua index 773d247..042cda7 100644 --- a/luamods/wolfadmin/commands/client/pm.lua +++ b/luamods/wolfadmin/commands/client/pm.lua @@ -21,22 +21,75 @@ local commands = require (wolfa_getLuaPath()..".commands.commands") local players = require (wolfa_getLuaPath()..".players.players") +local settings = require (wolfa_getLuaPath()..".util.settings") + function commandPersonalMessage(clientId, cmdArguments) if #cmdArguments > 1 then local cmdClient - + if tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then cmdClient = et.ClientNumberFromString(cmdArguments[1]) else cmdClient = tonumber(cmdArguments[1]) end - + if cmdClient ~= -1 and et.gentity_get(cmdClient, "pers.netname") then players.setLastPMSender(cmdClient, clientId) - + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..cmdClient.." \"^9reply: ^7r [^2message^7]\";") end end end -commands.addclient("pm", commandPersonalMessage, "", "", true) -commands.addclient("m", commandPersonalMessage, "", "", true) +commands.addclient("pm", commandPersonalMessage, "", "", true, (settings.get("fs_game") ~= "legacy")) +commands.addclient("m", commandPersonalMessage, "", "", true, (settings.get("fs_game") ~= "legacy")) + +function commandPersonalMessage(clientId, cmdArguments) + if #cmdArguments == 0 then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: "..commands.getclient("pm")["syntax"].."\";") + + return true + end + + local cmdClient + + if tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then + cmdClient = et.ClientNumberFromString(cmdArguments[1]) + else + cmdClient = tonumber(cmdArguments[1]) + end + + if cmdClient == -1 or cmdClient == nil then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9pm: ^7no or multiple matches for '^7"..cmdArguments[1].."^9'.\";") + + return true + elseif not et.gentity_get(cmdClient, "pers.netname") then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpm: ^7no connected player by that name or slot #\";") + + return true + end + + local message, messageConcatenated = {}, "" + + for i = 1, #cmdArguments do + message[i] = cmdArguments[i] + end + + messageConcatenated = table.concat(message, " ") + + if cmdClient ~= -1 and et.gentity_get(cmdClient, "pers.netname") then + players.setLastPMSender(cmdClient, clientId) + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..cmdArguments[1].."^7: (1 recipients): ^3"..messageConcatenated.."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/misc/pm.wav\";") + + if clientId ~= cmdClient then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..cmdClient.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..cmdArguments[1].."^7: (1 recipients): ^3"..messageConcatenated.."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..cmdClient.." \"sound/misc/pm.wav\";") + end + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..cmdClient.." \"^3private message from "..et.gentity_get(clientId, "pers.netname").."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..cmdClient.." \"^9reply: ^7r [^2message^7]\";") + end +end +commands.addclient("pm", commandPersonalMessage, "", "", true, (settings.get("fs_game") == "legacy")) +commands.addclient("m", commandPersonalMessage, "", "", true, (settings.get("fs_game") == "legacy")) diff --git a/luamods/wolfadmin/commands/client/r.lua b/luamods/wolfadmin/commands/client/r.lua index 0f9d6ec..c9f86fc 100644 --- a/luamods/wolfadmin/commands/client/r.lua +++ b/luamods/wolfadmin/commands/client/r.lua @@ -24,35 +24,39 @@ local players = require (wolfa_getLuaPath()..".players.players") function commandR(clientId, cmdArguments) if #cmdArguments == 0 then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: "..commands.getclient("r")["syntax"].."\";") - else - local recipient = players.getLastPMSender(clientId) - - if not (recipient and et.gentity_get(recipient, "pers.netname")) then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"player not found\";") - else - local message, messageConcatenated = {}, "" - - for i = 1, #cmdArguments do - message[i] = cmdArguments[i] - end - - messageConcatenated = table.concat(message, " ") - - players.setLastPMSender(recipient, clientId) - - et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..recipient..": (1 recipients): ^3"..messageConcatenated.."\";") - et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/misc/pm.wav\";") - - if clientId ~= recipient then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..recipient.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..recipient..": (1 recipients): ^3"..messageConcatenated.."\";") - et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/misc/pm.wav\";") - end - - et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..recipient.." \"^3private message from "..et.gentity_get(clientId, "pers.netname").."\";") - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..recipient.." \"^9reply: ^7r [^2message^7]\";") - end + + return true end - + + local recipient = players.getLastPMSender(clientId) + + if not (recipient and et.gentity_get(recipient, "pers.netname")) then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"player not found\";") + + return true + end + + local message, messageConcatenated = {}, "" + + for i = 1, #cmdArguments do + message[i] = cmdArguments[i] + end + + messageConcatenated = table.concat(message, " ") + + players.setLastPMSender(recipient, clientId) + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..recipient..": (1 recipients): ^3"..messageConcatenated.."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/misc/pm.wav\";") + + if clientId ~= recipient then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..recipient.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..recipient..": (1 recipients): ^3"..messageConcatenated.."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..recipient.." \"sound/misc/pm.wav\";") + end + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..recipient.." \"^3private message from "..et.gentity_get(clientId, "pers.netname").."\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..recipient.." \"^9reply: ^7r [^2message^7]\";") + return true end commands.addclient("r", commandR, "", "[^2message^7]", true)