Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile()
- DEFINE_BASECLASS( "base_anim" )
- ENT.PrintName = "Custom Zone"
- ENT.Author = "FusionLord"
- ENT.Information = "A configurable zone."
- ENT.Category = "temp"
- ENT.Spawnable = true
- ENT.AdminOnly = false
- ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
- function ENT:Initialize()
- if SERVER then
- self:SetTrigger(true);
- end
- self:SetCollisionGroup(COLLISION_GROUP_DEBRIS)
- self:SetMoveType(MOVETYPE_NONE)
- self:SetSolid(SOLID_VPHYSICS);
- self:DrawShadow(false);
- end
- function ENT:SetZoneData(data)
- self:SetNWInt("type", data.typeID);
- self:SetPos(data.pos);
- self:SetAngles(data.angles);
- self:UpdateBounds(data.mins, data.maxs);
- end
- function ENT:UpdateBounds(mins, maxs)
- net.Start("cz_zone_bounds_update");
- net.WriteEntity(self);
- net.WriteVector(mins);
- net.WriteVector(maxs);
- net.Broadcast()
- end
- if SERVER then
- util.AddNetworkString("cz_zone_bounds_update");
- function ENT:StartTouch(entity)
- if entity:GetClass() ~= "player" then return end
- local zone = customzones:GetZoneTypeFromInt(self:GetNWInt("type"));
- if zone.entering then
- zone.entering(entity, self);
- end
- end
- function ENT:Touch(entity)
- if entity:GetClass() ~= "player" then
- return;
- end
- local zone = customzones:GetZoneTypeFromInt(self:GetNWInt("type"));
- if zone.inside then
- zone.inside(entity, self);
- end
- end
- function ENT:EndTouch(entity)
- if entity:GetClass() ~= "player" then
- return;
- end
- local zone = customzones:GetZoneTypeFromInt(self:GetNWInt("type"));
- if zone.exiting then
- zone.exiting(entity, self);
- end
- end
- function ENT:Freeze()
- local phys = self:GetPhysicsObject();
- if IsValid(phys) then
- phys:EnableMotion( false );
- end
- end
- elseif CLIENT then
- net.Receive("cz_zone_bounds_update", function(len, ply)
- local entity = net.ReadEntity();
- local mins = net.ReadVector();
- local maxs = net.ReadVector();
- entity:PhysicsInitConvex({ -- This is where the entity is null.
- Vector( mins.x, mins.y, mins.z ),
- Vector( mins.x, mins.y, maxs.z ),
- Vector( mins.x, maxs.y, mins.z ),
- Vector( mins.x, maxs.y, maxs.z ),
- Vector( maxs.x, mins.y, mins.z ),
- Vector( maxs.x, mins.y, maxs.z ),
- Vector( maxs.x, maxs.y, mins.z ),
- Vector( maxs.x, maxs.y, maxs.z ),
- });
- entity:EnableCustomCollisions(true);
- entity:SetCollisionBounds(maxs, mins);
- entity:PhysicsInit(entity:GetSolid());
- entity:Freeze();
- UTIL:Log("Updated physics!");
- end);
- function ENT:Draw()
- local phys = self:GetPhysicsObject();
- if IsValid(phys) then
- local mins, maxs = phys:GetAABB();
- render.DrawWireframeBox(self:GetPos(), self:GetAngles(), mins, maxs, Color(0, 0, 255), true);
- else
- render.DrawWireframeSphere(self:GetPos(),16,16,16,Color(255, 0, 0),true);
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement