Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 74 additions & 82 deletions lua/advdupe2/sv_clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
if (Tab.ModelScale == 1) then Tab.ModelScale = nil end

if(Tab.Class == "gmod_cameraprop")then
Tab.key = Ent:GetNetworkedInt("key")

Check warning on line 190 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Deprecated"

Deprecated: Use :GetNWInt instead
end

-- Allow the entity to override the class
Expand Down Expand Up @@ -464,7 +464,7 @@
]]
function AdvDupe2.duplicator.AreaCopy(ply, Entities, Offset, CopyOutside)
local Constraints, EntTable, ConstraintTable = {}, {}, {}
local index, add, AddEnts, AddConstrs, ConstTable, EntTab

Check warning on line 467 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: AddConstrs

Check warning on line 467 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: AddEnts

for _, Ent in pairs(Entities) do
index = Ent:EntIndex()
Expand Down Expand Up @@ -716,7 +716,7 @@
end

if (Ent and Ent.length) then
Ent.length = Constraint["length"]

Check warning on line 719 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
end -- Fix for weird bug with ropes

return Ent
Expand All @@ -735,20 +735,20 @@
local ok, err = pcall(ModFunction, Player, Ent, Data)
if (not ok) then
if (Player) then
Player:ChatPrint('Error applying entity modifer, "' .. tostring(Type) .. '". ERROR: ' .. err)

Check warning on line 738 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
else
print('Error applying entity modifer, "' .. tostring(Type) .. '". ERROR: ' .. err)

Check warning on line 740 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
end
end
end
end
if (Ent.EntityMods["mass"] and duplicator.EntityModifiers["mass"]) then

Check warning on line 745 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
local ok, err = pcall(duplicator.EntityModifiers["mass"], Player, Ent, Ent.EntityMods["mass"])

Check warning on line 746 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
if (not ok) then
if (Player) then
Player:ChatPrint('Error applying entity modifer, "mass". ERROR: ' .. err)

Check warning on line 749 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
else
print('Error applying entity modifer, "' .. tostring(Type) .. '". ERROR: ' .. err)

Check warning on line 751 in lua/advdupe2/sv_clipboard.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
end
end
end
Expand Down Expand Up @@ -788,84 +788,72 @@
Params: <player> Player, <table> data
Returns: <entity> Entity, <table> data
]]
local function DoGenericPhysics(Entity, data, Player)
local function DoGenericPhysics(entity, data, ply)
if not data.PhysicsObjects then return end

if (not data) then return end
if (not data.PhysicsObjects) then return end
local Phys
if (Player) then
for Bone, Args in pairs(data.PhysicsObjects) do
Phys = Entity:GetPhysicsObjectNum(Bone)
if (IsValid(Phys)) then
Phys:SetPos(Args.Pos)
Phys:SetAngles(Args.Angle)
Phys:EnableMotion(false)
Player:AddFrozenPhysicsObject(Entity, Phys)
end
end
else
for Bone, Args in pairs(data.PhysicsObjects) do
Phys = Entity:GetPhysicsObjectNum(Bone)
if (IsValid(Phys)) then
Phys:SetPos(Args.Pos)
Phys:SetAngles(Args.Angle)
Phys:EnableMotion(false)
for bone, args in ipairs(data.PhysicsObjects) do
local phys = entity:GetPhysicsObjectNum(bone)

if IsValid(phys) then
phys:SetPos(args.Pos)
phys:SetAngles(args.Angle)
phys:EnableMotion(false)

if ply then
ply:AddFrozenPhysicsObject(entity, phys)
end
end
end
end

local function reportclass(ply, class)
net.Start("AdvDupe2_ReportClass")
net.WriteString(class)
net.Send(ply)
end

local function reportmodel(ply, model)
net.Start("AdvDupe2_ReportModel")
net.WriteString(model)
net.Send(ply)
end

local strictConvar = GetConVar("AdvDupe2_Strict")

--[[
Name: GenericDuplicatorFunction
Desc: Override the default duplicator's GenericDuplicatorFunction function
Params: <table> data, <player> Player
Returns: <entity> Entity
]]
local function GenericDuplicatorFunction(data, Player)
local strictConvar = GetConVar("AdvDupe2_Strict")

