Initial commit

This commit is contained in:
pavetr
2026-03-15 14:54:49 +03:00
commit 64f8029c06
4027 changed files with 254888 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
local plyMeta = FindMetaTable("Player")
DarkRP.declareChatCommand{
command = "setspawn",
description = "Reset the spawn position for some job and place a new one at your position (use the command name of the job as argument)",
delay = 1.5
}
DarkRP.declareChatCommand{
command = "addspawn",
description = "Add a spawn position for some job (use the command name of the job as argument)",
delay = 1.5
}
DarkRP.declareChatCommand{
command = "removespawn",
description = "Remove a spawn position for some job (use the command name of the job as argument)",
delay = 1.5
}
DarkRP.declareChatCommand{
command = "jailpos",
description = "Reset jail positions and create a new one at your position.",
delay = 1.5,
condition = fn.FAnd{plyMeta.isChief, fn.Compose{fn.Curry(fn.GetValue, 2)("chiefjailpos"), fn.Curry(fn.GetValue, 2)("Config"), gmod.GetGamemode}}
}
DarkRP.declareChatCommand{
command = "setjailpos",
description = "Reset jail positions and create a new one at your position.",
delay = 1.5,
condition = fn.FAnd{plyMeta.isChief, fn.Compose{fn.Curry(fn.GetValue, 2)("chiefjailpos"), fn.Curry(fn.GetValue, 2)("Config"), gmod.GetGamemode}}
}
DarkRP.declareChatCommand{
command = "addjailpos",
description = "Add a jail position where you're standing.",
delay = 1.5,
condition = fn.FAnd{plyMeta.isChief, fn.Compose{fn.Curry(fn.GetValue, 2)("chiefjailpos"), fn.Curry(fn.GetValue, 2)("Config"), gmod.GetGamemode}}
}

View File

