This commit is contained in:
lifestorm
2024-08-04 23:54:45 +03:00
parent 8064ba84d8
commit 6a58f406b1
7522 changed files with 4011896 additions and 15 deletions

View File

@@ -0,0 +1,155 @@
--[[
| 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:KeyPress(client, key)
if (!IsFirstTimePredicted()) then return end
if (key != IN_ATTACK) then return end
local weapon = client:GetActiveWeapon()
if (!IsValid(weapon) or weapon:GetClass() != "weapon_physgun") then return end
if (!CAMI.PlayerHasAccess(client, "Helix - Manage Clientside Props")) then return end
-- Get the clientside entity that the player is looking at
local traceLength = 0
local targetEntity
local aimVector = client:GetAimVector()
local trace = {
start = client:GetShootPos(),
endpos = client:GetShootPos(),
filter = client
}
while (traceLength < 250) do -- Don't want it to go forever
if (IsValid(targetEntity)) then break end
trace.endpos = trace.start + aimVector * traceLength
for _, csent in ipairs(self.activeClientProps) do
if (csent:GetPos():DistToSqr(trace.endpos) > 62500) then continue end
local vMin, vMax = csent:GetRenderBounds()
local vPos = csent:WorldToLocal(trace.endpos)
if (!vPos:WithinAABox(vMax, vMin)) then continue end
targetEntity = csent
break
end
traceLength = traceLength + 1
end
if (!IsValid(targetEntity)) then return end
net.Start("ixClientProps.RecreateProp")
net.WriteVector(targetEntity:GetPos())
net.SendToServer()
end
local frameInterval = 5
function PLUGIN:Think()
self.coroutine = self.coroutine and coroutine.status(self.coroutine) != "dead" and self.coroutine or coroutine.create(function()
while (true) do
local maxPerFrame = ix.option.Get("csentRenderSpeed", 50)
local i = 0
for _, data in ipairs(self.clientProps) do
self:ManageClientsideProp(data)
i = i + 1
if (i == maxPerFrame) then
i = 0
coroutine.yield()
end
end
coroutine.yield()
end
end)
if (FrameNumber() % frameInterval != 0) then return end
local succ, err = coroutine.resume(self.coroutine)
if (succ) then return end
ErrorNoHalt(err)
end
function PLUGIN:InitPostEntity()
net.Start("ixClientProps.RequestProps")
net.SendToServer()
end
net.Receive("ixClientProps.NetworkProp", function()
local propData = net.ReadTable()
PLUGIN.clientProps[#PLUGIN.clientProps + 1] = propData
end)
net.Receive("ixClientProps.RecreateProp", function()
local position = net.ReadVector()
for k, data in ipairs(PLUGIN.clientProps) do
if (!data.position:IsEqualTol(position, 0.1)) then continue end
table.remove(PLUGIN.clientProps, k)
break
end
for k, csent in ipairs(PLUGIN.activeClientProps) do
if (!csent:GetPos():IsEqualTol(position, 0.1)) then continue end
csent:Remove()
table.remove(PLUGIN.activeClientProps, k)
break
end
end)
net.Receive("ixClientProps.MassRemoveProps", function()
local position = net.ReadVector()
local radius = net.ReadUInt(16)
local newTable = {}
for k, data in ipairs(PLUGIN.clientProps) do
if (data.position:Distance(position) <= radius) then continue end
newTable[#newTable + 1] = data
end
PLUGIN.clientProps = newTable
local newActiveTable = {}
for k, csent in ipairs(PLUGIN.activeClientProps) do
if (csent:GetPos():Distance(position) <= radius) then
csent:Remove()
else
newActiveTable[#newActiveTable + 1] = csent
end
end
PLUGIN.activeClientProps = newActiveTable
end)
express.Receive("ixClientProps.RequestProps", function(props)
PLUGIN.clientProps = props
end)

View File

@@ -0,0 +1,42 @@
--[[
| 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/
--]]
PLUGIN.activeClientProps = PLUGIN.activeClientProps or {}
function PLUGIN:ManageClientsideProp(csentData)
if (NikNaks.PVS.IsPositionVisible(csentData.position, LocalPlayer():EyePos())) then
for _, activeProp in ipairs(self.activeClientProps) do
if (csentData.position:IsEqualTol(activeProp:GetPos(), 0.1)) then return end -- Ensure we don't have a duplicate
end
local clientProp = ClientsideModel(csentData.model)
clientProp:SetPos(csentData.position)
clientProp:SetAngles(csentData.angles)
clientProp:SetSkin(csentData.skin)
clientProp:SetColor(csentData.color)
clientProp:SetRenderMode(RENDERMODE_TRANSCOLOR)
clientProp:SetMaterial(csentData.material)
clientProp:Spawn()
self.activeClientProps[#self.activeClientProps + 1] = clientProp
else
for k, activeProp in ipairs(self.activeClientProps) do
if (!csentData.position:IsEqualTol(activeProp:GetPos(), 0.1)) then continue end
activeProp:Remove()
table.remove(self.activeClientProps, k)
return
end
end
end

View File

@@ -0,0 +1,133 @@
--[[
| 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/
--]]
require("niknaks")
local PLUGIN = PLUGIN
PLUGIN.name = "Clientside Props"
PLUGIN.description = "Adds a way to convert server props to clientside props for performance reasons."
PLUGIN.author = "Aspect™"
PLUGIN.clientProps = PLUGIN.clientProps or {}
ix.util.Include("cl_hooks.lua")
ix.util.Include("cl_plugin.lua")
ix.util.Include("sv_hooks.lua")
ix.util.Include("sv_plugin.lua")
CAMI.RegisterPrivilege({
Name = "Helix - Manage Clientside Props",
MinAccess = "admin"
})
ix.option.Add("csentRenderSpeed", ix.type.number, 50, {
category = "performance",
min = 1,
max = 500
})
ix.lang.AddTable("english", {
optCsentRenderSpeed = "Clientside Prop Render Speed",
optdCsentRenderSpeed = "How many clientside props should be calcualted every frame. Lower values = more FPS, but slower, higher values = less FPS, but faster.",
cmdRemoveClientProps = "Remove all clientside props in a radius around you."
})
ix.command.Add("RemoveClientProps", {
description = "@cmdRemoveClientProps",
adminOnly = true,
arguments = {
ix.type.number
},
OnRun = function(self, client, radius)
if (radius < 0) then
client:Notify("Radius must be a positive number!")
return
end
local newTable = {}
for k, propData in ipairs(PLUGIN.clientProps) do
if (propData.position:Distance(client:GetPos()) <= radius) then continue end
newTable[#newTable + 1] = propData
end
PLUGIN.clientProps = newTable
net.Start("ixClientProps.MassRemoveProps")
net.WriteVector(client:GetPos())
net.WriteUInt(radius, 16)
net.Broadcast()
client:Notify("Removed all clientside props in a radius of " .. radius .. " units.")
end
})
local PERSISTENCE = ix.plugin.Get("persistence")
properties.Add("clientprop", {
MenuLabel = "Convert to Client Prop",
Order = 400,
MenuIcon = "icon16/contrast_low.png",
Filter = function(self, entity, client)
return entity:GetClass() == "prop_physics" and CAMI.PlayerHasAccess(client, "Helix - Manage Clientside Props")
end,
Action = function(self, entity)
self:MsgStart()
net.WriteEntity(entity)
self:MsgEnd()
end,
Receive = function(self, length, client)
local entity = net.ReadEntity()
if (!IsValid(entity)) then return end
if (!self:Filter(entity, client)) then return end
if (!entity:TestPVS(client)) then
client:Notify("That prop cannot be converted because its origin is outside the world!")
return
end
-- Unpersist it if it's persisted
if (PERSISTENCE) then
for k, v in ipairs(PERSISTENCE.stored) do
if (v == entity) then
table.remove(PERSISTENCE.stored, k)
break
end
end
entity:SetNetVar("Persistent", false)
end
local propData = {
position = entity:GetPos(),
angles = entity:GetAngles(),
model = entity:GetModel(),
skin = entity:GetSkin(),
color = entity:GetColor(),
material = entity:GetMaterial()
}
entity:Remove()
PLUGIN.clientProps[#PLUGIN.clientProps + 1] = propData
PLUGIN:NetworkProp(propData)
end
})

View File

@@ -0,0 +1,59 @@
--[[
| 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:LoadData()
self.clientProps = self:GetData() or {}
end
function PLUGIN:SaveData()
self:SetData(self.clientProps)
end
net.Receive("ixClientProps.RecreateProp", function(_, client)
if (!CAMI.PlayerHasAccess(client, "Helix - Manage Clientside Props")) then return end
local position = net.ReadVector()
for k, propData in ipairs(PLUGIN.clientProps) do
if (!propData.position:IsEqualTol(position, 0.1)) then continue end
local entity = ents.Create("prop_physics")
entity:SetModel(propData.model)
entity:SetPos(position)
entity:SetAngles(propData.angles)
entity:SetSkin(propData.skin)
entity:SetColor(propData.color)
entity:SetRenderMode(RENDERMODE_TRANSCOLOR)
entity:SetMaterial(propData.material)
entity:Spawn()
local physicsObject = entity:GetPhysicsObject()
if (IsValid(physicsObject)) then
physicsObject:EnableMotion(false)
end
table.remove(PLUGIN.clientProps, k)
net.Start("ixClientProps.RecreateProp")
net.WriteVector(position)
net.Broadcast()
break
end
end)
net.Receive("ixClientProps.RequestProps", function(_, client)
express.Send("ixClientProps.RequestProps", PLUGIN.clientProps, client)
end)

View File

@@ -0,0 +1,21 @@
--[[
| 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/
--]]
util.AddNetworkString("ixClientProps.NetworkProp")
util.AddNetworkString("ixClientProps.RecreateProp")
util.AddNetworkString("ixClientProps.RequestProps")
util.AddNetworkString("ixClientProps.MassRemoveProps")
function PLUGIN:NetworkProp(propData)
net.Start("ixClientProps.NetworkProp")
net.WriteTable(propData)
net.Broadcast()
end