Initial commit
This commit is contained in:
90
gamemodes/darkrp/gamemode/modules/chat/cl_chat.lua
Normal file
90
gamemodes/darkrp/gamemode/modules/chat/cl_chat.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
--[[---------------------------------------------------------------------------
|
||||
Gamemode function
|
||||
---------------------------------------------------------------------------]]
|
||||
function GM:OnPlayerChat()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Add a message to chat
|
||||
---------------------------------------------------------------------------]]
|
||||
local function AddToChat(bits)
|
||||
local col1 = Color(net.ReadUInt(8), net.ReadUInt(8), net.ReadUInt(8))
|
||||
|
||||
local prefixText = net.ReadString()
|
||||
local ply = net.ReadEntity()
|
||||
ply = IsValid(ply) and ply or LocalPlayer()
|
||||
|
||||
if not IsValid(ply) then return end
|
||||
|
||||
if prefixText == "" or not prefixText then
|
||||
prefixText = ply:Nick()
|
||||
prefixText = prefixText ~= "" and prefixText or ply:SteamName()
|
||||
end
|
||||
|
||||
local col2 = Color(net.ReadUInt(8), net.ReadUInt(8), net.ReadUInt(8))
|
||||
|
||||
local text = net.ReadString()
|
||||
local shouldShow
|
||||
if text and text ~= "" then
|
||||
if IsValid(ply) then
|
||||
shouldShow = hook.Call("OnPlayerChat", GAMEMODE, ply, text, false, not ply:Alive(), prefixText, col1, col2)
|
||||
end
|
||||
|
||||
if shouldShow ~= true then
|
||||
chat.AddNonParsedText(col1, prefixText, col2, ": " .. text)
|
||||
end
|
||||
else
|
||||
shouldShow = hook.Call("ChatText", GAMEMODE, "0", prefixText, prefixText, "darkrp")
|
||||
|
||||
if shouldShow ~= true then
|
||||
chat.AddNonParsedText(col1, prefixText)
|
||||
end
|
||||
end
|
||||
chat.PlaySound()
|
||||
end
|
||||
net.Receive("DarkRP_Chat", AddToChat)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Credits
|
||||
|
||||
Please only ADD to the credits.
|
||||
---------------------------------------------------------------------------]]
|
||||
local creds =
|
||||
[[
|
||||
|
||||
LightRP was created by Rick darkalonio. LightRP was sandbox with some added RP elements.
|
||||
LightRP was released at the end of January 2007
|
||||
|
||||
DarkRP was created as a spoof of LightRP by Rickster, somewhere during the summer of 2007.
|
||||
Note: There was a DarkRP in 2006, but that was an entirely different gamemode.
|
||||
|
||||
Rickster went to serve his country and went to Afghanistan. During that time, the following people updated DarkRP:
|
||||
Picwizdan
|
||||
Sibre
|
||||
[GNC] Matt
|
||||
PhilXYZ
|
||||
Chromebolt A.K.A. Unib5 (STEAM_0:1:19045957)
|
||||
|
||||
In 2008, Unib5 was administrator on a DarkRP server called EuroRP, owned by Jiggu. FPtje frequently joined this server to prop kill en masse. While Jiggu loved watching the chaos unfold, Unib5 hated it and banned FPtje on sight. Since Jiggu kept unbanning FPtje, Unib5 felt powerless. In an attempt to stop FPtje, Unib5 put FPtje's favourite prop killing props (the locker and the sawblade) in the default blacklist of DarkRP in an update. This in turn enraged FPtje, as he swore to make an update in secret that would suddenly pop up and overthrow the established version. As a result, DarkRP 2.3.1 was released in December 2008. After a bit of a fight, FPtje became the official updater of DarkRP.
|
||||
|
||||
Current developer:
|
||||
Falco A.K.A. FPtje Atheos (STEAM_0:0:8944068)
|
||||
|
||||
People who have contributed (ordered by commits, with at least two commits)
|
||||
Bo98
|
||||
Drakehawke (STEAM_0:0:22342869) (64 commits on old SVN)
|
||||
FiG-Scorn
|
||||
Noiwex
|
||||
KoZ
|
||||
Eusion (STEAM_0:0:20450406) (3 commits on old SVN)
|
||||
Gangleider
|
||||
MattWalton12
|
||||
TypicalRookie
|
||||
]]
|
||||
|
||||
local function credits(um)
|
||||
chat.AddNonParsedText(Color(255, 0, 0, 255), "[", Color(50,50,50,255), GAMEMODE.Name, Color(255, 0, 0, 255), "] ", color_white, DarkRP.getPhrase("credits_see_console"))
|
||||
|
||||
MsgC(Color(255, 0, 0, 255), DarkRP.getPhrase("credits_for", GAMEMODE.Name), color_white, creds)
|
||||
end
|
||||
usermessage.Hook("DarkRP_Credits", credits)
|
||||
207
gamemodes/darkrp/gamemode/modules/chat/cl_chatlisteners.lua
Normal file
207
gamemodes/darkrp/gamemode/modules/chat/cl_chatlisteners.lua
Normal file
@@ -0,0 +1,207 @@
|
||||
--[[---------------------------------------------------------------------------
|
||||
This module finds out for you who can see you talk or speak through the microphone
|
||||
---------------------------------------------------------------------------]]
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Variables
|
||||
---------------------------------------------------------------------------]]
|
||||
local receivers
|
||||
local currentChatText = {}
|
||||
local receiverConfigs = {}
|
||||
local currentConfig = {text = "", hearFunc = fn.Id} -- Default config is not loaded yet
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
addChatReceiver
|
||||
Add a chat command with specific receivers
|
||||
|
||||
prefix: the chat command itself ("/pm", "/ooc", "/me" are some examples)
|
||||
text: the text that shows up when it says "Some people can hear you X"
|
||||
hearFunc: a function(ply, splitText) that decides whether this player can or cannot hear you.
|
||||
return true if the player can hear you
|
||||
false if the player cannot
|
||||
nil if you want to prevent the text from showing up temporarily
|
||||
---------------------------------------------------------------------------]]
|
||||
function DarkRP.addChatReceiver(prefix, text, hearFunc)
|
||||
receiverConfigs[prefix] = {
|
||||
text = text,
|
||||
hearFunc = hearFunc
|
||||
}
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
removeChatReceiver
|
||||
Remove a chat command.
|
||||
|
||||
prefix: the command, like in addChatReceiver
|
||||
---------------------------------------------------------------------------]]
|
||||
function DarkRP.removeChatReceiver(prefix)
|
||||
receiverConfigs[prefix] = nil
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Draw the results to the screen
|
||||
---------------------------------------------------------------------------]]
|
||||
local function drawChatReceivers()
|
||||
if not receivers then return end
|
||||
|
||||
local fontHeight = draw.GetFontHeight("DarkRPHUD1")
|
||||
local x, y = chat.GetChatBoxPos()
|
||||
y = y - fontHeight - 4
|
||||
|
||||
local receiversCount = #receivers
|
||||
-- No one hears you
|
||||
if receiversCount == 0 then
|
||||
draw.WordBox(2, x, y, DarkRP.getPhrase("hear_noone", currentConfig.text), "DarkRPHUD1", Color(0,0,0,160), Color(255,0,0,255))
|
||||
return
|
||||
-- Everyone hears you
|
||||
elseif receiversCount == player.GetCount() - 1 then
|
||||
draw.WordBox(2, x, y, DarkRP.getPhrase("hear_everyone"), "DarkRPHUD1", Color(0,0,0,160), Color(0,255,0,255))
|
||||
return
|
||||
end
|
||||
|
||||
draw.WordBox(2, x, y - (receiversCount * (fontHeight + 4)), DarkRP.getPhrase("hear_certain_persons", currentConfig.text), "DarkRPHUD1", Color(0,0,0,160), Color(0,255,0,255))
|
||||
for i = 1, receiversCount, 1 do
|
||||
if not IsValid(receivers[i]) then
|
||||
receivers[i] = receivers[#receivers]
|
||||
receivers[#receivers] = nil
|
||||
continue
|
||||
end
|
||||
|
||||
draw.WordBox(2, x, y - (i - 1) * (fontHeight + 4), receivers[i]:Nick(), "DarkRPHUD1", Color(0, 0, 0, 160), color_white)
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Find out who could hear the player if they were to speak now
|
||||
---------------------------------------------------------------------------]]
|
||||
local function chatGetRecipients()
|
||||
if not currentConfig then return end
|
||||
|
||||
receivers = {}
|
||||
for _, ply in ipairs(player.GetAll()) do
|
||||
local hidePly = hook.Run("chatHideRecipient", ply)
|
||||
if not IsValid(ply) or ply == LocalPlayer() or ply:GetNoDraw() or hidePly then continue end
|
||||
|
||||
local val = currentConfig.hearFunc(ply, currentChatText)
|
||||
|
||||
-- Return nil to disable the chat recipients temporarily.
|
||||
if val == nil then
|
||||
receivers = nil
|
||||
return
|
||||
elseif val == true then
|
||||
table.insert(receivers, ply)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Called when the player starts typing
|
||||
---------------------------------------------------------------------------]]
|
||||
local function startFind()
|
||||
local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_ChatReceivers")
|
||||
if shouldDraw == false then return end
|
||||
|
||||
currentConfig = receiverConfigs[""]
|
||||
hook.Add("Think", "DarkRP_chatRecipients", chatGetRecipients)
|
||||
hook.Add("HUDPaint", "DarkRP_DrawChatReceivers", drawChatReceivers)
|
||||
end
|
||||
hook.Add("StartChat", "DarkRP_StartFindChatReceivers", startFind)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Called when the player stops typing
|
||||
---------------------------------------------------------------------------]]
|
||||
local function stopFind()
|
||||
hook.Remove("Think", "DarkRP_chatRecipients")
|
||||
hook.Remove("HUDPaint", "DarkRP_DrawChatReceivers")
|
||||
end
|
||||
hook.Add("FinishChat", "DarkRP_StopFindChatReceivers", stopFind)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Find out which chat command the user is typing
|
||||
---------------------------------------------------------------------------]]
|
||||
local function findConfig(text)
|
||||
local split = string.Explode(' ', text)
|
||||
local prefix = string.lower(split[1])
|
||||
|
||||
currentChatText = split
|
||||
|
||||
currentConfig = receiverConfigs[prefix] or receiverConfigs[""]
|
||||
end
|
||||
hook.Add("ChatTextChanged", "DarkRP_FindChatRecipients", findConfig)
|
||||
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Default chat receievers. If you want to add your own ones, don't add them to this file. Add them to a clientside module file instead.
|
||||
---------------------------------------------------------------------------]]
|
||||
-- Load after the custom languages have been loaded
|
||||
local function loadChatReceivers()
|
||||
-- Default talk chat receiver has no prefix
|
||||
DarkRP.addChatReceiver("", DarkRP.getPhrase("talk"), function(ply)
|
||||
if GAMEMODE.Config.alltalk then return nil end
|
||||
|
||||
return LocalPlayer():GetPos():DistToSqr(ply:GetPos()) <
|
||||
GAMEMODE.Config.talkDistance * GAMEMODE.Config.talkDistance
|
||||
end)
|
||||
|
||||
DarkRP.addChatReceiver("/ooc", DarkRP.getPhrase("speak_in_ooc"), function(ply) return true end)
|
||||
DarkRP.addChatReceiver("//", DarkRP.getPhrase("speak_in_ooc"), function(ply) return true end)
|
||||
DarkRP.addChatReceiver("/a", DarkRP.getPhrase("speak_in_ooc"), function(ply) return true end)
|
||||
DarkRP.addChatReceiver("/w", DarkRP.getPhrase("whisper"), function(ply) return LocalPlayer():GetPos():DistToSqr(ply:GetPos()) < GAMEMODE.Config.whisperDistance * GAMEMODE.Config.whisperDistance end)
|
||||
DarkRP.addChatReceiver("/y", DarkRP.getPhrase("yell"), function(ply) return LocalPlayer():GetPos():DistToSqr(ply:GetPos()) < GAMEMODE.Config.yellDistance * GAMEMODE.Config.yellDistance end)
|
||||
DarkRP.addChatReceiver("/me", DarkRP.getPhrase("perform_your_action"), function(ply) return LocalPlayer():GetPos():DistToSqr(ply:GetPos()) < GAMEMODE.Config.meDistance * GAMEMODE.Config.meDistance end)
|
||||
DarkRP.addChatReceiver("/g", DarkRP.getPhrase("talk_to_your_group"), function(ply)
|
||||
for _, func in pairs(GAMEMODE.DarkRPGroupChats) do
|
||||
if func(LocalPlayer()) and func(ply) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
|
||||
DarkRP.addChatReceiver("/pm", "PM", function(ply, text)
|
||||
if not isstring(text[2]) then return false end
|
||||
text[2] = string.lower(tostring(text[2]))
|
||||
|
||||
return string.find(string.lower(ply:Nick()), text[2], 1, true) ~= nil or
|
||||
string.find(string.lower(ply:SteamName()), text[2], 1, true) ~= nil or
|
||||
string.lower(ply:SteamID()) == text[2]
|
||||
end)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Voice chat receivers
|
||||
---------------------------------------------------------------------------]]
|
||||
local voiceDistance = GM.Config.voiceDistance * GM.Config.voiceDistance
|
||||
DarkRP.addChatReceiver("speak", DarkRP.getPhrase("speak"), function(ply)
|
||||
if not LocalPlayer().DRPIsTalking then return nil end
|
||||
if LocalPlayer():GetPos():DistToSqr(ply:GetPos()) > voiceDistance then return false end
|
||||
|
||||
return not GAMEMODE.Config.dynamicvoice or ply:isInRoom()
|
||||
end)
|
||||
end
|
||||
hook.Add("loadCustomDarkRPItems", "loadChatListeners", loadChatReceivers)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Called when the player starts using their voice
|
||||
---------------------------------------------------------------------------]]
|
||||
local function startFindVoice(ply)
|
||||
if ply ~= LocalPlayer() then return end
|
||||
|
||||
local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_ChatReceivers")
|
||||
if shouldDraw == false then return end
|
||||
|
||||
currentConfig = receiverConfigs["speak"]
|
||||
hook.Add("Think", "DarkRP_chatRecipients", chatGetRecipients)
|
||||
hook.Add("HUDPaint", "DarkRP_DrawChatReceivers", drawChatReceivers)
|
||||
end
|
||||
hook.Add("PlayerStartVoice", "DarkRP_VoiceChatReceiverFinder", startFindVoice)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Called when the player stops using their voice
|
||||
---------------------------------------------------------------------------]]
|
||||
local function stopFindVoice(ply)
|
||||
if ply ~= LocalPlayer() then return end
|
||||
|
||||
stopFind()
|
||||
end
|
||||
hook.Add("PlayerEndVoice", "DarkRP_VoiceChatReceiverFinder", stopFindVoice)
|
||||
56
gamemodes/darkrp/gamemode/modules/chat/cl_interface.lua
Normal file
56
gamemodes/darkrp/gamemode/modules/chat/cl_interface.lua
Normal file
@@ -0,0 +1,56 @@
|
||||
DarkRP.addChatReceiver = DarkRP.stub{
|
||||
name = "addChatReceiver",
|
||||
description = "Add a chat command with specific receivers",
|
||||
parameters = {
|
||||
{
|
||||
name = "prefix",
|
||||
description = "The chat command itself (\"/pm\", \"/ooc\", \"/me\" are some examples)",
|
||||
type = "string",
|
||||
optional = false
|
||||
},
|
||||
{
|
||||
name = "text",
|
||||
description = "The text that shows up when it says \"Some people can hear you X\"",
|
||||
type = "string",
|
||||
optional = false
|
||||
},
|
||||
{
|
||||
name = "hearFunc",
|
||||
description = "A function(ply, splitText) that decides whether this player can or cannot hear you.",
|
||||
type = "function",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.removeChatReceiver = DarkRP.stub{
|
||||
name = "removeChatReceiver",
|
||||
description = "Remove a chat command receiver",
|
||||
parameters = {
|
||||
{
|
||||
name = "prefix",
|
||||
description = "The chat command itself (\"/pm\", \"/ooc\", \"/me\" are some examples)",
|
||||
type = "string",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.hookStub{
|
||||
name = "chatHideRecipient",
|
||||
description = "Hide a receipent from who can hear/see your text GUI.",
|
||||
parameters = {
|
||||
{
|
||||
name = "ply",
|
||||
description = "The player who spoke.",
|
||||
type = "Player"
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
|
||||
}
|
||||
}
|
||||
216
gamemodes/darkrp/gamemode/modules/chat/sh_chatcommands.lua
Normal file
216
gamemodes/darkrp/gamemode/modules/chat/sh_chatcommands.lua
Normal file
@@ -0,0 +1,216 @@
|
||||
local plyMeta = FindMetaTable("Player")
|
||||
DarkRP.chatCommands = DarkRP.chatCommands or {}
|
||||
|
||||
local validChatCommand = {
|
||||
command = isstring,
|
||||
description = isstring,
|
||||
condition = fn.FOr{fn.Curry(fn.Eq, 2)(nil), isfunction},
|
||||
delay = isnumber,
|
||||
tableArgs = fn.FOr{fn.Curry(fn.Eq, 2)(nil), isbool},
|
||||
}
|
||||
|
||||
local checkChatCommand = function(tbl)
|
||||
for k in pairs(validChatCommand) do
|
||||
if not validChatCommand[k](tbl[k]) then
|
||||
return false, k
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function DarkRP.declareChatCommand(tbl)
|
||||
local valid, element = checkChatCommand(tbl)
|
||||
if not valid then
|
||||
DarkRP.error("Incorrect chat command! " .. element .. " is invalid!", 2)
|
||||
end
|
||||
|
||||
tbl.command = string.lower(tbl.command)
|
||||
DarkRP.chatCommands[tbl.command] = DarkRP.chatCommands[tbl.command] or tbl
|
||||
for k, v in pairs(tbl) do
|
||||
DarkRP.chatCommands[tbl.command][k] = v
|
||||
end
|
||||
end
|
||||
|
||||
function DarkRP.removeChatCommand(command)
|
||||
DarkRP.chatCommands[string.lower(command)] = nil
|
||||
end
|
||||
|
||||
function DarkRP.chatCommandAlias(command, ...)
|
||||
local name
|
||||
for k, v in ipairs{...} do
|
||||
name = string.lower(v)
|
||||
|
||||
DarkRP.chatCommands[name] = {command = name}
|
||||
setmetatable(DarkRP.chatCommands[name], {
|
||||
__index = DarkRP.chatCommands[command]
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function DarkRP.getChatCommand(command)
|
||||
return DarkRP.chatCommands[string.lower(command)]
|
||||
end
|
||||
|
||||
function DarkRP.getChatCommands()
|
||||
return DarkRP.chatCommands
|
||||
end
|
||||
|
||||
function DarkRP.getSortedChatCommands()
|
||||
local tbl = fn.Compose{table.ClearKeys, table.Copy, DarkRP.getChatCommands}()
|
||||
table.SortByMember(tbl, "command", true)
|
||||
|
||||
return tbl
|
||||
end
|
||||
|
||||
-- chat commands that have been defined, but not declared
|
||||
DarkRP.getIncompleteChatCommands = fn.Curry(fn.Filter, 3)(fn.Compose{fn.Not, checkChatCommand})(DarkRP.chatCommands)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Chat commands
|
||||
---------------------------------------------------------------------------]]
|
||||
DarkRP.declareChatCommand{
|
||||
command = "pm",
|
||||
description = "Send a private message to someone.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "w",
|
||||
description = "Say something in whisper voice.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "y",
|
||||
description = "Yell something out loud.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "me",
|
||||
description = "Chat roleplay to say you're doing things that you can't show otherwise.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "/",
|
||||
description = "Global server chat.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "a",
|
||||
description = "Global server chat.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "ooc",
|
||||
description = "Global server chat.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "broadcast",
|
||||
description = "Broadcast something as a mayor.",
|
||||
delay = 1.5,
|
||||
condition = plyMeta.isMayor
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "channel",
|
||||
description = "Tune into a radio channel.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "radio",
|
||||
description = "Say something through the radio.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "g",
|
||||
description = "Group chat.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "credits",
|
||||
description = "Send the DarkRP credits to someone.",
|
||||
delay = 1.5
|
||||
}
|
||||
|
||||
|
||||
local function init()
|
||||
if not DarkRP then
|
||||
MsgC(Color(255,0,0), "DarkRP Classic Advert tried to run, but DarkRP wasn't declared!\n")
|
||||
return
|
||||
end
|
||||
|
||||
DarkRP.removeChatCommand("advert")
|
||||
DarkRP.declareChatCommand({
|
||||
command = "advert",
|
||||
description = "Displays an advertisement to everyone in chat.",
|
||||
delay = 1.5
|
||||
})
|
||||
|
||||
if SERVER then
|
||||
DarkRP.defineChatCommand("advert",function(ply,args)
|
||||
if args == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", ""))
|
||||
return ""
|
||||
end
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", ""))
|
||||
return
|
||||
end
|
||||
for k,v in pairs(player.GetAll()) do
|
||||
local col = team.GetColor(ply:Team())
|
||||
DarkRP.talkToPerson(v, col, "[Реклама] " .. ply:Nick(), Color(255, 255, 0, 255), text, ply)
|
||||
end
|
||||
end
|
||||
hook.Call("playerAdverted", nil, ply, args)
|
||||
return args, DoSay
|
||||
end, 1.5)
|
||||
else
|
||||
DarkRP.addChatReceiver("/advert", "advertise", function(ply) return true end)
|
||||
end
|
||||
end
|
||||
|
||||
if SERVER then
|
||||
if #player.GetAll() > 0 then
|
||||
init()
|
||||
else
|
||||
hook.Add("PlayerInitialSpawn", "dfca-load", init)
|
||||
end
|
||||
else
|
||||
hook.Add("InitPostEntity", "dfca-load", init)
|
||||
end
|
||||
|
||||
|
||||
if SERVER then
|
||||
|
||||
local function Roll(ply, args)
|
||||
local DoSay = function()
|
||||
if GAMEMODE.Config.alltalk then
|
||||
for _, target in pairs(player.GetAll()) do
|
||||
DarkRP.talkToPerson(target, team.GetColor(ply:Team()), ply:Nick().. " выпало " ..math.random(1,100).." из 100.")
|
||||
end
|
||||
else
|
||||
DarkRP.talkToRange(ply, ply:Nick().. " выпало " ..math.random(1,100).." из 100.", "", 250)
|
||||
end
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("roll", Roll, 1.5)
|
||||
|
||||
|
||||
|
||||
DarkRP.declareChatCommand{
|
||||
command = "roll",
|
||||
description = "write an roll",
|
||||
delay = 1.5
|
||||
}
|
||||
end
|
||||
121
gamemodes/darkrp/gamemode/modules/chat/sh_interface.lua
Normal file
121
gamemodes/darkrp/gamemode/modules/chat/sh_interface.lua
Normal file
@@ -0,0 +1,121 @@
|
||||
DarkRP.declareChatCommand = DarkRP.stub{
|
||||
name = "declareChatCommand",
|
||||
description = "Declare a chat command (describe it)",
|
||||
parameters = {
|
||||
{
|
||||
name = "table",
|
||||
description = "The description of the chat command. Has to contain a string: command, string: description, number: delay, optional function: condition",
|
||||
type = "table",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.removeChatCommand = DarkRP.stub{
|
||||
name = "removeChatCommand",
|
||||
description = "Remove a chat command",
|
||||
parameters = {
|
||||
{
|
||||
name = "command",
|
||||
description = "The chat command to remove",
|
||||
type = "string",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.chatCommandAlias = DarkRP.stub{
|
||||
name = "chatCommandAlias",
|
||||
description = "Create an alias for a chat command",
|
||||
parameters = {
|
||||
{
|
||||
name = "command",
|
||||
description = "An already existing chat command.",
|
||||
type = "string",
|
||||
optional = false
|
||||
},
|
||||
{
|
||||
name = "alias",
|
||||
description = "One or more aliases for the chat command.",
|
||||
type = "vararg",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.getChatCommand = DarkRP.stub{
|
||||
name = "getChatCommand",
|
||||
description = "Get the information on a chat command.",
|
||||
parameters = {
|
||||
{
|
||||
name = "command",
|
||||
description = "The chat command",
|
||||
type = "string",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
{
|
||||
name = "chatTable",
|
||||
description = "A table containing the information of the chat command.",
|
||||
type = "table"
|
||||
}
|
||||
},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.getChatCommands = DarkRP.stub{
|
||||
name = "getChatCommands",
|
||||
description = "Get every chat command.",
|
||||
parameters = {
|
||||
|
||||
},
|
||||
returns = {
|
||||
{
|
||||
name = "commands",
|
||||
description = "A table containing every command. Table indices are the command strings.",
|
||||
type = "table"
|
||||
}
|
||||
},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.getSortedChatCommands = DarkRP.stub{
|
||||
name = "getSortedChatCommands",
|
||||
description = "Get every chat command, sorted by their name.",
|
||||
parameters = {
|
||||
|
||||
},
|
||||
returns = {
|
||||
{
|
||||
name = "commands",
|
||||
description = "A table containing every command.",
|
||||
type = "table"
|
||||
}
|
||||
},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.getIncompleteChatCommands = DarkRP.stub{
|
||||
name = "getIncompleteChatCommands",
|
||||
description = "chat commands that have been defined, but not declared. Information about these chat commands is missing.",
|
||||
parameters = {
|
||||
},
|
||||
returns = {
|
||||
{
|
||||
name = "commands",
|
||||
description = "A table containing the undeclared chat commands.",
|
||||
type = "table"
|
||||
}
|
||||
},
|
||||
metatable = DarkRP
|
||||
}
|
||||
183
gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua
Normal file
183
gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua
Normal file
@@ -0,0 +1,183 @@
|
||||
local function registerCommandDefinition(cmd, callback)
|
||||
local chatcommands = DarkRP.getChatCommands()
|
||||
|
||||
chatcommands[cmd] = chatcommands[cmd] or {}
|
||||
chatcommands[cmd].callback = callback
|
||||
chatcommands[cmd].command = chatcommands[cmd].command or cmd
|
||||
end
|
||||
|
||||
function DarkRP.defineChatCommand(cmd, callback)
|
||||
cmd = string.lower(cmd)
|
||||
local detour = function(ply, arg, ...)
|
||||
local canChatCommand = gamemode.Call("canChatCommand", ply, cmd, arg, ...)
|
||||
if not canChatCommand then
|
||||
return ""
|
||||
end
|
||||
|
||||
local ret = {callback(ply, arg, ...)}
|
||||
local overrideTxt, overrideDoSayFunc = hook.Run("onChatCommand", ply, cmd, arg, ret, ...)
|
||||
|
||||
if overrideTxt then return overrideTxt, overrideDoSayFunc end
|
||||
return unpack(ret)
|
||||
end
|
||||
|
||||
registerCommandDefinition(cmd, detour)
|
||||
end
|
||||
|
||||
function DarkRP.definePrivilegedChatCommand(cmd, priv, callback, extraInfoTbl)
|
||||
cmd = string.lower(cmd)
|
||||
|
||||
local function onCAMIResult(ply, arg, hasAccess, reason)
|
||||
if hasAccess then return callback(ply, arg) end
|
||||
|
||||
local notify = ply:EntIndex() == 0 and print or fp{DarkRP.notify, ply, 1, 4}
|
||||
notify(DarkRP.getPhrase("no_privilege"))
|
||||
end
|
||||
|
||||
local function callbackdetour(ply, arg, ...)
|
||||
local canChatCommand = gamemode.Call("canChatCommand", ply, cmd, arg)
|
||||
if not canChatCommand then
|
||||
return ""
|
||||
end
|
||||
|
||||
CAMI.PlayerHasAccess(ply, priv, fp{onCAMIResult, ply, arg}, nil, extraInfoTbl)
|
||||
|
||||
local overrideTxt, overrideDoSayFunc = hook.Run("onChatCommand", ply, cmd, arg, {""})
|
||||
|
||||
if overrideTxt then return overrideTxt, overrideDoSayFunc end
|
||||
return ""
|
||||
end
|
||||
|
||||
registerCommandDefinition(cmd, callbackdetour)
|
||||
end
|
||||
|
||||
local function RP_PlayerChat(ply, text, teamonly)
|
||||
DarkRP.log(ply:Nick() .. " (" .. ply:SteamID() .. "): " .. text)
|
||||
local callback = ""
|
||||
local DoSayFunc
|
||||
local groupSay = DarkRP.getChatCommand("g")
|
||||
|
||||
-- Extract the chat command
|
||||
local tblCmd = fn.Compose{
|
||||
DarkRP.getChatCommand,
|
||||
string.lower,
|
||||
fn.Curry(fn.Flip(string.sub), 2)(2), -- extract prefix
|
||||
fn.Curry(fn.GetValue, 2)(1), -- Get the first word
|
||||
fn.Curry(string.Explode, 2)(' ') -- split by spaces
|
||||
}(text)
|
||||
|
||||
if string.sub(text, 1, 1) == GAMEMODE.Config.chatCommandPrefix and tblCmd then
|
||||
local args = string.sub(text, string.len(tblCmd.command) + 3, string.len(text))
|
||||
args = tblCmd.tableArgs and DarkRP.explodeArg(args) or args
|
||||
|
||||
ply.DrpCommandDelays = ply.DrpCommandDelays or {}
|
||||
if tblCmd.delay and ply.DrpCommandDelays[tblCmd.command] and ply.DrpCommandDelays[tblCmd.command] > CurTime() - tblCmd.delay then
|
||||
return ""
|
||||
end
|
||||
|
||||
ply.DrpCommandDelays[tblCmd.command] = CurTime()
|
||||
|
||||
callback, DoSayFunc = tblCmd.callback(ply, args)
|
||||
if callback == "" then
|
||||
return "", "", DoSayFunc
|
||||
end
|
||||
text = string.sub(text, string.len(tblCmd.command) + 3, string.len(text))
|
||||
elseif teamonly and groupSay then
|
||||
callback, DoSayFunc = groupSay.callback(ply, text)
|
||||
return text, "", DoSayFunc
|
||||
end
|
||||
|
||||
if callback ~= "" then
|
||||
callback = callback or "" .. " "
|
||||
end
|
||||
|
||||
return text, callback, DoSayFunc;
|
||||
end
|
||||
|
||||
local function RP_ActualDoSay(ply, text, callback)
|
||||
callback = callback or ""
|
||||
if text == "" then return "" end
|
||||
local col = team.GetColor(ply:Team())
|
||||
local col2 = color_white
|
||||
if not ply:Alive() then
|
||||
col2 = Color(255, 200, 200, 255)
|
||||
col = col2
|
||||
end
|
||||
|
||||
if GAMEMODE.Config.alltalk then
|
||||
local name = ply:Nick()
|
||||
for _, v in ipairs(player.GetAll()) do
|
||||
DarkRP.talkToPerson(v, col, callback .. name, col2, text, ply)
|
||||
end
|
||||
else
|
||||
DarkRP.talkToRange(ply, callback .. ply:Nick(), text, GAMEMODE.Config.talkDistance)
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
function GM:canChatCommand(ply, cmd, ...)
|
||||
if not ply.DarkRPUnInitialized then return true end
|
||||
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("data_not_loaded_one"))
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("data_not_loaded_two"))
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
g_DarkRPOldHookCall = g_DarkRPOldHookCall or hook.Call
|
||||
|
||||
local GM = GM
|
||||
function hook.Call(name, gm, ply, text, teamonly, ...)
|
||||
if name == "PlayerSay" then
|
||||
local dead = not ply:Alive()
|
||||
|
||||
local text2 = text
|
||||
local callback
|
||||
local DoSayFunc
|
||||
|
||||
text2 = g_DarkRPOldHookCall(name, gm, ply, text, teamonly, dead) or text2
|
||||
|
||||
text2, callback, DoSayFunc = RP_PlayerChat(ply, text2, teamonly)
|
||||
if tostring(text2) == " " then text2, callback = callback, text2 end
|
||||
if not GM.Config.deadtalk and dead then return "" end
|
||||
|
||||
if game.IsDedicated() then
|
||||
ServerLog("\"" .. ply:Nick() .. "<" .. ply:UserID() .. ">" .. "<" .. ply:SteamID() .. ">" .. "<" .. team.GetName(ply:Team()) .. ">\" say \"" .. text .. "\"\n" .. "\n")
|
||||
end
|
||||
|
||||
if DoSayFunc then DoSayFunc(text2) return "" end
|
||||
RP_ActualDoSay(ply, text2, callback)
|
||||
|
||||
hook.Call("PostPlayerSay", nil, ply, text2, teamonly, dead)
|
||||
return ""
|
||||
end
|
||||
|
||||
return g_DarkRPOldHookCall(name, gm, ply, text, teamonly, ...)
|
||||
end
|
||||
|
||||
local function ConCommand(ply, _, args)
|
||||
if not args[1] then return end
|
||||
local cmd = string.lower(args[1])
|
||||
local tbl = DarkRP.getChatCommand(cmd)
|
||||
|
||||
if not tbl then return end
|
||||
|
||||
table.remove(args, 1) -- Remove subcommand
|
||||
local arg = tbl.tableArgs and args or table.concat(args, ' ')
|
||||
local time = CurTime()
|
||||
|
||||
if not tbl then return end
|
||||
|
||||
ply.DrpCommandDelays = ply.DrpCommandDelays or {}
|
||||
|
||||
if IsValid(ply) then -- Server console isn't valid
|
||||
if tbl.delay and ply.DrpCommandDelays[cmd] and ply.DrpCommandDelays[cmd] > time - tbl.delay then
|
||||
return
|
||||
end
|
||||
|
||||
ply.DrpCommandDelays[cmd] = time
|
||||
end
|
||||
|
||||
tbl.callback(ply, arg)
|
||||
end
|
||||
concommand.Add("darkrp", ConCommand)
|
||||
241
gamemodes/darkrp/gamemode/modules/chat/sv_chatcommands.lua
Normal file
241
gamemodes/darkrp/gamemode/modules/chat/sv_chatcommands.lua
Normal file
@@ -0,0 +1,241 @@
|
||||
--[[---------------------------------------------------------
|
||||
Talking
|
||||
---------------------------------------------------------]]
|
||||
local function PM(ply, args)
|
||||
local namepos = string.find(args, " ")
|
||||
if not namepos then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
|
||||
local name = string.sub(args, 1, namepos - 1)
|
||||
local msg = string.sub(args, namepos + 1)
|
||||
|
||||
if msg == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
|
||||
local target = DarkRP.findPlayer(name)
|
||||
if target == ply then return "" end
|
||||
|
||||
if target then
|
||||
local col = team.GetColor(ply:Team())
|
||||
local pname = ply:Nick()
|
||||
local col2 = color_white
|
||||
DarkRP.talkToPerson(target, col, "(PM) " .. pname, col2, msg, ply)
|
||||
DarkRP.talkToPerson(ply, col, "(PM) " .. pname, col2, msg, ply)
|
||||
else
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(name)))
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
DarkRP.defineChatCommand("pm", PM, 1.5)
|
||||
|
||||
local function Whisper(ply, args)
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
DarkRP.talkToRange(ply, "(" .. DarkRP.getPhrase("whisper") .. ") " .. ply:Nick(), text, GAMEMODE.Config.whisperDistance)
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("w", Whisper, 1.5)
|
||||
|
||||
local function Yell(ply, args)
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
DarkRP.talkToRange(ply, "(" .. DarkRP.getPhrase("yell") .. ") " .. ply:Nick(), text, GAMEMODE.Config.yellDistance)
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("y", Yell, 1.5)
|
||||
|
||||
local function Me(ply, args)
|
||||
if args == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
if GAMEMODE.Config.alltalk then
|
||||
local col = team.GetColor(ply:Team())
|
||||
local name = ply:Nick()
|
||||
for _, target in ipairs(player.GetAll()) do
|
||||
DarkRP.talkToPerson(target, col, name .. " " .. text)
|
||||
end
|
||||
else
|
||||
DarkRP.talkToRange(ply, ply:Nick() .. " " .. text, "", GAMEMODE.Config.meDistance)
|
||||
end
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("me", Me, 1.5)
|
||||
|
||||
local function OOC(ply, args)
|
||||
if not GAMEMODE.Config.ooc then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("disabled", DarkRP.getPhrase("ooc"), ""))
|
||||
return ""
|
||||
end
|
||||
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
local col = team.GetColor(ply:Team())
|
||||
local col2 = color_white
|
||||
if not ply:Alive() then
|
||||
col2 = Color(255, 200, 200, 255)
|
||||
col = col2
|
||||
end
|
||||
|
||||
local phrase = DarkRP.getPhrase("ooc")
|
||||
local name = ply:Nick()
|
||||
for _, v in ipairs(player.GetAll()) do
|
||||
DarkRP.talkToPerson(v, col, "(" .. phrase .. ") " .. name, col2, text, ply)
|
||||
end
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("/", OOC, true, 1.5)
|
||||
DarkRP.defineChatCommand("a", OOC, true, 1.5)
|
||||
DarkRP.defineChatCommand("ooc", OOC, true, 1.5)
|
||||
|
||||
local function MayorBroadcast(ply, args)
|
||||
if args == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
local Team = ply:Team()
|
||||
if not RPExtraTeams[Team] or not RPExtraTeams[Team].mayor then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("incorrect_job", DarkRP.getPhrase("broadcast")))
|
||||
return ""
|
||||
end
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return
|
||||
end
|
||||
|
||||
local col = team.GetColor(ply:Team())
|
||||
local col2 = Color(170, 0, 0, 255)
|
||||
local phrase = DarkRP.getPhrase("broadcast")
|
||||
local name = ply:Nick()
|
||||
for _, v in ipairs(player.GetAll()) do
|
||||
DarkRP.talkToPerson(v, col, phrase .. " " .. name, col2, text, ply)
|
||||
end
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("broadcast", MayorBroadcast, 1.5)
|
||||
|
||||
local function SetRadioChannel(ply,args)
|
||||
local channel = DarkRP.toInt(args)
|
||||
if channel == nil or channel < 0 or channel > 100 then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), "0<" .. DarkRP.getPhrase("channel") .. "<100"))
|
||||
return ""
|
||||
end
|
||||
DarkRP.notify(ply, 2, 4, DarkRP.getPhrase("channel_set_to_x", args))
|
||||
ply.RadioChannel = channel
|
||||
return ""
|
||||
end
|
||||
DarkRP.defineChatCommand("channel", SetRadioChannel)
|
||||
|
||||
local function SayThroughRadio(ply,args)
|
||||
if not ply.RadioChannel then ply.RadioChannel = 1 end
|
||||
local radioChannel = ply.RadioChannel
|
||||
if not args or args == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return ""
|
||||
end
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return
|
||||
end
|
||||
local col = Color(180, 180, 180, 255)
|
||||
local phrase = DarkRP.getPhrase("radio_x", radioChannel)
|
||||
for _, v in ipairs(player.GetAll()) do
|
||||
if v.RadioChannel == radioChannel then
|
||||
DarkRP.talkToPerson(v, col, phrase, col, text, ply)
|
||||
end
|
||||
end
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("radio", SayThroughRadio, 1.5)
|
||||
|
||||
local function GroupMsg(ply, args)
|
||||
local DoSay = function(text)
|
||||
if text == "" then
|
||||
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
|
||||
return
|
||||
end
|
||||
|
||||
local col = team.GetColor(ply:Team())
|
||||
|
||||
local groupChats = {}
|
||||
for _, func in pairs(GAMEMODE.DarkRPGroupChats) do
|
||||
-- not the group of the player
|
||||
if not func(ply) then continue end
|
||||
|
||||
table.insert(groupChats, func)
|
||||
end
|
||||
|
||||
if table.IsEmpty(groupChats) then return "" end
|
||||
|
||||
local phrase = DarkRP.getPhrase("group")
|
||||
local name = ply:Nick()
|
||||
local color = color_white
|
||||
for _, target in ipairs(player.GetAll()) do
|
||||
-- The target is in any of the group chats
|
||||
for _, func in ipairs(groupChats) do
|
||||
if not func(target, ply) then continue end
|
||||
|
||||
DarkRP.talkToPerson(target, col, phrase .. " " .. name, color, text, ply)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return args, DoSay
|
||||
end
|
||||
DarkRP.defineChatCommand("g", GroupMsg, 0)
|
||||
|
||||
-- here's the new easter egg. Easier to find, more subtle, doesn't only credit FPtje and unib5
|
||||
-- WARNING: DO NOT EDIT THIS
|
||||
-- You can edit DarkRP but you HAVE to credit the original authors!
|
||||
-- You even have to credit all the previous authors when you rename the gamemode.
|
||||
-- local CreditsWait = true
|
||||
local function GetDarkRPAuthors(ply, args)
|
||||
local target = DarkRP.findPlayer(args) -- Only send to one player. Prevents spamming
|
||||
target = IsValid(target) and target or ply
|
||||
|
||||
if target ~= ply then
|
||||
if ply.CreditsWait then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("wait_with_that")) return "" end
|
||||
ply.CreditsWait = true
|
||||
timer.Simple(60, function() if IsValid(ply) then ply.CreditsWait = nil end end) -- so people don't spam it
|
||||
end
|
||||
|
||||
local rf = RecipientFilter()
|
||||
rf:AddPlayer(target)
|
||||
if ply ~= target then
|
||||
rf:AddPlayer(ply)
|
||||
end
|
||||
|
||||
umsg.Start("DarkRP_Credits", rf)
|
||||
umsg.End()
|
||||
|
||||
return ""
|
||||
end
|
||||
DarkRP.defineChatCommand("credits", GetDarkRPAuthors, 50)
|
||||
145
gamemodes/darkrp/gamemode/modules/chat/sv_interface.lua
Normal file
145
gamemodes/darkrp/gamemode/modules/chat/sv_interface.lua
Normal file
@@ -0,0 +1,145 @@
|
||||
DarkRP.defineChatCommand = DarkRP.stub{
|
||||
name = "defineChatCommand",
|
||||
description = "Create a chat command that calls the function",
|
||||
parameters = {
|
||||
{
|
||||
name = "chat command",
|
||||
description = "The registered chat command",
|
||||
type = "string",
|
||||
optional = false
|
||||
},
|
||||
{
|
||||
name = "callback",
|
||||
description = "The function that is called when the chat command is executed",
|
||||
type = "function",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.definePrivilegedChatCommand = DarkRP.stub{
|
||||
name = "definePrivilegedChatCommand",
|
||||
description = "Create a chat command that calls the function if the player has the right CAMI privilege. Will automatically notify the user when they don't have access. Note that chat command functions registered with this function can NOT override the chat that will appear after the command has been executed.",
|
||||
parameters = {
|
||||
{
|
||||
name = "chat command",
|
||||
description = "The registered chat command",
|
||||
type = "string",
|
||||
optional = false
|
||||
},
|
||||
{
|
||||
name = "privilege",
|
||||
description = "The name of the CAMI privilege",
|
||||
type = "string",
|
||||
optional = false
|
||||
},
|
||||
{
|
||||
name = "callback",
|
||||
description = "The function that is called when the chat command is executed",
|
||||
type = "function",
|
||||
optional = false
|
||||
}
|
||||
},
|
||||
returns = {},
|
||||
metatable = DarkRP
|
||||
}
|
||||
|
||||
DarkRP.hookStub{
|
||||
name = "PostPlayerSay",
|
||||
description = "Called after a player has said something.",
|
||||
parameters = {
|
||||
{
|
||||
name = "ply",
|
||||
description = "The player who spoke.",
|
||||
type = "Player"
|
||||
},
|
||||
{
|
||||
name = "text",
|
||||
description = "The thing they said.",
|
||||
type = "string"
|
||||
},
|
||||
{
|
||||
name = "teamonly",
|
||||
description = "Whether they said it to their team only.",
|
||||
type = "boolean"
|
||||
},
|
||||
{
|
||||
name = "dead",
|
||||
description = "Whether they are dead.",
|
||||
type = "boolean"
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
DarkRP.hookStub{
|
||||
name = "canChatCommand",
|
||||
description = "Called when a player tries to run any chat command or uses the DarkRP console command. ",
|
||||
parameters = {
|
||||
{
|
||||
name = "ply",
|
||||
description = "The player who spoke.",
|
||||
type = "Player"
|
||||
},
|
||||
{
|
||||
name = "command",
|
||||
description = "The thing they said.",
|
||||
type = "string"
|
||||
},
|
||||
{
|
||||
name = "arguments",
|
||||
description = "The arguments of the chat command, given as one string.",
|
||||
type = "string"
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
{
|
||||
name = "canChatCommand",
|
||||
description = "Whether the player is allowed to run the chat command.",
|
||||
type = "boolean"
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
DarkRP.hookStub{
|
||||
name = "onChatCommand",
|
||||
description = "Called after a player has run any chat command or uses the DarkRP console command. Note: the chat command has already been run. Use canChatCommand if you want to stop chat commands from being run.",
|
||||
parameters = {
|
||||
{
|
||||
name = "ply",
|
||||
description = "The player who spoke.",
|
||||
type = "Player"
|
||||
},
|
||||
{
|
||||
name = "command",
|
||||
description = "The thing they said.",
|
||||
type = "string"
|
||||
},
|
||||
{
|
||||
name = "arguments",
|
||||
description = "The arguments of the chat command, given either as one string or a table of strings. That depends on whether the command is declared to use table arguments.",
|
||||
type = "string"
|
||||
},
|
||||
{
|
||||
name = "return",
|
||||
description = "The return value of the chat command function. Should contain a chat text override and/or a say function. See the return values of this hook for a description",
|
||||
type = "table"
|
||||
}
|
||||
},
|
||||
returns = {
|
||||
{
|
||||
name = "overrideText",
|
||||
description = "Overrides the text a chat command will put in everyone's chat box. Return nil to not change behaviour.",
|
||||
type = "string"
|
||||
},
|
||||
{
|
||||
name = "overrideSayFunc",
|
||||
description = "Say functions handle what needs to be said to whom. The say function for PMs for example make sure only the sender and receiver see the message. You can override this behaviour by returning a different say function in this hook. Return nil to not change behaviour.",
|
||||
type = "function"
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user