@@ -0,0 +1,144 @@
--[[---------------------------------------------------------------------------
Loading
---------------------------------------------------------------------------]]
local teamSpawns = {}
local jailPos = {}
local function onDBInitialized()
local map = MySQLite.SQLStr(string.lower(game.GetMap()))
MySQLite.query("SELECT * FROM darkrp_position NATURAL JOIN darkrp_jobspawn WHERE map = " .. map .. ";", function(data)
teamSpawns = data or {}
end)
MySQLite.query([[SELECT * FROM darkrp_position WHERE type = 'J' AND map = ]] .. map .. [[;]], function(data)
for _, v in ipairs(data or {}) do
table.insert(jailPos, Vector(v.x, v.y, v.z))
end
end)
end
hook.Add("DarkRPDBInitialized", "GetPositions", onDBInitialized)
local JailIndex = 1 -- Used to circulate through the jailpos table
-- Function for backwards compatibility
function DarkRP.storeJailPos(ply, addingPos)
local pos = ply:GetPos()
if addingPos then
DarkRP.addJailPos(pos)
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("added_jailpos"))
else
DarkRP.setJailPos(pos)
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("reset_add_jailpos"))
end
end
function DarkRP.setJailPos(pos)
local map = MySQLite.SQLStr(string.lower(game.GetMap()))
jailPos = {pos}
local remQuery = "DELETE FROM darkrp_position WHERE type = 'J' AND map = %s;"
local insQuery = "INSERT INTO darkrp_position(map, type, x, y, z) VALUES(%s, 'J', %s, %s, %s);"
remQuery = string.format(remQuery, map)
insQuery = string.format(insQuery, map, pos.x, pos.y, pos.z)
MySQLite.begin()
MySQLite.queueQuery(remQuery)
MySQLite.queueQuery(insQuery)
MySQLite.commit()
JailIndex = 1
end
function DarkRP.addJailPos(pos)
local map = MySQLite.SQLStr(string.lower(game.GetMap()))
table.insert(jailPos, pos)
local insQuery = "INSERT INTO darkrp_position(map, type, x, y, z) VALUES(%s, 'J', %s, %s, %s);"
insQuery = string.format(insQuery, map, pos.x, pos.y, pos.z)
MySQLite.query(insQuery)
JailIndex = 1
end
function DarkRP.retrieveJailPos(index)
if not jailPos then return Vector(0, 0, 0) end
if index then
return jailPos[index]
end
-- Retrieve the least recently used jail position
local oldestPos = jailPos[JailIndex]
JailIndex = JailIndex % #jailPos + 1
return oldestPos
end
function DarkRP.jailPosCount()
return table.Count(jailPos or {})
end
function DarkRP.storeTeamSpawnPos(t, pos)
local map = string.lower(game.GetMap())
local teamcmd = RPExtraTeams[t].command
DarkRP.removeTeamSpawnPos(t, function()
MySQLite.query([[INSERT INTO darkrp_position(map, type, x, y, z) VALUES(]] .. MySQLite.SQLStr(map) .. [[, "T", ]] .. pos[1] .. [[, ]] .. pos[2] .. [[, ]] .. pos[3] .. [[);]]
, function()
MySQLite.queryValue([[SELECT MAX(id) FROM darkrp_position WHERE map = ]] .. MySQLite.SQLStr(map) .. [[ AND type = "T";]], function(id)
if not id then return end
MySQLite.query([[INSERT INTO darkrp_jobspawn VALUES(]] .. id .. [[, ]] .. MySQLite.SQLStr(teamcmd) .. [[);]])
table.insert(teamSpawns, {id = id, map = map, x = pos[1], y = pos[2], z = pos[3], teamcmd = teamcmd})
end)
end)
end)
end
function DarkRP.addTeamSpawnPos(t, pos)
local map = string.lower(game.GetMap())
local teamcmd = RPExtraTeams[t].command
MySQLite.query([[INSERT INTO darkrp_position(map, type, x, y, z) VALUES(]] .. MySQLite.SQLStr(map) .. [[, "T", ]] .. pos[1] .. [[, ]] .. pos[2] .. [[, ]] .. pos[3] .. [[);]]
, function()
MySQLite.queryValue([[SELECT MAX(id) FROM darkrp_position WHERE map = ]] .. MySQLite.SQLStr(map) .. [[ AND type = "T";]], function(id)
if isbool(id) then return end
MySQLite.query([[INSERT INTO darkrp_jobspawn VALUES(]] .. id .. [[, ]] .. MySQLite.SQLStr(teamcmd) .. [[);]])
table.insert(teamSpawns, {id = id, map = map, x = pos[1], y = pos[2], z = pos[3], teamcmd = teamcmd})
end)
end)
end
function DarkRP.removeTeamSpawnPos(t, callback)
local map = string.lower(game.GetMap())
local teamcmd = RPExtraTeams[tonumber(t)].command
for k, v in pairs(teamSpawns) do
if v.teamcmd == teamcmd then
teamSpawns[k] = nil
end
end
MySQLite.query([[SELECT darkrp_position.id FROM darkrp_position
NATURAL JOIN darkrp_jobspawn
WHERE map = ]] .. MySQLite.SQLStr(map) .. [[
AND teamcmd = ]] .. MySQLite.SQLStr(teamcmd) .. [[;]], function(data)
MySQLite.begin()
for _, v in ipairs(data or {}) do
MySQLite.query([[DELETE FROM darkrp_position WHERE id = ]] .. v.id .. [[;]])
MySQLite.query([[DELETE FROM darkrp_jobspawn WHERE id = ]] .. v.id .. [[;]])
end
MySQLite.commit(callback)
end)
end
function DarkRP.retrieveTeamSpawnPos(t)
local isTeam = function(tbl) return RPExtraTeams[t].command == tbl.teamcmd end
local getPos = function(tbl) return Vector(tonumber(tbl.x), tonumber(tbl.y), tonumber(tbl.z)) end
return table.ClearKeys(fn.Map(getPos, fn.Filter(isTeam, teamSpawns)))
end

View File

