
/*
    Addon id: e7709ac2-cc0b-41b1-845d-7528015000ee
    Version: v1.7.8 (stable)
*/

AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
ENT.AutomaticFrameAdvance = true 
-- a91f6942e11bb9a70ff8e3d7a0dcc737fd407c85d2d10ff95a1cfed59177e84a

local function GetCameras(Players)
    local Tbl = {}
    for k,v in pairs(ents.FindByClass("realistic_police_camera")) do 
        if IsValid(v:CPPIGetOwner()) then 
            if v:CPPIGetOwner() == Players then 
                if IsValid(v) then 
                    Tbl[#Tbl + 1] = v
                end   
            end 
        end 
    end 
    return Tbl 
end 
function ENT:Initialize()
	self:SetModel( "models/props/cs_office/tv_plasma.mdl" )
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	self:SetUseType(SIMPLE_USE)
	self:SetNWInt("CameraId", 1)
timer.Create("rpt_refresh_camera:"..self:EntIndex(), 3, 0, function()
		if not IsValid(self) then return end  
		for k,v in pairs(ents.FindInSphere(self:GetPos(), 100)) do 
			if IsValid(v) && v:IsPlayer() then 
				v.RPTShowEntity = GetCameras(v)[self:GetNWInt("CameraId")]
			end 
		end 
	end)
end
function ENT:Use(activator)
	if IsValid(self:CPPIGetOwner()) then 
		if self:GetNWInt("CameraId") < #GetCameras(self:CPPIGetOwner()) then 
			self:SetNWInt("CameraId", self:GetNWInt("CameraId") + 1) 
		else 
			self:SetNWInt("CameraId", 1) 
		end 
		activator.RPTShowEntity = GetCameras(self:CPPIGetOwner())[self:GetNWInt("CameraId")]
	end 
end 