local Entity = ents.Create(data.Class)
if (not IsValid(Entity)) then
if (Player) then
reportclass(Player, data.Class)
local function GenericDuplicatorFunction(data, ply)
if not util.IsValidModel(data.Model) then
if ply then
net.Start("AdvDupe2_ReportModel")
net.WriteString(data.Model)
net.Send(ply)
else
print("Advanced Duplicator 2 Invalid Class: " .. data.Class)
print("Advanced Duplicator 2 Invalid Model: " .. data.Model)
end
return nil

return
end

if (not util.IsValidModel(data.Model) and not file.Exists(data.Model, "GAME")) then
if (Player) then
reportmodel(Player, data.Model)
local entity = ents.Create(data.Class)

if not IsValid(entity) then
if ply then
net.Start("AdvDupe2_ReportClass")
net.WriteString(class)
net.Send(ply)
else
print("Advanced Duplicator 2 Invalid Model: " .. data.Model)
print("Advanced Duplicator 2 Invalid Class: " .. data.Class)
end
return nil

return
end

duplicator.DoGeneric(Entity, data)
if (Player) then Entity:SetCreator(Player) end
Entity:Spawn()
Entity:Activate()
DoGenericPhysics(Entity, data, Player)
duplicator.DoGeneric(entity, data)
if ply then entity:SetCreator(ply) end

entity:Spawn()
entity:Activate()

if (not strictConvar:GetBool()) then
table.Add(Entity:GetTable(), data)
DoGenericPhysics(entity, data, ply)

if not strictConvar:GetBool() then
table.Add(entity:GetTable(), data)
end
return Entity

return entity
end

--[[
Expand All @@ -874,43 +862,47 @@
Params: <player> Player, <vector> Pos, <angle> Ang, <string> Model, <table> PhysicsObject, <table> Data
Returns: <entity> Prop
]]
local function MakeProp(Player, Pos, Ang, Model, PhysicsObject, Data)

if Data.ModelScale then Data.ModelScale = math.Clamp(Data.ModelScale, 1e-5, 1e5) end

if (not util.IsValidModel(Model) and not file.Exists(Data.Model, "GAME")) then
if (Player) then
reportmodel(Player, Data.Model)
local function MakeProp(ply, pos, ang, model, physicsobject, data)
if data.ModelScale then Data.ModelScale = math.Clamp(data.ModelScale, 1e-5, 1e5) end

if not util.IsValidModel(model) then
if ply then
net.Start("AdvDupe2_ReportModel")
net.WriteString(model)
net.Send(ply)
else
print("Advanced Duplicator 2 Invalid Model: " .. Model)
print("Advanced Duplicator 2 Invalid Model: " .. model)
end
return nil

return
end

Data.Pos = Pos
Data.Angle = Ang
Data.Model = Model
Data.Frozen = true
-- Make sure this is allowed
if (Player) then
if (not gamemode.Call("PlayerSpawnProp", Player, Model)) then
return false
data.Pos = pos
data.Angle = ang
data.Model = model
data.Frozen = true

if ply then
if not gamemode.Call("PlayerSpawnProp", ply, model) then
return
end
end

local Prop = ents.Create("prop_physics")
if not IsValid(Prop) then return false end
local prop = ents.Create("prop_physics")
if not IsValid(prop) then return end

duplicator.DoGeneric(prop, data)

if ply then prop:SetCreator(ply) end
prop:Spawn()

DoGenericPhysics(prop, data, ply)

duplicator.DoGeneric(Prop, Data)
if (Player) then Prop:SetCreator(Player) end
Prop:Spawn()
Prop:Activate()
DoGenericPhysics(Prop, Data, Player)
if (Data.Flex) then
duplicator.DoFlex(Prop, Data.Flex, Data.FlexScale)
if data.Flex then
duplicator.DoFlex(prop, data.Flex, data.FlexScale)
end

return Prop
return prop
end

local function RestoreBodyGroups(ent, BodyG)
Expand Down
Loading