mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-18 22:23:46 +03:00
Upload
This commit is contained in:
117
lua/pac3/extra/server/contraption.lua
Normal file
117
lua/pac3/extra/server/contraption.lua
Normal file
@@ -0,0 +1,117 @@
|
||||
--[[
|
||||
| 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("pac_to_contraption")
|
||||
|
||||
local receieved = {}
|
||||
|
||||
local function spawn(val,ply)
|
||||
local model = val.mdl
|
||||
|
||||
if not model or model == "" or model:find("\n") or model:find("..", 1, true) then
|
||||
return
|
||||
end
|
||||
|
||||
pace.suppress_prop_spawn = true
|
||||
local ok = hook.Run("PlayerSpawnProp", ply, model)
|
||||
pace.suppress_prop_spawn = false
|
||||
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
|
||||
local ent = ents.Create("prop_physics")
|
||||
|
||||
SafeRemoveEntity(receieved[val.id])
|
||||
receieved[val.id] = ent
|
||||
|
||||
ent:SetModel(model)-- insecure
|
||||
ent:SetPos(val.pos)-- insecure
|
||||
ent:SetAngles(val.ang)-- insecure
|
||||
ent:SetSkin(val.skn)
|
||||
ent:SetMaterial(val.mat) -- insecure
|
||||
ent:Spawn()
|
||||
ent:SetHealth(9999999)
|
||||
ent:SetColor(val.clr)
|
||||
ent:SetRenderMode( RENDERMODE_TRANSCOLOR )
|
||||
|
||||
hook.Run("PlayerSpawnedProp", ply, model, ent)
|
||||
|
||||
if ent.CPPISetOwner and not (ent:CPPIGetOwner() or NULL):IsValid() then
|
||||
ent:CPPISetOwner(ply)
|
||||
end
|
||||
|
||||
local phys = ent:GetPhysicsObject()
|
||||
|
||||
if phys:IsValid() then
|
||||
phys:EnableMotion(false)
|
||||
|
||||
local maxabs = 150
|
||||
|
||||
val.scale.X = math.Clamp(val.scale.X,-maxabs,maxabs)
|
||||
val.scale.Y = math.Clamp(val.scale.Y,-maxabs,maxabs)
|
||||
val.scale.Z = math.Clamp(val.scale.Z,-maxabs,maxabs)
|
||||
|
||||
for i=0, ent:GetBoneCount()-1 do
|
||||
ent:ManipulateBoneScale( i, val.scale )
|
||||
end
|
||||
|
||||
undo.Create("Prop")
|
||||
undo.SetPlayer(ply)
|
||||
undo.AddEntity(ent)
|
||||
undo.Finish("Prop ("..tostring(model)..")")
|
||||
|
||||
ply:AddCleanup("props", ent)
|
||||
|
||||
gamemode.Call("PlayerSpawnedProp", ply, model, ent)
|
||||
else
|
||||
ent:Remove()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local pac_to_contraption_allow = CreateConVar("pac_to_contraption_allow", "1")
|
||||
local max_contraptions = CreateConVar("pac_max_contraption_entities", 60)
|
||||
|
||||
pace.PCallNetReceive(net.Receive, "pac_to_contraption", function(len, ply)
|
||||
if not pac_to_contraption_allow:GetBool() then
|
||||
net.Start("pac_submit_acknowledged")
|
||||
net.WriteBool(false)
|
||||
net.WriteString("This server does not allow spawning PAC contraptions.")
|
||||
net.Send(ply)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if len < 64 then return end
|
||||
|
||||
local allowed = pac.RatelimitPlayer( ply, "pac_to_contraption", 5, 1, {"Player ", ply, " is spamming pac_to_contraption!"} )
|
||||
if not allowed then return end
|
||||
|
||||
local data = net.ReadTable()
|
||||
|
||||
local max = max_contraptions:GetInt()
|
||||
local count = table.Count(data)
|
||||
if count > max then
|
||||
net.Start("pac_submit_acknowledged")
|
||||
net.WriteBool(false)
|
||||
net.WriteString("You can only spawn " .. max .. " props at a time!")
|
||||
net.Send(ply)
|
||||
|
||||
pac.Message(ply, " might have tried to crash the server by attempting to spawn ", count, " entities with the contraption system!")
|
||||
return
|
||||
end
|
||||
|
||||
pac.Message("Spawning contraption by ", ply, " with ", count, " entities")
|
||||
|
||||
for key, val in pairs(data) do
|
||||
spawn(val,ply)
|
||||
end
|
||||
end)
|
||||
16
lua/pac3/extra/server/init.lua
Normal file
16
lua/pac3/extra/server/init.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
pacx = pacx or {}
|
||||
|
||||
include("pac3/extra/shared/init.lua")
|
||||
|
||||
include("contraption.lua")
|
||||
include("map_outfit.lua")
|
||||
163
lua/pac3/extra/server/map_outfit.lua
Normal file
163
lua/pac3/extra/server/map_outfit.lua
Normal file
@@ -0,0 +1,163 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
pacx.SpawnedMapEntities = pacx.SpawnedMapEntities or {}
|
||||
|
||||
local VEC0 = Vector(0, 0, 0)
|
||||
local ANG0 = Angle(0, 0, 0)
|
||||
local VEC1 = Vector(1, 1, 1)
|
||||
|
||||
local function tocolor(v, a) return Color(v.x, v.y, v.z, a) end
|
||||
|
||||
local function has_clip(part)
|
||||
for key, part in pairs(part.children) do
|
||||
if part.self.ClassName == "clip" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function set_pos(ent, data, parent)
|
||||
local ppos = Vector()
|
||||
local pang = Angle()
|
||||
|
||||
if parent:IsValid() then
|
||||
ppos = parent:GetPos()
|
||||
pang = parent:GetAngles()
|
||||
end
|
||||
|
||||
local pos, ang = LocalToWorld((data.Position or VEC0)+ (data.PositionOffset or VEC0), (data.Angles or ANG0) + (data.AngleOffset or ANG0), ppos, pang)
|
||||
|
||||
ent:SetPos(pos)
|
||||
ent:SetAngles(ang)
|
||||
end
|
||||
|
||||
local spawn_handlers = {
|
||||
model = function(part, parent)
|
||||
if
|
||||
(not part.self.Alpha or part.self.Alpha ~= 0) and
|
||||
(not part.self.Size or part.self.Size ~= 0) and
|
||||
(not part.self.Scale or part.self.Scale ~= VEC0)
|
||||
then
|
||||
SafeRemoveEntity(pacx.SpawnedMapEntities[part.self.UniqueID])
|
||||
|
||||
local ent = ents.Create("prop_dynamic")
|
||||
|
||||
local data = part.self
|
||||
|
||||
ent:SetModel(data.Model or "models/dav0r/hoverball.mdl")
|
||||
|
||||
local c = data.Color
|
||||
|
||||
if c and data.Brightness then
|
||||
c = c * data.Brightness
|
||||
end
|
||||
|
||||
if data.Color then ent:SetColor(tocolor(c, (data.Alpha or 1) * 255)) end
|
||||
if data.Skin then ent:SetSkin(data.Skin) end
|
||||
if data.Material then ent:SetMaterial(data.Material) end
|
||||
if data.Size then ent:SetModelScale(data.Size, 0) end
|
||||
ent:PhysicsInit(SOLID_VPHYSICS)
|
||||
|
||||
set_pos(ent, part.self, parent)
|
||||
|
||||
ent:Spawn()
|
||||
|
||||
pacx.SpawnedMapEntities[part.self.UniqueID] = ent
|
||||
|
||||
return ent
|
||||
end
|
||||
end,
|
||||
|
||||
light = function(part, parent)
|
||||
|
||||
SafeRemoveEntity(pacx.SpawnedMapEntities[part.self.UniqueID])
|
||||
|
||||
local ent = ents.Create("light_dynamic")
|
||||
|
||||
local data = part.self
|
||||
|
||||
local c = data.Color
|
||||
|
||||
ent:SetKeyValue("_light", ("%i %i %i 255"):format(c and c.x or 255, c and c.y or 255, c and c.z or 255))
|
||||
ent:SetKeyValue("brightness", (data.Brightness or 1) * 8)
|
||||
if data.Size then ent:SetKeyValue("distance", data.Size) end
|
||||
if data.Style then ent:SetKeyValue("style", data.Style) end
|
||||
|
||||
set_pos(ent, part.self, parent)
|
||||
|
||||
ent:Spawn()
|
||||
ent:Activate()
|
||||
|
||||
pacx.SpawnedMapEntities[part.self.UniqueID] = ent
|
||||
|
||||
end,
|
||||
|
||||
effect = function(part, parent)
|
||||
if parent:IsValid() and part.data.Effect then
|
||||
ParticleEffectAttach(part.data.Effect, PATTACH_ABSORIGIN_FOLLOW, parent, 0)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
local function try_spawn(part, parent)
|
||||
|
||||
local func = spawn_handlers[part.self.ClassName]
|
||||
|
||||
if func then
|
||||
return func(part, parent)
|
||||
else
|
||||
pac.Message(part.self.ClassName)
|
||||
end
|
||||
|
||||
return NULL
|
||||
end
|
||||
|
||||
local function parse_part_data(part, parent)
|
||||
parent = try_spawn(part, parent)
|
||||
|
||||
for key, part in pairs(part.children) do
|
||||
parse_part_data(part, parent)
|
||||
end
|
||||
end
|
||||
|
||||
function pacx.SpawnMapOutfit(data)
|
||||
if data.self then
|
||||
data = {data}
|
||||
end
|
||||
|
||||
for key, part in pairs(data) do
|
||||
parse_part_data(part, NULL)
|
||||
end
|
||||
end
|
||||
|
||||
concommand.Add("pac_spawn_map", function(ply, _, args)
|
||||
if not ply:IsAdmin() then return end
|
||||
|
||||
if not args[1] then
|
||||
return ply:PrintMessage(HUD_PRINTCONSOLE, "Please enter a pac name")
|
||||
end
|
||||
|
||||
for _,v in pairs(pacx.SpawnedMapEntities) do
|
||||
SafeRemoveEntity(v)
|
||||
end
|
||||
|
||||
pacx.SpawnedMapEntities = {}
|
||||
|
||||
local data = pace.luadata.ReadFile("pac3/" .. args[1] .. ".txt")
|
||||
|
||||
if data then
|
||||
pacx.SpawnMapOutfit(data)
|
||||
else
|
||||
pac.Message(data)
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user