
/*
    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 
-- 3aaf217dbda72c52d8532897f5c9000ac85eca339f30615d1f3f36b925d66cfe

local function GetCameras()
    local Tbl = {}
    for k,v in pairs(ents.FindByClass("realistic_police_camera")) do 
        if not IsValid(v:CPPIGetOwner()) then
			if IsValid(v) then 
				Tbl[#Tbl + 1] = v
			end   
        end 
    end 
    return Tbl 
end 
-- 76561198219964944

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()[self:GetNWInt("CameraId")]
			end 
		end
	end)
end

function ENT:Use(activator)
	local getCameras = GetCameras()

	if self:GetNWInt("CameraId") < #getCameras then 
		self:SetNWInt("CameraId", self:GetNWInt("CameraId") + 1) 
	else 
		self:SetNWInt("CameraId", 1) 
	end  
	activator.RPTShowEntity = getCameras[self:GetNWInt("CameraId")]
end 