@@ -0,0 +1,178 @@
DarkRP.storeJailPos = DarkRP.stub{
name = "storeJailPos",
description = "Store a jailposition from a player's location.",
parameters = {
{
name = "ply",
description = "The player of whom to get the location.",
type = "Player",
optional = false
},
{
name = "addingPos",
description = "Whether to reset all jailpositions and to create a new one here or to add it to the existing jailpos.",
type = "boolean",
optional = true
}
},
returns = {
},
metatable = DarkRP
}
DarkRP.setJailPos = DarkRP.stub{
name = "setJailPos",
description = "Remove all jail positions in this map and create a new one. To add a jailpos without removing previous ones use DarkRP.addJailPos. This jail position will be saved in the database.",
parameters = {
{
name = "pos",
description = "The position to set as jailpos.",
type = "Vector",
optional = false
}
},
returns = {
},
metatable = DarkRP
}
DarkRP.addJailPos = DarkRP.stub{
name = "addJailPos",
description = "Add a jail position to the map. This jail position will be saved in the database.",
parameters = {
{
name = "pos",
description = "The position to add as jailpos.",
type = "Vector",
optional = false
}
},
returns = {
},
metatable = DarkRP
}
DarkRP.retrieveJailPos = DarkRP.stub{
name = "retrieveJailPos",
description = "Retrieve a jail position.",
parameters = {
{
name = "index",
description = "Which jailpos to return.",
type = "number",
optional = true
}
},
returns = {
{
name = "pos",
description = "A jail position.",
type = "Vector"
}
},
metatable = DarkRP
}
DarkRP.jailPosCount = DarkRP.stub{
name = "jailPosCount",
description = "The amount of jail positions in the current map.",
parameters = {
},
returns = {
{
name = "count",
description = "The amount of jail positions in the current map.",
type = "number"
}
},
metatable = DarkRP
}
DarkRP.storeTeamSpawnPos = DarkRP.stub{
name = "storeTeamSpawnPos",
description = "Store a spawn position of a job in the database (replaces all other spawn positions).",
parameters = {
{
name = "team",
description = "The job to store the spawn position of.",
type = "number",
optional = false
},
{
name = "pos",
description = "The position to store.",
type = "Vector",
optional = false
}
},
returns = {
},
metatable = DarkRP
}
DarkRP.addTeamSpawnPos = DarkRP.stub{
name = "addTeamSpawnPos",
description = "Add a spawn position to the database. The position will not replace other spawn positions.",
parameters = {
{
name = "team",
description = "The job to store the spawn position of.",
type = "number",
optional = false
},
{
name = "pos",
description = "The position to store.",
type = "Vector",
optional = false
}
},
returns = {
},
metatable = DarkRP
}
DarkRP.removeTeamSpawnPos = DarkRP.stub{
name = "removeTeamSpawnPos",
description = "Remove a single spawn position.",
parameters = {
{
name = "team",
description = "The job to remove the spawn position of.",
type = "number",
optional = false
},
{
name = "pos",
description = "The position to remove.",
type = "Vector",
optional = false
}
},
returns = {
},
metatable = DarkRP
}
DarkRP.retrieveTeamSpawnPos = DarkRP.stub{
name = "retrieveTeamSpawnPos",
description = "Retrieve a random spawn position for a job.",
parameters = {
{
name = "team",
description = "The job to get a spawn position for.",
type = "number",
optional = false
}
},
returns = {
{
name = "pos",
description = "A nice spawn position.",
type = "Vector"
}
},
metatable = DarkRP
}

View File

@@ -0,0 +1,30 @@
local function storeJail(ply, add, hasAccess)
if not IsValid(ply) then return end
-- Admin or Chief can set the Jail Position
local Team = ply:Team()
if (RPExtraTeams[Team] and RPExtraTeams[Team].chief and GAMEMODE.Config.chiefjailpos) or hasAccess then
DarkRP.storeJailPos(ply, add)
else
local str = DarkRP.getPhrase("admin_only")
if GAMEMODE.Config.chiefjailpos then
str = DarkRP.getPhrase("chief_or") .. str
end
DarkRP.notify(ply, 1, 4, str)
end
end
local function JailPos(ply)
CAMI.PlayerHasAccess(ply, "DarkRP_AdminCommands", fp{storeJail, ply, false})
return ""
end
DarkRP.defineChatCommand("jailpos", JailPos)
DarkRP.defineChatCommand("setjailpos", JailPos)
local function AddJailPos(ply)
CAMI.PlayerHasAccess(ply, "DarkRP_AdminCommands", fp{storeJail, ply, true})
return ""
end
DarkRP.defineChatCommand("addjailpos", AddJailPos)

View File

@@ -0,0 +1,58 @@
local function SetSpawnPos(ply, args)
local pos = ply:GetPos()
local t
for k, v in pairs(RPExtraTeams) do
if args == v.command then
t = k
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("updated_spawnpos", v.name))
break
end
end
if t then
DarkRP.storeTeamSpawnPos(t, {pos.x, pos.y, pos.z})
else
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args)))
end
end
DarkRP.definePrivilegedChatCommand("setspawn", "DarkRP_AdminCommands", SetSpawnPos)
local function AddSpawnPos(ply, args)
local pos = ply:GetPos()
local t
for k, v in pairs(RPExtraTeams) do
if args == v.command then
t = k
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("created_spawnpos", v.name))
break
end
end
if t then
DarkRP.addTeamSpawnPos(t, {pos.x, pos.y, pos.z})
else
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args)))
end
end
DarkRP.definePrivilegedChatCommand("addspawn", "DarkRP_AdminCommands", AddSpawnPos)
local function RemoveSpawnPos(ply, args)
local t
for k, v in pairs(RPExtraTeams) do
if args == v.command then
t = k
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("remove_spawnpos", v.name))
break
end
end
if t then
DarkRP.removeTeamSpawnPos(t)
else
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args)))
end
end
DarkRP.definePrivilegedChatCommand("removespawn", "DarkRP_AdminCommands", RemoveSpawnPos)