mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 13:53:45 +03:00
Upload
This commit is contained in:
167
gamemodes/ixhl2rp/plugins/combineutilities/teams/cl_teams.lua
Normal file
167
gamemodes/ixhl2rp/plugins/combineutilities/teams/cl_teams.lua
Normal file
@@ -0,0 +1,167 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
function PLUGIN:UpdateTeamMenu()
|
||||
if (IsValid(ix.gui.protectionTeams)) then
|
||||
ix.gui.protectionTeams.memberScroll:Clear()
|
||||
ix.gui.protectionTeams.teamScroll:Clear()
|
||||
|
||||
if ix.gui.protectionTeams.leaveButton then
|
||||
ix.gui.protectionTeams.leaveButton:Remove()
|
||||
end
|
||||
|
||||
if ix.gui.protectionTeams.createButton then
|
||||
ix.gui.protectionTeams.createButton:Remove()
|
||||
end
|
||||
|
||||
if ix.gui.protectionTeams.joinButton then
|
||||
ix.gui.protectionTeams.joinButton:Remove()
|
||||
end
|
||||
|
||||
ix.gui.protectionTeams.CreateButtons()
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:CreateTeam(client, index)
|
||||
self.teams[index] = {
|
||||
owner = client,
|
||||
members = {client}
|
||||
}
|
||||
|
||||
hook.Run("OnCreateTeam", client, index)
|
||||
end
|
||||
|
||||
function PLUGIN:ReassignTeam(index, newIndex)
|
||||
local curTeam = self.teams[index]
|
||||
|
||||
self:DeleteTeam(index)
|
||||
self:CreateTeam(curTeam["owner"], newIndex)
|
||||
self.teams[newIndex]["members"] = curTeam["members"]
|
||||
|
||||
hook.Run("OnReassignTeam", index, newIndex)
|
||||
end
|
||||
|
||||
function PLUGIN:DeleteTeam(index)
|
||||
self.teams[index] = nil
|
||||
hook.Run("OnDeleteTeam", index)
|
||||
end
|
||||
|
||||
function PLUGIN:LeaveTeam(client, index)
|
||||
if table.HasValue(self.teams[index]["members"], client) then
|
||||
table.RemoveByValue(self.teams[index]["members"], client)
|
||||
end
|
||||
|
||||
hook.Run("OnLeaveTeam", client, index)
|
||||
end
|
||||
|
||||
function PLUGIN:JoinTeam(client, index)
|
||||
if !index or index and !self.teams[index] then return end
|
||||
if !self.teams[index]["members"] then return end
|
||||
|
||||
table.insert(self.teams[index]["members"], client)
|
||||
|
||||
hook.Run("OnJoinTeam", client, index)
|
||||
end
|
||||
|
||||
function PLUGIN:SetTeamOwner(index, client)
|
||||
if !self.teams[index] then return end
|
||||
|
||||
self.teams[index]["owner"] = client
|
||||
|
||||
hook.Run("OnSetTeamOwner", client, index)
|
||||
end
|
||||
|
||||
-- Hooks
|
||||
function PLUGIN:OnCreateTeam(client, index)
|
||||
self:UpdateTeamMenu()
|
||||
end
|
||||
|
||||
function PLUGIN:OnReassignTeam(index, newIndex)
|
||||
self:UpdateTeamMenu()
|
||||
end
|
||||
|
||||
function PLUGIN:OnDeleteTeam(index)
|
||||
self:UpdateTeamMenu()
|
||||
end
|
||||
|
||||
function PLUGIN:OnLeaveTeam(client, index)
|
||||
self:UpdateTeamMenu()
|
||||
end
|
||||
|
||||
function PLUGIN:OnJoinTeam(client, index)
|
||||
self:UpdateTeamMenu()
|
||||
end
|
||||
|
||||
function PLUGIN:OnSetTeamOwner(client, index)
|
||||
self:UpdateTeamMenu()
|
||||
end
|
||||
|
||||
function PLUGIN:PopulateCharacterInfo(client, character, container)
|
||||
if (LocalPlayer():HasActiveCombineMask() and client:GetNetVar("ProtectionTeam")) then
|
||||
local curTeam = container:AddRowAfter("name", "curTeam")
|
||||
curTeam:SetText(L("TeamStatus", client:GetNetVar("ProtectionTeam"), client:GetNetVar("ProtectionTeamOwner") and L("TeamOwnerStatus") or L("TeamMemberStatus")))
|
||||
curTeam:SetBackgroundColor(client:GetNetVar("ProtectionTeamOwner") and Color(50,150,100) or Color(50,100,150))
|
||||
end
|
||||
end
|
||||
|
||||
net.Receive("ixPTSync", function()
|
||||
local bTeams = net.ReadBool()
|
||||
|
||||
if (!bTeams) then
|
||||
PLUGIN.teams = {}
|
||||
return
|
||||
end
|
||||
|
||||
local teams = net.ReadTable()
|
||||
PLUGIN.teams = teams or {}
|
||||
end)
|
||||
|
||||
net.Receive("ixPTCreate", function()
|
||||
local index = net.ReadUInt(8)
|
||||
local client = net.ReadEntity()
|
||||
|
||||
PLUGIN:CreateTeam(client, index)
|
||||
end)
|
||||
|
||||
net.Receive("ixPTDelete", function()
|
||||
local index = net.ReadUInt(8)
|
||||
|
||||
PLUGIN:DeleteTeam(index)
|
||||
end)
|
||||
|
||||
net.Receive("ixPTLeave", function()
|
||||
local index = net.ReadUInt(8)
|
||||
local client = net.ReadEntity()
|
||||
|
||||
PLUGIN:LeaveTeam(client, index)
|
||||
end)
|
||||
|
||||
net.Receive("ixPTJoin", function()
|
||||
local index = net.ReadUInt(8)
|
||||
local client = net.ReadEntity()
|
||||
|
||||
PLUGIN:JoinTeam(client, index)
|
||||
end)
|
||||
|
||||
net.Receive("ixPTOwner", function()
|
||||
local index = net.ReadUInt(8)
|
||||
local client = net.ReadEntity()
|
||||
|
||||
PLUGIN:SetTeamOwner(index, client)
|
||||
end)
|
||||
|
||||
net.Receive("ixPTReassign", function()
|
||||
local index = net.ReadUInt(8)
|
||||
local newIndex = net.ReadUInt(8)
|
||||
|
||||
PLUGIN:ReassignTeam(index, newIndex)
|
||||
end)
|
||||
166
gamemodes/ixhl2rp/plugins/combineutilities/teams/sh_teams.lua
Normal file
166
gamemodes/ixhl2rp/plugins/combineutilities/teams/sh_teams.lua
Normal file
@@ -0,0 +1,166 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
ix.util.IncludeDir("ixhl2rp/plugins/combineutilities/teams/derma", true)
|
||||
|
||||
PLUGIN.teams = {}
|
||||
|
||||
function PLUGIN:GetReceivers()
|
||||
local recievers = {}
|
||||
|
||||
for _, client in pairs(player.GetAll()) do
|
||||
if (client:IsCombine()) then
|
||||
table.insert(recievers, client)
|
||||
end
|
||||
end
|
||||
|
||||
return recievers
|
||||
end
|
||||
|
||||
ix.command.Add("PTCreate", {
|
||||
description = "@cmdPTCreate",
|
||||
arguments = bit.bor(ix.type.number, ix.type.optional),
|
||||
OnCheckAccess = function(self, client)
|
||||
return client:IsCombine()
|
||||
end,
|
||||
OnRun = function(self, client, index)
|
||||
if (!client:IsCombine()) then
|
||||
return "@CannotUseTeamCommands"
|
||||
end
|
||||
|
||||
if (!index) then
|
||||
return client:RequestString("@cmdPTCreate", "@cmdCreatePTDesc", function(text) ix.command.Run(client, "PTCreate", {text}) end, "")
|
||||
end
|
||||
|
||||
return PLUGIN:CreateTeam(client, index)
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("PTJoin", {
|
||||
description = "@cmdPTJoin",
|
||||
arguments = ix.type.number,
|
||||
OnCheckAccess = function(self, client)
|
||||
return client:IsCombine()
|
||||
end,
|
||||
OnRun = function(self, client, index)
|
||||
if (!client:IsCombine()) then
|
||||
return "@CannotUsePTCommands"
|
||||
end
|
||||
|
||||
return PLUGIN:JoinTeam(client, index)
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("PTLeave", {
|
||||
description = "@cmdPTLeave",
|
||||
OnCheckAccess = function(self, client)
|
||||
return client:IsCombine()
|
||||
end,
|
||||
OnRun = function(self, client)
|
||||
if (!client:IsCombine()) then
|
||||
return "@CannotUsePTCommands"
|
||||
end
|
||||
|
||||
return PLUGIN:LeaveTeam(client)
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("PTLead", {
|
||||
description = "@cmdPTLead",
|
||||
arguments = bit.bor(ix.type.player, ix.type.optional),
|
||||
OnCheckAccess = function(self, client)
|
||||
return client:IsCombine()
|
||||
end,
|
||||
OnRun = function(self, client, target)
|
||||
if (!client:IsCombine()) then
|
||||
return "@CannotUseTeamCommands"
|
||||
end
|
||||
|
||||
if (target == client or !target) then
|
||||
target = client
|
||||
end
|
||||
|
||||
local index = target:GetNetVar("ProtectionTeam")
|
||||
|
||||
if (!PLUGIN.teams[index]) then return "@TargetNoCurrentTeam" end
|
||||
|
||||
if (!client:IsDispatch()) then
|
||||
if (client:GetNetVar("ProtectionTeam") != target:GetNetVar("ProtectionTeam")) then return "@TargetNotSameTeam" end
|
||||
|
||||
if (PLUGIN.teams[index]["owner"]) then
|
||||
if (target == client) then return "@TeamAlreadyHasOwner" end
|
||||
if (!client:GetNetVar("ProtectionTeamOwner")) then return "@CannotPromoteTeamMembers" end
|
||||
end
|
||||
end
|
||||
|
||||
if ((target == client or !target) and (PLUGIN:SetTeamOwner(index, target))) then
|
||||
return "@TeamOwnerAssume"
|
||||
end
|
||||
|
||||
return PLUGIN:SetTeamOwner(index, target)
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("PTKick", {
|
||||
description = "@cmdPTKick",
|
||||
arguments = ix.type.player,
|
||||
OnCheckAccess = function(self, client)
|
||||
return client:IsCombine()
|
||||
end,
|
||||
OnRun = function(self, client, target)
|
||||
if (!client:IsCombine()) then
|
||||
return "@CannotUseTeamCommands"
|
||||
end
|
||||
|
||||
local index = target:GetNetVar("ProtectionTeam")
|
||||
|
||||
if (!PLUGIN.teams[index]) then return "@TargetNoCurrentTeam" end
|
||||
|
||||
if (client:GetNetVar("ProtectionTeam") != target:GetNetVar("ProtectionTeam") and !client:IsDispatch()) then return "@TargetNotSameTeam" end
|
||||
|
||||
if (!client:GetNetVar("ProtectionTeamOwner") and !client:IsDispatch()) then return "@CannotKickTeamMembers" end
|
||||
|
||||
PLUGIN:LeaveTeam(target)
|
||||
|
||||
return "@KickedFromTeam", target:GetName()
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("PTReassign", {
|
||||
description = "@cmdPTReassign",
|
||||
arguments = {bit.bor(ix.type.number, ix.type.optional), bit.bor(ix.type.number, ix.type.optional)},
|
||||
OnCheckAccess = function(self, client)
|
||||
return client:IsCombine()
|
||||
end,
|
||||
OnRun = function(self, client, newIndex, oldIndex)
|
||||
if (!client:IsCombine()) then
|
||||
return "@CannotUseTeamCommands"
|
||||
end
|
||||
|
||||
local index = client:GetNetVar("ProtectionTeam")
|
||||
|
||||
if (!oldIndex and index) then
|
||||
oldIndex = index
|
||||
end
|
||||
|
||||
if (!client:IsDispatch()) then
|
||||
if (!PLUGIN.teams[oldIndex]) then return "@NoCurrentTeam" end
|
||||
if (!client:GetNetVar("ProtectionTeamOwner")) then return "@CannotReassignTeamIndex" end
|
||||
end
|
||||
|
||||
if (newIndex and oldIndex) then
|
||||
return PLUGIN:ReassignTeam(oldIndex, newIndex)
|
||||
else
|
||||
return client:RequestString("@cmdPTReassign", "@cmdReassignPTDesc", function(text) ix.command.Run(client, "PTReassign", {text, oldIndex}) end, "")
|
||||
end
|
||||
end
|
||||
})
|
||||
230
gamemodes/ixhl2rp/plugins/combineutilities/teams/sv_teams.lua
Normal file
230
gamemodes/ixhl2rp/plugins/combineutilities/teams/sv_teams.lua
Normal file
@@ -0,0 +1,230 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
util.AddNetworkString("ixPTSync")
|
||||
util.AddNetworkString("ixPTCreate")
|
||||
util.AddNetworkString("ixPTDelete")
|
||||
util.AddNetworkString("ixPTJoin")
|
||||
util.AddNetworkString("ixPTLeave")
|
||||
util.AddNetworkString("ixPTOwner")
|
||||
util.AddNetworkString("ixPTReassign")
|
||||
|
||||
function PLUGIN:CreateTeam(client, index, bNetworked, bNoNotif)
|
||||
if (IsValid(client) and client:GetNetVar("ProtectionTeam")) then
|
||||
return "@AlreadyHasTeam"
|
||||
end
|
||||
|
||||
if (self.teams[index]) then
|
||||
return "@TeamAlreadyExists", tostring(index)
|
||||
end
|
||||
|
||||
if (index > 99 or index < 1) then
|
||||
return "@TeamMustClamp"
|
||||
end
|
||||
|
||||
self.teams[index] = {
|
||||
owner = client,
|
||||
members = {client}
|
||||
}
|
||||
|
||||
if (IsValid(client)) then
|
||||
client:SetNetVar("ProtectionTeam", index)
|
||||
client:SetNetVar("ProtectionTeamOwner", true)
|
||||
end
|
||||
|
||||
if (!bNetworked) then
|
||||
net.Start("ixPTCreate")
|
||||
net.WriteUInt(index, 8)
|
||||
net.WriteEntity(client)
|
||||
net.Send(self:GetReceivers())
|
||||
end
|
||||
|
||||
hook.Run("OnCreateTeam", client, index)
|
||||
|
||||
if (!bNoNotif) then
|
||||
ix.combineNotify:AddNotification("NTC:// " .. client:GetCombineTag() .. " has established Protection-Team " .. index, Color(0, 145, 255, 255))
|
||||
end
|
||||
|
||||
return "@TeamCreated", tostring(index)
|
||||
end
|
||||
|
||||
function PLUGIN:ReassignTeam(index, newIndex, bNetworked)
|
||||
if (newIndex > 99 or newIndex < 1) then
|
||||
return "@TeamMustClamp"
|
||||
end
|
||||
|
||||
if (self.teams[newIndex]) then
|
||||
return "@TeamAlreadyExists", tostring(index)
|
||||
end
|
||||
|
||||
local curTeam = self.teams[index]
|
||||
|
||||
self:DeleteTeam(index, true, true)
|
||||
|
||||
self:CreateTeam(curTeam["owner"], newIndex, true, true)
|
||||
|
||||
self.teams[newIndex]["members"] = curTeam["members"]
|
||||
|
||||
for _, client in pairs(curTeam["members"]) do
|
||||
client:SetNetVar("ProtectionTeam", newIndex)
|
||||
end
|
||||
|
||||
if (!bNetworked) then
|
||||
net.Start("ixPTReassign")
|
||||
net.WriteUInt(index, 8)
|
||||
net.WriteUInt(newIndex, 8)
|
||||
net.Send(self:GetReceivers())
|
||||
end
|
||||
|
||||
hook.Run("OnReassignTeam", index, newIndex)
|
||||
|
||||
ix.combineNotify:AddNotification("NTC:// Protection-Team " .. index .. " re-assigned as Protection-Team " .. newIndex, Color(0, 145, 255, 255))
|
||||
|
||||
return "@TeamReassigned", tostring(index), tostring(newIndex)
|
||||
end
|
||||
|
||||
function PLUGIN:SetTeamOwner(index, client, bNetworked)
|
||||
local curOwner = self.teams[index]["owner"]
|
||||
|
||||
if (IsValid(curOwner)) then
|
||||
curOwner:SetNetVar("ProtectionTeamOwner", nil)
|
||||
end
|
||||
|
||||
self.teams[index]["owner"] = client
|
||||
|
||||
if (IsValid(client)) then
|
||||
client:SetNetVar("ProtectionTeamOwner", true)
|
||||
end
|
||||
|
||||
if (!bNetworked) then
|
||||
net.Start("ixPTOwner")
|
||||
net.WriteUInt(index, 8)
|
||||
net.WriteEntity(client)
|
||||
net.Send(self:GetReceivers())
|
||||
end
|
||||
|
||||
hook.Run("OnSetTeamOwner", client, index)
|
||||
|
||||
if (IsValid(client)) then
|
||||
ix.combineNotify:AddNotification("NTC:// " .. client:GetCombineTag() .. " designated as Protection-Team " .. index .. " Leader", Color(0, 145, 255, 255))
|
||||
return "@TeamOwnerSet", client:GetName()
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:DeleteTeam(index, bNetworked, bNoNotif)
|
||||
self.teams[index] = nil
|
||||
|
||||
for _, client in pairs(self:GetReceivers()) do
|
||||
if (client:GetNetVar("ProtectionTeam") == index) then
|
||||
client:SetNetVar("ProtectionTeam", nil)
|
||||
|
||||
if (client:GetNetVar("ProtectionTeamOwner")) then
|
||||
client:SetNetVar("ProtectionTeamOwner", nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (!bNetworked) then
|
||||
net.Start("ixPTDelete")
|
||||
net.WriteUInt(index, 8)
|
||||
net.Send(self:GetReceivers())
|
||||
end
|
||||
|
||||
if (!bNoNotif) then
|
||||
ix.combineNotify:AddNotification("NTC:// Protection-Team " .. index .. " has been disbanded", Color(0, 145, 255, 255))
|
||||
end
|
||||
|
||||
hook.Run("OnDeleteTeam", index)
|
||||
end
|
||||
|
||||
function PLUGIN:JoinTeam(client, index, bNetworked)
|
||||
if (client:GetNetVar("ProtectionTeam")) then
|
||||
return "@TeamMustLeave"
|
||||
end
|
||||
|
||||
if (index > 99 or index < 1) then
|
||||
return "@TeamMustClamp"
|
||||
end
|
||||
|
||||
if (!self.teams[index]) then
|
||||
return "@TeamNonExistent", tostring(index)
|
||||
end
|
||||
|
||||
table.insert(self.teams[index]["members"], client)
|
||||
|
||||
client:SetNetVar("ProtectionTeam", index)
|
||||
|
||||
if (!bNetworked) then
|
||||
net.Start("ixPTJoin")
|
||||
net.WriteUInt(index, 8)
|
||||
net.WriteEntity(client)
|
||||
net.Send(self:GetReceivers())
|
||||
end
|
||||
|
||||
hook.Run("OnJoinTeam", client, index)
|
||||
|
||||
ix.combineNotify:AddNotification("NTC:// " .. client:GetCombineTag() .. " has interlocked into Protection-Team " .. index, Color(0, 145, 255, 255))
|
||||
|
||||
return "@JoinedTeam", index
|
||||
end
|
||||
|
||||
function PLUGIN:LeaveTeam(client, bNetworked)
|
||||
if (!client:GetNetVar("ProtectionTeam")) then
|
||||
return "@NoCurrentTeam"
|
||||
end
|
||||
|
||||
local index = client:GetNetVar("ProtectionTeam")
|
||||
local curTeam = self.teams[index]
|
||||
|
||||
if (curTeam) then
|
||||
table.RemoveByValue(self.teams[index]["members"], client)
|
||||
|
||||
client:SetNetVar("ProtectionTeam", nil)
|
||||
|
||||
if (!bNetworked) then
|
||||
net.Start("ixPTLeave")
|
||||
net.WriteUInt(index, 8)
|
||||
net.WriteEntity(client)
|
||||
net.Send(self:GetReceivers())
|
||||
end
|
||||
|
||||
if (client:GetNetVar("ProtectionTeamOwner")) then
|
||||
self:SetTeamOwner(index, nil)
|
||||
end
|
||||
|
||||
hook.Run("OnLeaveTeam", client, index)
|
||||
|
||||
ix.combineNotify:AddNotification("NTC:// " .. client:GetCombineTag() .. " has detached from Protection-Team " .. index, Color(0, 145, 255, 255))
|
||||
|
||||
return "@LeftTeam", index
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:Tick()
|
||||
local curTime = CurTime()
|
||||
|
||||
if (!self.tick or self.tick < curTime) then
|
||||
self.tick = curTime + 30
|
||||
|
||||
for index, teamTbl in pairs(self.teams) do
|
||||
if (table.IsEmpty(teamTbl["members"])) then
|
||||
self:DeleteTeam(index)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerDisconnected(client)
|
||||
if (client:GetNetVar("ProtectionTeam")) then
|
||||
self:LeaveTeam(client)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user