mirror of
https://github.com/wiremod/advdupe2.git
synced 2025-03-04 03:03:05 -05:00
Fix lua error and refactor table.count (#347)
* Fix lua error and refactor table.count * Also replace deprecated table.GetFirstKey * Add iscopyable function * Fixed
This commit is contained in:
parent
756f7d6d5e
commit
72dff27b04
@ -114,11 +114,13 @@ local gtSetupTable = {
|
||||
}
|
||||
}
|
||||
|
||||
function AdvDupe2.duplicator.IsCopyable(Ent)
|
||||
return not Ent.DoNotDuplicate and duplicator.IsAllowed(Ent:GetClass()) and IsValid(Ent:GetPhysicsObject())
|
||||
end
|
||||
|
||||
local function CopyEntTable(Ent, Offset)
|
||||
-- Filter duplicator blocked entities out.
|
||||
if Ent.DoNotDuplicate then return nil end
|
||||
|
||||
if (not IsValid(Ent:GetPhysicsObject())) then return nil end
|
||||
if not AdvDupe2.duplicator.IsCopyable(Ent) then return nil end
|
||||
|
||||
local Tab = {}
|
||||
|
||||
@ -238,7 +240,7 @@ local function CopyEntTable(Ent, Offset)
|
||||
end
|
||||
end
|
||||
|
||||
if(table.Count(Tab.BodyG)==0)then
|
||||
if(next(Tab.BodyG)==nil)then
|
||||
Tab.BodyG = nil
|
||||
end
|
||||
|
||||
@ -1324,7 +1326,7 @@ local function AdvDupe2_Spawn()
|
||||
if IsValid(Entity) then
|
||||
table.insert(Queue.CreatedConstraints, Entity)
|
||||
end
|
||||
elseif (table.Count(Queue.ConstraintList) > 0) then
|
||||
elseif (next(Queue.ConstraintList) ~= nil) then
|
||||
local tbl = {}
|
||||
for k, v in pairs(Queue.ConstraintList) do
|
||||
table.insert(tbl, v)
|
||||
|
@ -1,6 +1,6 @@
|
||||
--Save a file to the client
|
||||
local function SaveFile(ply, cmd, args)
|
||||
if(not ply.AdvDupe2 or not ply.AdvDupe2.Entities or table.Count(ply.AdvDupe2.Entities)==0)then AdvDupe2.Notify(ply,"Duplicator is empty, nothing to save.", NOTIFY_ERROR) return end
|
||||
if(not ply.AdvDupe2 or not ply.AdvDupe2.Entities or next(ply.AdvDupe2.Entities)==nil)then AdvDupe2.Notify(ply,"Duplicator is empty, nothing to save.", NOTIFY_ERROR) return end
|
||||
if(not game.SinglePlayer() and CurTime()-(ply.AdvDupe2.FileMod or 0) < 0)then
|
||||
AdvDupe2.Notify(ply,"Cannot save at the moment. Please Wait...", NOTIFY_ERROR)
|
||||
return
|
||||
|
@ -129,12 +129,12 @@ if(SERVER)then
|
||||
}
|
||||
|
||||
local function PlayerCanDupeCPPI(ply, ent)
|
||||
if ent.DoNotDuplicate or areacopy_classblacklist[ent:GetClass()] or not IsValid(ent:GetPhysicsObject()) or not duplicator.IsAllowed(ent:GetClass()) then return false end
|
||||
if not AdvDupe2.duplicator.IsCopyable(ent) or areacopy_classblacklist[ent:GetClass()] then return false end
|
||||
return ent:CPPIGetOwner()==ply
|
||||
end
|
||||
|
||||
local function PlayerCanDupeTool(ply, ent)
|
||||
if ent.DoNotDuplicate or areacopy_classblacklist[ent:GetClass()] or not IsValid(ent:GetPhysicsObject()) or not duplicator.IsAllowed(ent:GetClass()) then return false end
|
||||
if not AdvDupe2.duplicator.IsCopyable(ent) or areacopy_classblacklist[ent:GetClass()] then return false end
|
||||
local trace = WireLib and WireLib.dummytrace(ent) or { Entity = ent }
|
||||
return hook.Run( "CanTool", ply, trace, "advdupe2" ) ~= false
|
||||
end
|
||||
@ -227,13 +227,14 @@ if(SERVER)then
|
||||
local B = (Vector(-area_size,-area_size,-area_size)+Pos)
|
||||
|
||||
local Ents = FindInBox(B,T, ply)
|
||||
if next(Ents)==nil then
|
||||
local _, Ent = next(Ents)
|
||||
if not Ent then
|
||||
self:SetStage(0)
|
||||
AdvDupe2.RemoveSelectBox(ply)
|
||||
return true
|
||||
end
|
||||
|
||||
local Ent = trace.HitNonWorld and trace.Entity or Ents[next(Ents)]
|
||||
Ent = trace.HitNonWorld and trace.Entity or Ent
|
||||
HeadEnt.Index = Ent:EntIndex()
|
||||
HeadEnt.Pos = Ent:GetPos()
|
||||
|
||||
@ -243,7 +244,7 @@ if(SERVER)then
|
||||
AdvDupe2.RemoveSelectBox(ply)
|
||||
elseif trace.HitNonWorld then --Area Copy is off
|
||||
-- Filter duplicator blocked entities out.
|
||||
if not duplicator.IsAllowed( trace.Entity:GetClass() ) then
|
||||
if not AdvDupe2.duplicator.IsCopyable( trace.Entity ) then
|
||||
return false
|
||||
end
|
||||
|
||||
@ -285,13 +286,14 @@ if(SERVER)then
|
||||
Entities[ent:EntIndex()] = ent
|
||||
end
|
||||
end
|
||||
if next(Entities)==nil then
|
||||
|
||||
local _, Ent = next(Entities)
|
||||
if not Ent then
|
||||
umsg.Start("AdvDupe2_RemoveGhosts", ply)
|
||||
umsg.End()
|
||||
return true
|
||||
end
|
||||
|
||||
local Ent = Entities[next(Entities)]
|
||||
HeadEnt.Index = Ent:EntIndex()
|
||||
HeadEnt.Pos = Ent:GetPos()
|
||||
|
||||
@ -675,7 +677,8 @@ if(SERVER)then
|
||||
local B = (Vector(-i,-i,-i)+Pos)
|
||||
|
||||
local Entities = FindInBox(B,T, ply)
|
||||
if(table.Count(Entities)==0)then
|
||||
local _, HeadEnt = next(Entities)
|
||||
if not HeadEnt then
|
||||
AdvDupe2.Notify(ply, "Area Auto Save copied 0 entities; be sure to turn it off.", NOTIFY_ERROR)
|
||||
return
|
||||
end
|
||||
@ -683,9 +686,9 @@ if(SERVER)then
|
||||
if(ply.AdvDupe2.AutoSaveEnt && Entities[ply.AdvDupe2.AutoSaveEnt])then
|
||||
Tab.HeadEnt.Index = ply.AdvDupe2.AutoSaveEnt
|
||||
else
|
||||
Tab.HeadEnt.Index = table.GetFirstKey(Entities)
|
||||
Tab.HeadEnt.Index = HeadEnt:EntIndex()
|
||||
end
|
||||
Tab.HeadEnt.Pos = Entities[Tab.HeadEnt.Index]:GetPos()
|
||||
Tab.HeadEnt.Pos = HeadEnt:GetPos()
|
||||
|
||||
local WorldTrace = util.TraceLine( {mask=MASK_NPCWORLDSTATIC, start=Tab.HeadEnt.Pos+Vector(0,0,1), endpos=Tab.HeadEnt.Pos-Vector(0,0,50000)} )
|
||||
if(WorldTrace.Hit)then Tab.HeadEnt.Z = math.abs(Tab.HeadEnt.Pos.Z-WorldTrace.HitPos.Z) else Tab.HeadEnt.Z = 0 end
|
||||
@ -719,16 +722,17 @@ if(SERVER)then
|
||||
|
||||
local Entities = ents.GetAll()
|
||||
for k,v in pairs(Entities) do
|
||||
if v:CreatedByMap() or not duplicator.IsAllowed(v:GetClass()) then
|
||||
if v:CreatedByMap() or not AdvDupe2.duplicator.IsCopyable(v) then
|
||||
Entities[k]=nil
|
||||
end
|
||||
end
|
||||
|
||||
if(table.Count(Entities)==0)then return end
|
||||
local _, HeadEnt = next(Entities)
|
||||
if not HeadEnt then return end
|
||||
|
||||
local Tab = {Entities={}, Constraints={}, HeadEnt={}, Description=""}
|
||||
Tab.HeadEnt.Index = table.GetFirstKey(Entities)
|
||||
Tab.HeadEnt.Pos = Entities[Tab.HeadEnt.Index]:GetPos()
|
||||
Tab.HeadEnt.Index = HeadEnt:EntIndex()
|
||||
Tab.HeadEnt.Pos = HeadEnt:GetPos()
|
||||
|
||||
local WorldTrace = util.TraceLine( {mask=MASK_NPCWORLDSTATIC, start=Tab.HeadEnt.Pos+Vector(0,0,1), endpos=Tab.HeadEnt.Pos-Vector(0,0,50000)} )
|
||||
if(WorldTrace.Hit)then Tab.HeadEnt.Z = math.abs(Tab.HeadEnt.Pos.Z-WorldTrace.HitPos.Z) else Tab.HeadEnt.Z = 0 end
|
||||
@ -1486,9 +1490,6 @@ if(CLIENT)then
|
||||
local txtbox2 = vgui.Create("DTextEntry", pnl)
|
||||
txtbox2:SetWide(pnl:GetWide()-100)
|
||||
txtbox2:SetPos(60, 5)
|
||||
txtbox2.OnEnter = function()
|
||||
btn2:DoClick()
|
||||
end
|
||||
|
||||
local btn2 = vgui.Create("DImageButton", pnl)
|
||||
x, y = txtbox2:GetPos()
|
||||
@ -1500,6 +1501,9 @@ if(CLIENT)then
|
||||
if(txtbox2:GetValue()=="")then return end
|
||||
RunConsoleCommand("AdvDupe2_SaveMap", txtbox2:GetValue())
|
||||
end
|
||||
txtbox2.OnEnter = function()
|
||||
btn2:DoClick()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user