Initial commit
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user