Advertisement
sb2014

Cinematic Intro V2 cl_cineditor.lua

Jul 23rd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. --[[-------------------------------------------------------------------------
  2. Init Code
  3. ---------------------------------------------------------------------------]]
  4.  
  5. if !CI then CI = {} end
  6. if !CI.data then CI.data = {} end
  7. if !CI.menu then CI.menu = {} end
  8. function CI.Msg(msg)
  9. if Q_Lib then Q_Lib.Msg(CI.Q_LIBID,msg) end
  10. end
  11.  
  12. CI.isEditting = false
  13. CI.selectedSceane = false
  14. CI.sel_Scene = nil // Currently selected scene
  15. CI.sel_Cam = nil // Currently selected cam
  16. CI.Q_LIBID = nil
  17.  
  18. --[[-------------------------------------------------------------------------
  19. Init Library
  20. ---------------------------------------------------------------------------]]
  21. hook.Add("HUDPaint", "CI_Init_Load", function()
  22. if include('qlib/cl_q_lib.lua') then
  23. CI.Q_LIBID = Q_Lib.RegisterAddon({
  24. name = "Cinematic Intro",
  25. shrt_name = "CIntro",
  26. description = "Create a Cinematic Introduction for your server with fancy affects.",
  27. uid = 76561198339572056,
  28. error_report = [Error] Destination host down,
  29. })
  30. hook.Remove("HUDPaint", "CI_Init_Load")
  31. end
  32. end)
  33. --[[-------------------------------------------------------------------------
  34. Core Functions
  35. ---------------------------------------------------------------------------]]
  36.  
  37.  
  38. function CI.redrawCameras()
  39. CI.Msg("Redrawing cameras")
  40. end
  41.  
  42.  
  43. function CI.data_Save(data, map)
  44. if !data then data = CI.data end
  45. if !map then map = game.GetMap() end
  46. CI.Msg("Saved the current map data to server.")
  47. net.Start("ci:submit")
  48. net.WriteString(util.TableToJSON(data))
  49. net.SendToServer()
  50.  
  51. --PrintTable(data)
  52. end
  53.  
  54. function CI.global_Update(_d)
  55. table.Merge(CI.data.settings,_d)
  56. CI.Msg("Update made. Pushing content to server.")
  57. CI.data_Save()
  58. end
  59.  
  60. --[[-------------------------------------------------------------------------
  61. Scene, Camera, Helper funcs.
  62. ---------------------------------------------------------------------------]]
  63.  
  64. function CI.select_Scene(id)
  65. if !id then id = 1 end
  66. if CI.data.scenes and CI.data.scenes[id] then
  67. CI.sel_Scene = id
  68. CI.redrawCameras()
  69.  
  70. CI.Msg("Selected scene: "..id.."/"..table.Count(CI.data.scenes).." ("..table.Count(CI.data.scenes[CI.sel_Scene].cams).." cams).")
  71. end
  72. end
  73.  
  74. function CI.select_Cam(id)
  75. if !id then id = 1 end
  76. if CI.sel_Scene and CI.data.scenes[CI.sel_Scene] and CI.data.scenes[CI.sel_Scene].cams[id] then
  77. CI.sel_Cam = id
  78. CI.Msg("Selected cam: "..id.."/"..table.Count(CI.data.scenes[CI.sel_Scene].cams)..".")
  79. end
  80. end
  81.  
  82. function CI.scene_Add(data)
  83. if !data then data = CI.data end
  84. if !data.scenes then data.scenes = {} end
  85. if !data.settings then data.settings = {entities = {}, pp = {}, only_once = false, loop = false, music = "" } end -- create the table xd
  86. local newScene = {cams = {}, settings = {title = "", subtitle = "", length = 1}}
  87. table.insert(data.scenes, newScene)
  88.  
  89. CI.sel_Scene = table.Count(data.scenes)
  90. CI.menu.EMenu(true)
  91. CI.Msg("Inserting a new scene: "..CI.sel_Scene..".")
  92. end
  93.  
  94. function CI.updateCam(data)
  95. if !data then data = CI.data end
  96. if !data.scenes or !CI.sel_Scene or !CI.sel_Cam or !data.scenes[CI.sel_Scene] or !data.scenes[CI.sel_Scene].cams[CI.sel_Cam] then return end
  97.  
  98. local data_t = data.scenes[CI.sel_Scene].cams[CI.sel_Cam]
  99. data_t.pos = LocalPlayer():EyePos()
  100. data_t.ang = LocalPlayer():EyeAngles()
  101. CI.Msg("Updating Camera for SceneID "..CI.sel_Scene.." CameraID "..CI.sel_Cam)
  102. end
  103.  
  104. function CI.cam_Add(data)
  105. if !data then data = CI.data end
  106. if !data.scenes or !CI.sel_Scene or !data.scenes[CI.sel_Scene] then CI.Msg("No scene selected") return end
  107.  
  108. local newCam = {pos = LocalPlayer():EyePos(), ang = LocalPlayer():EyeAngles()}
  109. table.insert(data.scenes[CI.sel_Scene].cams, newCam)
  110.  
  111. CI.sel_Cam = table.Count(data.scenes[CI.sel_Scene].cams)
  112. CI.menu.EMenu(true)
  113. CI.Msg("Inserting a new cam: "..CI.sel_Cam.." to scene: "..CI.sel_Scene..".")
  114. end
  115.  
  116. function CI.scene_Update(_d,id)
  117. if isbool(_d) then
  118. table.remove(CI.data.scenes,id)
  119. CI.Msg("Data deleted for Scene ID"..id)
  120. CI.data_Save()
  121. return end
  122. table.Merge(CI.data.scenes[id].settings,_d)
  123. CI.Msg("Inserting data into SceneID: "..id.." make sure to save changes.")
  124. CI.data_Save()
  125. end
  126.  
  127.  
  128. --[[-------------------------------------------------------------------------
  129. Handle Keys
  130. ---------------------------------------------------------------------------]]
  131.  
  132. local Keys = {}
  133. Keys.insert = {mouse = nil, key = KEY_INSERT, onPress = function() end, onRelease = function() CI.scene_Add() end}
  134. Keys.save = {mouse = nil, key = KEY_END, onPress = function() end, onRelease = function() CI.data_Save() end}
  135. Keys.page_down = {mouse = nil, key = KEY_PAGEUP, onPress = function() end, onRelease = function() CI.select_Scene((CI.sel_Scene or 1)-1) end}
  136. Keys.page_up = {mouse = nil, key = KEY_PAGEDOWN, onPress = function() end, onRelease = function() CI.select_Scene((CI.sel_Scene or 1)+1) end}
  137. Keys.mouse_r = {mouse = MOUSE_RIGHT, key = nil, onPress = function() end, onRelease = function() CI.cam_Add() end}
  138. Keys.cam_up = {mouse = nil, key = KEY_UP, onPress = function() end, onRelease = function() CI.select_Cam((CI.sel_Cam or 1)+1) end}
  139. Keys.cam_down = {mouse = nil, key = KEY_DOWN, onPress = function() end, onRelease = function() CI.select_Cam((CI.sel_Cam or 1)-1) end}
  140. Keys.update = {mouse = MOUSE_LEFT, key = nil, onPress = function() end, onRelease = function() CI.updateCam() end}
  141.  
  142. hook.Add("Tick","Tick_ci",function ()
  143. if CI.isEditting and !vgui.CursorVisible() then
  144. for k,v in pairs(Keys) do
  145. local isDown = v.key and input.IsKeyDown(v.key) or v.mouse and input.IsMouseDown(v.mouse)
  146.  
  147. if isDown and !v.isDown then
  148. if v.onPress then v.onPress() end
  149. v.isDown = true
  150. elseif !isDown and v.isDown then
  151. if v.onRelease then v.onRelease() end
  152. v.isDown = nil
  153. end
  154. end
  155. end
  156. end)
  157.  
  158. --[[-------------------------------------------------------------------------
  159. Other
  160. ---------------------------------------------------------------------------]]
  161.  
  162. -- hook.Add("PrePlayerDraw","PrePlayerDraw_CI",function (ply)
  163. -- if CI.isEditting then return true end
  164. -- end)
  165.  
  166. net.Receive("ci:orbit",function() CI.isEditting = net.ReadBool() CI.menu.EMenu(CI.isEditting) end)
  167.  
  168. concommand.Add("CI_Save", function(ply, cnt, arg) CI.data_Save() end)
  169. -- concommand.Add("CI_AddScene", function(ply, cnt, arg) CI.scene_Add() end)
  170. -- concommand.Add("CI_AddCam", function(ply, cnt, arg) CI.data_Save_CurMap() end)
  171.  
  172.  
  173. -- local function drawCamera()
  174.  
  175. -- local cam = ClientsideModel( "models/dav0r/camera.mdl" )
  176. -- cam:SetPos(ply:GetPos())
  177. -- cam:SetAngles(ply:GetAngles())
  178.  
  179. -- return cam
  180.  
  181. -- end
  182.  
  183.  
  184.  
  185. local rope = Material("cable/rope")
  186. hook.Add("PostDrawTranslucentRenderables", "PostDrawTranslucentRenderables_ci", function(_,skybox)
  187.  
  188. -- if skybox then return end
  189. -- for k,v in pairs(markers) do
  190. -- render.SetMaterial(rope)
  191. -- render.DrawBeam( v["vector1"], v["vector2"], 1, 0, 0, Color(255,0,0,255) )
  192. -- render.SetMaterial(rope)
  193. -- render.DrawBeam( v["vector1"], v["lookingAt1"], 1, 0, 0, Color(0,255,0,255) )
  194. -- render.SetMaterial(rope)
  195. -- render.DrawBeam( v["vector2"], v["lookingAt2"], 1, 0, 0, Color(0,255,0,255) )
  196. -- render.DrawWireframeSphere( Vector(v["vector1"].x,v["vector1"].y,v["vector1"].z+25), 10, 20, 20, Color(255,50,50,255) )
  197. -- render.DrawWireframeSphere( Vector(v["vector2"].x,v["vector2"].y,v["vector2"].z+25), 10, 20, 20, Color(255,50,50,255) )
  198. -- end
  199.  
  200.  
  201. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement