1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-02 00:42:29 +00:00

Ownership

Добавлена установка владельцев энтити стандартными фнукциями GMod'а
This commit is contained in:
kosmik641
2025-11-06 08:26:50 +03:00
parent a3b01b69a4
commit 499770d9d3
3 changed files with 26 additions and 5 deletions

View File

@@ -57,6 +57,7 @@ function ENT:PostEntityPaste(ply,ent,createdEntities)
v[1].NoPhysics = v[2] or nil v[1].NoPhysics = v[2] or nil
-- Assign ownership -- Assign ownership
if IsValid(self:GetOwner()) then v[1]:SetOwner(self:GetOwner()) end
if CPPI and IsValid(self:CPPIGetOwner()) then v[1]:CPPISetOwner(self:CPPIGetOwner()) end if CPPI and IsValid(self:CPPIGetOwner()) then v[1]:CPPISetOwner(self:CPPIGetOwner()) end
-- Some shared general information about the bogey -- Some shared general information about the bogey
@@ -105,8 +106,9 @@ function ENT:Initialize()
end end
self:SetUseType(SIMPLE_USE) self:SetUseType(SIMPLE_USE)
-- Prop-protection related -- Prop-protection related
if CPPI and IsValid(self.Owner) then if IsValid(self.Owner) then
self:CPPISetOwner(self.Owner) self:SetOwner(self.Owner)
if CPPI then self:CPPISetOwner(self.Owner) end
end end
-- Entities that belong to train and must be cleaned up later -- Entities that belong to train and must be cleaned up later
self.TrainEntities = {} self.TrainEntities = {}
@@ -1032,6 +1034,7 @@ function ENT:CreateBogey(pos,ang,forward,typ)
bogey:Spawn() bogey:Spawn()
-- Assign ownership -- Assign ownership
if IsValid(self:GetOwner()) then bogey:SetOwner(self:GetOwner()) end
if CPPI and IsValid(self:CPPIGetOwner()) then bogey:CPPISetOwner(self:CPPIGetOwner()) end if CPPI and IsValid(self:CPPIGetOwner()) then bogey:CPPISetOwner(self:CPPIGetOwner()) end
-- Some shared general information about the bogey -- Some shared general information about the bogey
@@ -1069,6 +1072,7 @@ function ENT:CreateBogey(pos,ang,forward,typ)
end end
function ENT:AddLightSensor(pos,ang,model) function ENT:AddLightSensor(pos,ang,model)
local sensor = ents.Create("gmod_train_autodrive_coil") local sensor = ents.Create("gmod_train_autodrive_coil")
if IsValid(self:GetOwner()) then sensor:SetOwner(self:GetOwner()) end
if CPPI and IsValid(self:CPPIGetOwner()) then sensor:CPPISetOwner(self:CPPIGetOwner()) end if CPPI and IsValid(self:CPPIGetOwner()) then sensor:CPPISetOwner(self:CPPIGetOwner()) end
sensor:SetPos(self:LocalToWorld(pos)) sensor:SetPos(self:LocalToWorld(pos))
sensor:SetAngles(self:LocalToWorldAngles(ang)) sensor:SetAngles(self:LocalToWorldAngles(ang))
@@ -1091,6 +1095,7 @@ function ENT:AddAutodriveCoil(bogey,right)
bogey.CoilL = coil bogey.CoilL = coil
end end
-- Assign ownership -- Assign ownership
if IsValid(self:GetOwner()) then coil:SetOwner(self:GetOwner()) end
if CPPI and IsValid(self:CPPIGetOwner()) then coil:CPPISetOwner(self:CPPIGetOwner()) end if CPPI and IsValid(self:CPPIGetOwner()) then coil:CPPISetOwner(self:CPPIGetOwner()) end
end end
if right then if right then
@@ -1116,6 +1121,7 @@ function ENT:CreateCouple(pos,ang,forward,typ)
coupler:Spawn() coupler:Spawn()
-- Assign ownership -- Assign ownership
if IsValid(self:GetOwner()) then coupler:SetOwner(self:GetOwner()) end
if CPPI and IsValid(self:CPPIGetOwner()) then coupler:CPPISetOwner(self:CPPIGetOwner()) end if CPPI and IsValid(self:CPPIGetOwner()) then coupler:CPPISetOwner(self:CPPIGetOwner()) end
-- Some shared general information about the bogey -- Some shared general information about the bogey
@@ -1188,6 +1194,7 @@ function ENT:CreateSeatEntity(seat_info)
self:DrawShadow(false) self:DrawShadow(false)
--Assign ownership --Assign ownership
if IsValid(self:GetOwner()) then seat:SetOwner(self:GetOwner()) end
if CPPI and IsValid(self:CPPIGetOwner()) then seat:CPPISetOwner(self:CPPIGetOwner()) end if CPPI and IsValid(self:CPPIGetOwner()) then seat:CPPISetOwner(self:CPPIGetOwner()) end
-- Hide the entity visually -- Hide the entity visually

View File

@@ -149,7 +149,20 @@ function ENT:InitializeWheels()
else else
constraint.Weld(self,wheels,0,0,0,1,0) constraint.Weld(self,wheels,0,0,0,1,0)
end end
if CPPI then wheels:CPPISetOwner(self:CPPIGetOwner() or self:GetNW2Entity("TrainEntity"):GetOwner()) end
-- Assign ownership
if IsValid(self:GetOwner()) then
wheels:SetOwner(self:GetOwner())
elseif IsValid(self:GetNW2Entity("TrainEntity"):GetOwner()) then
wheels:SetOwner(self:GetNW2Entity("TrainEntity"):GetOwner())
end
if CPPI and IsValid(self:CPPIGetOwner()) then
wheels:CPPISetOwner(self:CPPIGetOwner())
elseif CPPI and IsValid(self:GetNW2Entity("TrainEntity"):CPPIGetOwner()) then
wheels:CPPISetOwner(self:GetNW2Entity("TrainEntity"):CPPIGetOwner())
end
wheels:SetNW2Entity("TrainBogey",self) wheels:SetNW2Entity("TrainBogey",self)
self.Wheels = wheels self.Wheels = wheels
end end

View File

@@ -37,8 +37,9 @@ function ENT:Use(_,ply)
self.Cover:SetOwner(self.Owner) self.Cover:SetOwner(self.Owner)
local phys = self.Cover:GetPhysicsObject() local phys = self.Cover:GetPhysicsObject()
phys:ApplyForceCenter(self.Cover:GetUp()*phys:GetMass()*40+self.Cover:GetRight()*phys:GetMass()*35 ) phys:ApplyForceCenter(self.Cover:GetUp()*phys:GetMass()*40+self.Cover:GetRight()*phys:GetMass()*35 )
if CPPI and IsValid(self.Owner) then if IsValid(self.Owner) then
self.Cover:CPPISetOwner(self.Owner) self.Cover:SetOwner(self.Owner)
if CPPI then self.Cover:CPPISetOwner(self.Owner) end
end end
if self.Code then self:SetNW2Int("Code",self.Code) end if self.Code then self:SetNW2Int("Code",self.Code) end
elseif self:GetModel() == "models/metrostroi_train/reversor/reversor_collection_box2.mdl" then elseif self:GetModel() == "models/metrostroi_train/reversor/reversor_collection_box2.mdl" then