Advertisement
Fozie

Camera System

Apr 25th, 2018
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.80 KB | None | 0 0
  1. @name Camera System
  2. @inputs Cam:wirelink
  3. @outputs
  4. @persist [C Config Help]:table Selected:string
  5. @trigger
  6. if(first()){
  7.     #[-----------------------------------------
  8.         Name: Config
  9.     -----------------------------------------]#
  10.     Config = table()
  11.    
  12.     Config["Dist", number] = 500 #This will change the tracking distance for your camera.
  13.    
  14.     #[-----------------------------------------
  15.         Name: Setup
  16.     -----------------------------------------]#
  17.     function fancyPrint(Text:string){
  18.         printColor(vec(100, 100, 100), "[", vec(120, 255, 0), "Cam", vec(100, 100, 100), "]: ", vec(255, 255, 255), Text)
  19.     }
  20.    
  21.     if(!Cam){
  22.         fancyPrint("Sorry, but I couldn't find a Camera Controller. Try to wire one to me.")
  23.     }
  24.    
  25.     runOnChat(1)
  26.    
  27.     #[-----------------------------------------
  28.         Name: Commands
  29.     -----------------------------------------]#
  30.     Help = table()
  31.    
  32.     Help["!add", string] = "Adds a new camera at your location."
  33.     Help["!remove", string] = "Removes the requested camera."
  34.     Help["!view", string] = "Changes your view to the view of the requested camera."
  35.     Help["!off", string] = "Turns off the camera."
  36.     Help["!moveup", string] = "Moves the requested camera up to the requested units."
  37.     Help["!movedown", string] = "Moves the requested camera down to the requested units."
  38.     Help["!move", string] = "Moves the requested camera to your location."
  39.    
  40. }
  41. interval(100)
  42.  
  43. #[-----------------------------------------
  44.     Name: Chat
  45. -----------------------------------------]#
  46.    
  47. if(chatClk(owner())){
  48.     local A = lastSaid():explode(" ")
  49.    
  50.     if(A[1, string] == "!add"){
  51.         local Name = A[2, string]
  52.        
  53.         hideChat(1)
  54.        
  55.         if(Name == ""){
  56.             fancyPrint("Sorry, but that's not a valid camera.")  
  57.         }
  58.         else{
  59.             local Data = table()
  60.            
  61.             Data["Pos", vector] = owner():pos()
  62.             Data["DAng", angle] = owner():eyeAngles()
  63.             Data["Ang", angle] = ang(0, 0, 0)
  64.             Data["Track", number] = 0
  65.            
  66.             C[Name, table] = Data
  67.             fancyPrint("Added a camera at your location. (" + Name + ")")  
  68.         }
  69.     }
  70.    
  71.     if(A[1, string] == "!remove"){
  72.         local Name = A[2, string]
  73.        
  74.         hideChat(1)
  75.        
  76.          if(C[Name, table]){
  77.             C:removeTable(Name)
  78.            
  79.             fancyPrint("Removed camera " + Name + ".")
  80.         }
  81.         else{
  82.             fancyPrint("Sorry, but I couldn't find camera " + Name)
  83.         }
  84.     }
  85.    
  86.     if(A[1, string] == "!view"){
  87.         local Name = A[2, string]
  88.        
  89.         hideChat(1)
  90.        
  91.         if(C[Name, table]){
  92.             Cam["Activated", number] = 1
  93.             Cam["Position", vector] = C[Name, table]["Pos", vector]
  94.             Cam["Angle", angle] = C[Name, table]["DAng", angle]
  95.            
  96.             Selected = Name
  97.            
  98.             fancyPrint("Now viewing camera " + Name + ".")
  99.         }
  100.         else{
  101.             fancyPrint("Sorry, but I couldn't find camera " + Name)
  102.         }
  103.     }
  104.    
  105.     if(A[1, string] == "!off"){
  106.         hideChat(1)
  107.  
  108.         if(!Cam["Activated", number]){
  109.             fancyPrint("Disabled your camera.")
  110.             Cam["Activated", number] = 0
  111.            
  112.             Selected = ""
  113.         }
  114.     }
  115.    
  116.     if(A[1, string] == "!track"){
  117.         local Name = A[2, string]
  118.        
  119.         hideChat(1)
  120.        
  121.         if(C[Name, table]){
  122.             if(C[Name, table]["Track", number]){
  123.                 fancyPrint("Motion Tracking disabled for camera " + Name + ".")
  124.                 C[Name, table]["Track", number] = 0
  125.                
  126.                 Cam["Angle", angle] = C[Name, table]["DAng", angle]
  127.             }
  128.             else{
  129.                 fancyPrint("Motion Tracking enabled for camera " + Name + ".")
  130.                 C[Name, table]["Track", number] = 1
  131.             }
  132.         }
  133.         else{
  134.             fancyPrint("Sorry, but I couldn't find camera " + Name)
  135.         }
  136.     }
  137.    
  138.     if(A[1, string] == "!help"){
  139.         hideChat(1)
  140.        
  141.         fancyPrint("Here's a list of commands.")
  142.        
  143.         foreach(K, V:string = Help){
  144.             fancyPrint(K + " - " + V)  
  145.         }  
  146.     }
  147.    
  148.     if(A[1, string] == "!moveup"){
  149.         local Name = A[2, string]
  150.         local Num = A[3, string]:toNumber()
  151.        
  152.         hideChat(1)
  153.        
  154.         if(C[Name, table] & Num > 0){
  155.             C[Name, table]["Pos", vector] = C[Name, table]["Pos", vector] + vec(0, 0, Num)
  156.            
  157.             fancyPrint("Moved " + Name + " up " + Num + " units.")  
  158.         }
  159.         else{
  160.             fancyPrint("Invalid number or couldn't find camera " + Name + ".")  
  161.         }
  162.     }
  163.    
  164.     if(A[1, string] == "!movedown"){
  165.         local Name = A[2, string]
  166.         local Num = A[3, string]:toNumber()
  167.        
  168.         hideChat(1)
  169.        
  170.         if(C[Name, table] & Num > 0){
  171.             C[Name, table]["Pos", vector] = C[Name, table]["Pos", vector] - vec(0, 0, Num)
  172.            
  173.             fancyPrint("Moved " + Name + " down " + Num + " units.")  
  174.         }
  175.         else{
  176.             fancyPrint("Invalid number or couldn't find camera " + Name + ".")  
  177.         }
  178.     }
  179.    
  180.     if(A[1, string] == "!move"){
  181.         local Name = A[2, string]
  182.        
  183.         hideChat(1)
  184.        
  185.         if(C[Name, table]){
  186.             C[Name, table]["Pos", vector] = owner():pos()
  187.            
  188.             fancyPrint("Moved " + Name + " to your location.")
  189.         }
  190.         else{
  191.             fancyPrint("Invalid number or couldn't find camera " + Name + ".")
  192.         }
  193.     }
  194. }
  195.  
  196. if(changed(Cam) & Cam){
  197.     fancyPrint("Found Camera Controller, type !help to get a list of commands!")  
  198. }
  199.  
  200. #[-----------------------------------------
  201.     Name: Tracking
  202. -----------------------------------------]#
  203. if(C[Selected, table]["Track", number]){
  204.     local Dist = Config["Dist", number]
  205.    
  206.     findByClass("player")
  207.     local E = findClosest(C[Selected, table]["Pos", vector])
  208.    
  209.     if(E:pos():distance(C[Selected, table]["Pos", vector]) <= Dist){
  210.  
  211.         C[Selected, table]["Ang", angle] = ((E:pos() + vec(0, 0, 50)) - C[Selected, table]["Pos", vector]):toAngle()  
  212.     }
  213.     else{
  214.         C[Selected, table]["Ang", angle] = C[Selected, table]["DAng", angle]  
  215.     }
  216.    
  217.     Cam["Angle", angle] = C[Selected, table]["Ang", angle]
  218. }
  219.  
  220. if(!Cam["Activated", number]){
  221.     Cam["Position", vector] = C[Selected, table]["Pos", vector]  
  222. }
  223.  
  224. #[-----------------------------------------
  225.     Made By Fozie!
  226.    
  227.     SteamID: STEAM_0:0:226129070
  228.     Profile: http://steamcommunity.com/profiles/76561198412523868
  229.     Discord: Fozie#5014
  230. -----------------------------------------]#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement