Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if CLIENT then
- local T = { };
- T.OPEN = false;
- T.OPENLOCATOR = false;
- T.STACK = { };
- T.MAIN = { };
- T.INTERVAL = 0;
- T.ID_INCREMENTOR = 1;
- T.RENDER = function()
- T.INTERVAL = T.INTERVAL + 3;
- for i, params in pairs(T.STACK) do
- local ent = Entity(params['entity']);
- local v = params['vector'];
- local a = params['angle'];
- local fov = params['fov'];
- local bnd = params['bounds'];
- local b = params['enable'];
- local lbl = params['label'];
- local nrz = params['nearz'];
- local frz = params['farz'];
- local spd = params['showspeed'];
- local ARS = params['ars'];
- if T.INTERVAL >= 100 then
- T.DELIVER_ARS_DATA(params['entity']);
- end
- if IsValid(ent) and b then
- local Speed = math.floor(-ent:GetVelocity():Dot(ent:GetAngles():Forward()) * 0.06858);
- --render.SetScissorRect(ScrW() * bnd[1], ScrH() * bnd[2], ScrW() * bnd[3], ScrH() * bnd[4], true);
- local ps = string.Explode(',', v);
- local as = string.Explode(',', a);
- render.RenderView( {
- origin = ent:LocalToWorld(Vector(ps[1], ps[2], ps[3])),
- angles = ent:LocalToWorldAngles(Angle(as[1], as[2], as[3])),
- x = ScrW() * bnd[1], y = ScrH() * bnd[2],
- w = ScrW() * bnd[3], h = ScrH() * bnd[4],
- fov = fov,
- drawviewmodel = false,
- znear = nrz,
- zfar = frz
- } )
- draw.NoTexture();
- surface.SetTextColor(255, 255, 255, 255);
- surface.SetTextPos(ScrW() * bnd[1] + ScrW() * 0.01, ScrH() * bnd[2]);
- surface.SetFont('Trebuchet24');
- local W, H = surface.GetTextSize(lbl);
- surface.DrawText(lbl .. (spd and ( ', ' .. Speed .. ' km/h' ) or '' ) .. '|' .. ARS);
- surface.SetDrawColor(0, 0, 0, 150);
- surface.DrawRect(ScrW() * bnd[1] + ScrW() * 0.01, ScrH() * bnd[2], W, H);
- --render.SetScissorRect(0, 0, 0, 0, false);
- end
- end
- end
- T.ADD = function()
- local t = { };
- t['entity'] = LocalPlayer():EntIndex();
- t['vector'] = '0,0,0';
- t['angle'] = '0,0,0';
- t['bounds'] = { 0.5, 0.5, 0.25, 0.25 }; -- multiplicator of resolution
- t['fov'] = 70;
- t['enable'] = true;
- t['showspeed'] = false;
- t['uid'] = T.ID_INCREMENTOR;
- t['label'] = '';
- t['nearz'] = 0;
- t['farz'] = 200;
- t['ars'] = '-';
- table.insert(T.STACK, t);
- t = nil;
- T.ID_INCREMENTOR = T.ID_INCREMENTOR + 1;
- end
- T.CHANGEPARAMS = function(id)
- local F = vgui.Create('DFrame');
- F:SetSize(300, 570);
- F:Center();
- F:MakePopup();
- F:SetBackgroundBlur(true);
- F:SetTitle('Camera settings');
- local CPY = vgui.Create('DButton', F);
- CPY:SetSize(100, 22);
- CPY:SetText('Copy to new');
- CPY:SetPos(30, 30);
- CPY.DoClick = function()
- F:Close();
- T.CLONE(T.TABLE_INDEX_BY_UID(id));
- end
- local str = nil;
- if T.STACK[T.TABLE_INDEX_BY_UID(id)]['label'] != '' then
- str = file.Read('cams/'..T.STACK[T.TABLE_INDEX_BY_UID(id)]['label']..'.json', 'DATA');
- end
- local btnLbl = str == nil and 'Save camera' or 'Override camera';
- local SAVE = vgui.Create('DButton', F);
- SAVE:SetSize(100, 22);
- SAVE:SetText(btnLbl);
- SAVE:SetPos(F:GetWide() - SAVE:GetWide() - 30, 30);
- SAVE.DoClick = function()
- local t = T.STACK[T.TABLE_INDEX_BY_UID(id)];
- local str = util.TableToJSON(t);
- local filename = string.Trim(t['label']);
- if filename == '' then
- F:Hide();
- local f = vgui.Create('DFrame');
- f:SetSize(300, 70);
- f:Center();
- f:MakePopup();
- f:SetBackgroundBlur(true);
- f:SetTitle('Enter name of the camera');
- local entr = vgui.Create('DTextEntry', f);
- entr:SetPos(20, 30);
- entr:SetSize(230, 20);
- local ok = vgui.Create('DButton', f);
- ok:SetPos(250, 30);
- ok:SetSize(30, 20);
- ok:SetText('OK');
- ok.DoClick = function()
- local str = string.Trim(entr:GetText());
- if str != '' then
- filename = str;
- file.Write('cams/' .. filename .. '.json', str);
- end
- f:Close();
- end
- entr.OnEnter = ok.DoClick
- f.OnClose = function()
- F:Show();
- end
- else
- file.Write('cams/' .. filename .. '.json', str);
- end
- end
- local ID = vgui.Create('DTextEntry', F);
- ID:SetNumeric(true);
- ID:SetPos(100, 70);
- ID:SetSize(40, 22);
- local IDD = vgui.Create('DLabel', F);
- IDD:SetPos(30, 70);
- IDD:SetText('Ent ID');
- local VEC = vgui.Create('DTextEntry', F);
- VEC:SetPos(100, 100);
- VEC:SetSize(150, 22);
- local VECC = vgui.Create('DLabel', F);
- VECC:SetPos(30, 100);
- VECC:SetText('Pos offset');
- local ANG = vgui.Create('DTextEntry', F);
- ANG:SetPos(100, 130);
- ANG:SetSize(150, 22);
- local ANGG = vgui.Create('DLabel', F);
- ANGG:SetPos(30, 130);
- ANGG:SetText('Ang offset');
- local CAMX = vgui.Create('DTextEntry', F);
- CAMX:SetPos(100, 170);
- CAMX:SetSize(40, 22);
- CAMX:SetNumeric(true);
- local CAMXX = vgui.Create('DLabel', F);
- CAMXX:SetPos(30, 170);
- CAMXX:SetText('Draw X');
- local CAMY = vgui.Create('DTextEntry', F);
- CAMY:SetPos(100, 200);
- CAMY:SetSize(40, 22);
- CAMY:SetNumeric(true);
- local CAMYY = vgui.Create('DLabel', F);
- CAMYY:SetPos(30, 200);
- CAMYY:SetText('Draw Y');
- local CAMW = vgui.Create('DTextEntry', F);
- CAMW:SetPos(100, 240);
- CAMW:SetSize(40, 22);
- CAMW:SetNumeric(true);
- local CAMWW = vgui.Create('DLabel', F);
- CAMWW:SetPos(30, 240);
- CAMWW:SetText('Draw W');
- local CAMH = vgui.Create('DTextEntry', F);
- CAMH:SetPos(100, 270);
- CAMH:SetSize(40, 22);
- CAMH:SetNumeric(true);
- local CAMHH = vgui.Create('DLabel', F);
- CAMHH:SetPos(30, 270);
- CAMHH:SetText('Draw H');
- local FOV = vgui.Create('DTextEntry', F);
- FOV:SetPos(100, 310);
- FOV:SetSize(40, 22);
- FOV:SetNumeric(true);
- local FOVV = vgui.Create('DLabel', F);
- FOVV:SetPos(30, 310);
- FOVV:SetText('FOV');
- local Enbl = vgui.Create('DCheckBoxLabel', F);
- Enbl:SetSize(100, 40);
- Enbl:SetPos(100, 370);
- Enbl:SetText('Toggle enabled');
- local Spd = vgui.Create('DCheckBoxLabel', F);
- Spd:SetSize(100, 40);
- Spd:SetPos(100, 385);
- Spd:SetText('Show kmh');
- local LBL = vgui.Create('DTextEntry', F);
- LBL:SetPos(100, 400);
- LBL:SetSize(150, 22);
- local LBLL = vgui.Create('DLabel', F);
- LBLL:SetPos(30, 400);
- LBLL:SetText('Camera label');
- local NEARZ = vgui.Create('DTextEntry', F);
- NEARZ:SetPos(120, 430);
- NEARZ:SetSize(60, 22);
- NEARZ:SetNumeric(true);
- local NEARZZ = vgui.Create('DLabel', F);
- NEARZZ:SetPos(30, 430);
- NEARZZ:SetText('Camera ZNear');
- NEARZZ:SetSize(100, 30);
- local FARZ = vgui.Create('DTextEntry', F);
- FARZ:SetPos(120, 460);
- FARZ:SetSize(60, 22);
- FARZ:SetNumeric(true);
- local FARZZ = vgui.Create('DLabel', F);
- FARZZ:SetPos(30, 460);
- FARZZ:SetText('Camera ZFar');
- local OK = vgui.Create('DButton', F);
- OK:SetSize(100, 30);
- OK:SetText('Apply');
- OK:SetPos(F:GetWide() / 2 - 50, F:GetTall() - 35);
- OK.DoClick = function()
- F:Close();
- if T.STACK[id] ~= nil then
- T.STACK[id]['entity'] = tonumber(ID:GetText());
- T.STACK[id]['vector'] = VEC:GetText();
- T.STACK[id]['angle'] = ANG:GetText();
- T.STACK[id]['bounds'][1] = tonumber(CAMX:GetText());
- T.STACK[id]['bounds'][2] = tonumber(CAMY:GetText());
- T.STACK[id]['bounds'][3] = tonumber(CAMW:GetText());
- T.STACK[id]['bounds'][4] = tonumber(CAMH:GetText());
- T.STACK[id]['fov'] = tonumber(FOV:GetText());
- T.STACK[id]['enable'] = Enbl:GetChecked();
- T.STACK[id]['label'] = LBL:GetText();
- T.STACK[id]['nearz'] = NEARZ:GetText();
- T.STACK[id]['farz'] = FARZ:GetText();
- T.STACK[id]['showspeed'] = Spd:GetChecked();
- end
- end
- local Placer = nil;
- local PLACE = vgui.Create('DButton', F);
- PLACE:SetSize(150, 30);
- PLACE:SetText('Locate renderer via window');
- PLACE:SetPos(F:GetWide() / 2 - 75, F:GetTall() - 70);
- PLACE.DoClick = function()
- if T.OPENLOCATOR then return end
- Placer = vgui.Create('DFrame');
- Placer:SetSize(ScrW() * tonumber(CAMW:GetText()), ScrH() * tonumber(CAMH:GetText()));
- Placer:SetPos(ScrW() * tonumber(CAMX:GetText()), ScrH() * tonumber(CAMY:GetText()));
- Placer:SetTitle('');
- Placer:MakePopup();
- Placer:SetSizable(true);
- Placer.Paint = function(self, w, h)
- draw.NoTexture();
- surface.SetDrawColor(255, 0, 0, 100);
- surface.DrawRect(0, 0, w-5, 5);
- surface.DrawRect(w-5, 0, 5, h-5);
- surface.DrawRect(5, h-5, w-5, 5);
- surface.DrawRect(0, 5, 5, h-5);
- end
- Placer.Think = function(self)
- local mousex = math.Clamp( gui.MouseX(), 1, ScrW() - 1 )
- local mousey = math.Clamp( gui.MouseY(), 1, ScrH() - 1 )
- local ox, oy = self:GetPos();
- if ( self.Dragging ) then
- local x = mousex - self.Dragging[1]
- local y = mousey - self.Dragging[2]
- -- Lock to screen bounds if screenlock is enabled
- if ( self:GetScreenLock() ) then
- x = math.Clamp( x, 0, ScrW() - self:GetWide() )
- y = math.Clamp( y, 0, ScrH() - self:GetTall() )
- end
- self:SetPos( input.IsKeyDown(KEY_LSHIFT) and ox or x, input.IsKeyDown(KEY_LCONTROL) and oy or y );
- end
- if ( self.Sizing ) then
- local x = mousex - self.Sizing[1]
- local y = mousey - self.Sizing[2]
- local px, py = self:GetPos()
- if ( x < self.m_iMinWidth ) then x = self.m_iMinWidth elseif ( x > ScrW() - px && self:GetScreenLock() ) then x = ScrW() - px end
- if ( y < self.m_iMinHeight ) then y = self.m_iMinHeight elseif ( y > ScrH() - py && self:GetScreenLock() ) then y = ScrH() - py end
- self:SetSize( x, y )
- self:SetCursor( "sizenwse" )
- return
- end
- self:SetCursor( "sizeall" )
- -- Don't allow the frame to go higher than 0
- if ( self.y < 0 ) then
- self:SetPos( self.x, 0 )
- end
- end
- Placer.OnClose = function()
- local x, y, w, h = Placer:GetBounds();
- CAMX:SetText(math.Round(x / ScrW(), 3));
- CAMY:SetText(math.Round(y / ScrH(), 3));
- CAMW:SetText(math.Round(w / ScrW(), 3));
- CAMH:SetText(math.Round(h / ScrH(), 3));
- T.OPENLOCATOR = false;
- OK.DoClick();
- end
- T.OPENLOCATOR = true;
- end
- F.OnClose = function()
- if IsValid(Placer) then
- Placer:Close();
- end
- end
- if T.STACK[id] ~= nil then
- ID:SetText(T.STACK[id]['entity']);
- VEC:SetText(T.STACK[id]['vector']);
- ANG:SetText(T.STACK[id]['angle']);
- CAMX:SetText(T.STACK[id]['bounds'][1]);
- CAMY:SetText(T.STACK[id]['bounds'][2]);
- CAMW:SetText(T.STACK[id]['bounds'][3]);
- CAMH:SetText(T.STACK[id]['bounds'][4]);
- FOV:SetText(T.STACK[id]['fov']);
- Enbl:SetChecked(T.STACK[id]['enable']);
- Spd:SetChecked(T.STACK[id]['showspeed']);
- LBL:SetText(T.STACK[id]['label']);
- NEARZ:SetText(T.STACK[id]['nearz']);
- FARZ:SetText(T.STACK[id]['farz']);
- end
- end
- T.TABLE_INDEX_BY_ENTINDEX = function(ent_id)
- local id = 0;
- for i, kv in pairs(T.STACK) do
- if kv['entity'] == ent_id then
- id = i;
- end
- end
- return id;
- end
- T.TABLE_INDEX_BY_UID = function(uid)
- local id = 1;
- for i, kv in pairs(T.STACK) do
- if kv['uid'] == uid then
- id = i;
- end
- end
- return id;
- end
- T.DELIVER_ARS_DATA = function(eid)
- local t = { };
- t['ply'] = LocalPlayer();
- t['id'] = eid;
- net.Start('camtool_tunnel_handler')
- net.WriteTable(t)
- net.SendToServer();
- end
- T.CLONE = function(tableid)
- local original = T.STACK[tableid];
- local t = table.Copy(original); -- new
- original = nil;
- table.insert(T.STACK, t);
- t = nil;
- end
- T.SHOWMENU = function()
- if T.OPEN then return end
- T.MAIN = vgui.Create('DFrame');
- T.MAIN:SetSize(500, 600);
- T.MAIN:Center();
- T.MAIN:MakePopup();
- T.MAIN:SetTitle('Multiple camera tool v0.7')
- T.MAIN.CONTAINER = { };
- local p = vgui.Create('DPanel', T.MAIN);
- p:SetAlpha(0);
- local CONT = vgui.Create('DPanelList', T.MAIN);
- CONT:SetPos(25, 80);
- CONT:SetSize(T.MAIN:GetWide() - 50, T.MAIN:GetTall() - 120);
- local BAdd = vgui.Create('DButton', T.MAIN);
- BAdd:SetPos(50, 50);
- BAdd:SetSize(150, 25);
- BAdd:SetText('Create camera');
- local BLoad = vgui.Create('DButton', T.MAIN);
- BLoad:SetSize(150, 25);
- BLoad:SetPos(T.MAIN:GetWide() - BLoad:GetWide() - 50, 50);
- BLoad:SetText('Load camera from JSON file');
- BLoad.DoClick = function()
- T.MAIN:Hide();
- local f = vgui.Create('DFrame');
- f:SetSize(400, 400);
- f:SetTitle('Open file');
- f:MakePopup();
- f:Center();
- f:SetBackgroundBlur(true);
- local files = vgui.Create('DFileBrowser', f);
- files:Dock(FILL);
- files:SetPath('DATA');
- files:SetBaseFolder('cams');
- files:SetOpen(true);
- files:SetCurrentFolder('cams');
- files.OnSelect = function(self, path)
- local str = file.Read(path, 'DATA');
- local t = util.JSONToTable(str);
- if t != nil then
- if #table.GetKeys(t) > 0 then
- t['uid'] = T.ID_INCREMENTOR + 1;
- table.insert(T.STACK, t);
- T.ID_INCREMENTOR = T.ID_INCREMENTOR + 1;
- chat.AddText(Color(50,255,50), 'Camera loaded');
- else
- chat.AddText(Color(255,50,50), 'Invalid JSON file1');
- end
- else
- chat.AddText(Color(255,50,50), 'Invalid JSON file2');
- end
- f:Close();
- end
- f.OnClose = function()
- T.MAIN:Show();
- end
- end
- p.Think = function()
- --[[this condition resets main id incrementor when main camera table is empty]]--
- if #T.STACK == 0 and T.ID_INCREMENTOR > 1 then
- T.ID_INCREMENTOR = 1;
- end
- --[[this condition resets main id incrementor when main camera table is empty]]--
- if #T.MAIN.CONTAINER != #T.STACK then
- CONT:Clear();
- for i, kv in pairs(T.STACK) do
- local b = vgui.Create('DButton');
- b:SetPos(0, i * 45);
- b.ID = kv['uid'];
- b:SetText('');
- b:SetSize(CONT:GetWide(), 40);
- b.Paint = function(self, w, h)
- draw.NoTexture();
- surface.SetDrawColor(120, 120, 120, 255);
- surface.DrawRect(0, 0, w, h);
- surface.SetDrawColor(255, 0, 0, 100);
- surface.DrawRect(w * 0.9, 0, w * 0.1, h);
- local ent = Entity(kv['entity']);
- local v = kv['vector'];
- local a = kv['angle'];
- local fov = kv['fov'];
- local bnd = kv['bounds'];
- local b = kv['enable'];
- local uid = kv['uid'];
- if IsValid(ent) and b then
- local ps = string.Explode(',', v);
- local as = string.Explode(',', a);
- local x, y = self:GetPos();
- local x2, y2 = T.MAIN:GetPos();
- local x3, y3 = CONT:GetPos();
- render.RenderView( {
- origin = ent:LocalToWorld(Vector(ps[1], ps[2], ps[3])),
- angles = ent:LocalToWorldAngles(Angle(as[1], as[2], as[3])),
- x = x + x2 + x3, y = y + y2 + y3,
- w = h, h = h,
- fov = fov
- } )
- end
- if T.TABLE_INDEX_BY_UID(uid) == nil then
- self:Remove();
- end
- draw.SimpleText('Camera #' .. i .. '.Entity ID: ' .. kv['entity'], 'drwaCross', w * 0.2, h * 0.14, Color(150, 150, 150));
- draw.SimpleText('x', 'drwaCross', w * 0.935, h * 0.14, Color(255, 255, 255));
- end
- b.DoClick = function()
- local x, y = BAdd:LocalCursorPos();
- if x < b:GetWide() * 0.8 then
- T.CHANGEPARAMS(T.TABLE_INDEX_BY_UID(b.ID));
- else
- for idd, tbl in pairs(T.STACK) do
- if tbl['uid'] == b.ID then
- table.remove(T.STACK, idd);
- end
- end
- table.remove(T.MAIN.CONTAINER, T.TABLE_INDEX_BY_UID(b.ID));
- b:Remove();
- end
- end
- CONT:AddItem(b);
- T.MAIN.CONTAINER[i] = b;
- end
- end
- if not file.Exists('cams', 'DATA') then
- file.CreateDir('cams');
- end
- end
- T.MAIN.OnClose = function()
- T.OPEN = false;
- end
- BAdd.DoClick = function()
- T.ADD();
- end
- T.OPEN = true;
- end
- hook.Add('HUDPaint','camtool_r', T.RENDER);
- concommand.Add('camtool', T.SHOWMENU);
- surface.CreateFont('drwaCross', {
- font = 'Segoe UI';
- size = 30;
- });
- T.GET_ARS_DATA = function()
- local s = net.ReadString();
- local i = net.ReadInt(32);
- if T.STACK[T.TABLE_INDEX_BY_ENTINDEX(i)] != nil then
- T.STACK[T.TABLE_INDEX_BY_ENTINDEX(i)]['ars'] = s;
- end
- end
- net.Receive('camtool_tunnel_handler', T.GET_ARS_DATA);
- end
- if SERVER then
- util.AddNetworkString('camtool_tunnel_handler');
- local function recv()
- local t = net.ReadTable();
- local ply = t['ply'];
- local entID = t['id'];
- local ent = Entity(entID);
- local INFO = '-';
- if IsValid(ent) then
- if ent.ALS_ARS != nil and ent.Panel.V1 > 0.5 then
- --if ent.ALS_ARS.
- if ent.ALS_ARS.NoFreq != nil then
- if ent.ALS_ARS.NoFreq > 0 then
- INFO = 'ОЧ';
- end
- end
- if ent.ALS_ARS.F5 > 0 then
- INFO = 'АРС 0';
- end
- if ent.ALS_ARS.F4 > 0 then
- INFO = 'АРС 40 км/ч';
- end
- if ent.ALS_ARS.F3 > 0 then
- INFO = 'АРС 60 км/ч';
- end
- if ent.ALS_ARS.F2 > 0 then
- INFO = 'АРС 70 км/ч';
- end
- if ent.ALS_ARS.F1 > 0 then
- INFO = 'АРС 80 км/ч';
- end
- end
- if ent.BARS != nil then
- --if ent.ALS_ARS.
- if ent.BARS.NoFreq > 0 then
- INFO = 'ОЧ';
- end
- if ent.BARS.F5 > 0 then
- INFO = 'АРС 0';
- end
- if ent.BARS.F4 > 0 then
- INFO = 'АРС 40 км/ч';
- end
- if ent.BARS.F3 > 0 then
- INFO = 'АРС 60 км/ч';
- end
- if ent.BARS.F2 > 0 then
- INFO = 'АРС 70 км/ч';
- end
- if ent.BARS.F1 > 0 then
- INFO = 'АРС 80 км/ч';
- end
- end
- if ent.ARS != nil then
- --if ent.ALS_ARS.
- if ent.ARS.NoFreq > 0 then
- INFO = 'ОЧ';
- end
- if ent.ARS.F5 > 0 then
- INFO = 'АРС 0';
- end
- if ent.ARS.F4 > 0 then
- INFO = 'АРС 40 км/ч';
- end
- if ent.ARS.F3 > 0 then
- INFO = 'АРС 60 км/ч';
- end
- if ent.ARS.F2 > 0 then
- INFO = 'АРС 70 км/ч';
- end
- if ent.ARS.F1 > 0 then
- INFO = 'АРС 80 км/ч';
- end
- end
- end
- if IsValid(ply) then
- net.Start('camtool_tunnel_handler');
- net.WriteString(INFO);
- net.WriteInt(entID, 32);
- net.Send(ply);
- end
- end
- net.Receive('camtool_tunnel_handler', recv);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement