Advertisement
Guest User

Untitled

a guest
May 27th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.03 KB | None | 0 0
  1. GARAGE = {}
  2. GARAGE.RepairPrice = 100 //How much costs the repairing
  3. GARAGE.BodyGroupPrice = 200 //Bodygroups price
  4. GARAGE.SkinPrice = 500 //Paint job price
  5. GARAGE.ColorPrice = 250 //Color price
  6.  
  7. GARAGE.Data = {}
  8.  
  9. GARAGE_PROPS = GARAGE_PROPS or {}
  10. local plt = "models/hunter/plates/plate3x6.mdl"
  11. local pltB = "models/hunter/plates/plate6x6.mdl"
  12. local MX = {Vector(0,-142,0),Vector(142,0,0),Vector(142*2,-142,7200),Vector(142,-142*2,0)}
  13.  
  14.  
  15. if SERVER then
  16. util.AddNetworkString("CreateGarage")
  17. util.AddNetworkString("SendGarageMoney")
  18. util.AddNetworkString("RepairGarageCar")
  19. util.AddNetworkString("RepairCar")
  20. resource.AddFile("materials/garage/customs.vmt")
  21. resource.AddFile("materials/garage/circle.vmt")
  22. resource.AddFile("materials/garage/dot.vmt")
  23. resource.AddFile("materials/garage/neon_light.vmt")
  24. end
  25.  
  26. concommand.Add("gzg_garage_create",function(ply)
  27. if(ply:IsAdmin()) then
  28. net.Start("CreateGarage")
  29. net.SendToServer()
  30. end
  31. end)
  32.  
  33. concommand.Add("gzg_garage_save",function(ply)
  34. local tbl = {}
  35. file.Delete("garage_data.dat")
  36. file.Write("garage_data.dat",util.TableToJSON(GARAGE.Data))
  37. end)
  38.  
  39. concommand.Add("gzg_garage_remove",function()
  40. if(GARAGE_PROPS != nil) then
  41. for k,v in pairs(GARAGE_PROPS) do
  42. if(IsValid(v)) then
  43. v:Remove()
  44. end
  45. end
  46. end
  47. GARAGE.Data = {}
  48. end)
  49.  
  50. concommand.Add("gzg_garage_reload",function()
  51. timer.Simple(1,function()
  52. local t = util.JSONToTable(file.Read("garage_data.dat","DATA") or "[]")
  53. if(istable(t)) then
  54. for k,v in pairs(t) do
  55. PRELOAD_DOORS(v[1],v[2])
  56. end
  57. end
  58. end)
  59. end)
  60.  
  61. net.Receive("SendGarageMoney",function(l,ply)
  62. local a,b,c,d = net.ReadFloat(),net.ReadColor(),net.ReadTable(),net.ReadFloat()
  63. if(ply:getDarkRPVar("money") >= d) then
  64. ply:addMoney(-d)
  65. timer.Simple(0.1,function()
  66. local vh = ply:GetVehicle()
  67. vh:SetSkin(a)
  68. vh:SetColor(b)
  69. for k,v in pairs(c) do
  70. vh:SetBodygroup(k,v)
  71. end
  72. end)
  73. end
  74. end)
  75.  
  76. net.Receive("RepairCar",function(l,ply)
  77. if(ply:getDarkRPVar("money") >= GARAGE.RepairPrice) then
  78. ply:addMoney(-GARAGE.RepairPrice)
  79. ply:GetVehicle():SetHealth(ply:GetVehicle():GetMaxHealth() or 100)
  80. end
  81. end)
  82.  
  83. net.Receive("RepairGarageCar",function(l,ply)
  84. ply:GetVehicle():SetHealth(ply:GetVehicle():GetMaxHealth() or 100)
  85. end)
  86.  
  87. net.Receive("CreateGarage",function(l,ply)
  88. table.insert(GARAGE.Data,{ply:GetEyeTrace().HitPos,ply:EyeAngles()})
  89. PRELOAD_DOORS(ply:GetEyeTrace().HitPos,ply:EyeAngles(),ply)
  90. end)
  91.  
  92. hook.Add("Think","DoorResponse",function()
  93. for k,v in pairs(ents.FindByClass("prop_physics")) do
  94. if(v.IsGarageDoor or false) then
  95. b = false
  96. for _,a in pairs(ents.FindInSphere(v:GetPos(),180)) do
  97. if(a:IsPlayer()) then
  98. b = true
  99. end
  100. end
  101. if(b) then
  102. if(v.Out or 0 < 180) then
  103. v.Out = math.Clamp((v.Out or 0) + 2,0,144)
  104. end
  105. else
  106. if(v.Out or 0 > -1) then
  107. v.Out = math.Clamp((v.Out or 0) - 2,0,144)
  108. end
  109. end
  110. v:SetPos(v.Base + Vector(0,0,v.Out or 0))
  111. end
  112. end
  113.  
  114. if CLIENT then
  115. if(!IsValid(LocalPlayer().Lookcamera)) then
  116. LocalPlayer().ShouldMenu = false
  117. end
  118. for k,v in pairs(ents.FindByClass("prop_dynamic")) do
  119. if(v:GetNWBool("Waypoint",false)) then
  120. if(v:GetPos():Distance(LocalPlayer():GetPos()) < 96 && LocalPlayer():InVehicle()) then
  121. LocalPlayer().Lookcamera = v
  122. if(!(LocalPlayer().ShouldMenu or false)) then
  123. if(LocalPlayer().DM != nil) then
  124. LocalPlayer().DM:Remove()
  125. LocalPlayer().DM = nil
  126. end
  127. LocalPlayer().DM = vgui.Create("DGarage")
  128. LocalPlayer().ShouldMenu = true
  129. end
  130. elseif(LocalPlayer().Lookcamera == v) then
  131. LocalPlayer().Lookcamera = nil
  132. LocalPlayer().ShouldMenu = false
  133. end
  134. end
  135. end
  136.  
  137.  
  138. end
  139. end)
  140.  
  141. function drawGarage( ply, pos, angles, fov )
  142. if(IsValid(LocalPlayer().Lookcamera)) then
  143. local ent = LocalPlayer().Lookcamera
  144. local view = {}
  145.  
  146. view.origin = ent:GetPos() + Vector(0,0,100) + ent:GetForward()*72 - ent:GetRight()*96
  147. view.angles = ent:GetAngles() + Angle(35,135+90+10,0)
  148. view.fov = fov
  149.  
  150. return view
  151. end
  152. end
  153.  
  154. hook.Add( "CalcView", "drawGarage", drawGarage )
  155.  
  156. hook.Add( "ShouldDrawLocalPlayer", "drawGarage", function( ply )
  157. if(IsValid(LocalPlayer().Lookcamera)) then
  158. return true
  159. end
  160. end )
  161.  
  162. hook.Add("CreateMove","SetMovementNil",function(cmd)
  163. if((LocalPlayer().ShouldMenu or false) && ispanel(LocalPlayer().DM)) then
  164. cmd:ClearMovement()
  165. cmd:ClearButtons()
  166. end
  167. end)
  168.  
  169. function garagePickup( ply, ent )
  170. if ent.IsGarage or false then
  171. return false
  172. end
  173. end
  174. hook.Add( "PhysgunPickup", "Allow garagePickup Pickup", garagePickup )
  175.  
  176. hook.Add("CanTool","VehicleColor",function( ply, tr, tool )
  177. if (tool == "colour" || tool == "material") and IsValid( tr.Entity ) and tr.Entity:IsVehicle() then
  178. return false
  179. end
  180. end)
  181.  
  182. hook.Add( "CanProperty", "RemoveVehicleProperties", function( ply, property, ent )
  183. if(property == "bodygroups" or property == "skin") then
  184. return false
  185. end
  186. end )
  187.  
  188. local Laser = Material( "garage/neon_light" )
  189. local letter = Material("garage/customs")
  190.  
  191. local function drawBeams(ent,color)
  192. render.DrawBeam( ent:GetPos() + ent:GetRight()*148 - ent:GetUp()*4 - ent:GetForward()*70, ent:GetPos() - ent:GetForward()*70 - ent:GetRight()*148 - ent:GetUp()*4, 10, 10, 10, color )
  193. render.DrawBeam( ent:GetPos() + ent:GetRight()*148 - ent:GetUp()*4 - ent:GetForward()*4, ent:GetPos() - ent:GetForward()*4 - ent:GetRight()*148 - ent:GetUp()*4, 10, 10, 10, color )
  194.  
  195. render.DrawBeam( ent:GetPos() + ent:GetRight()*70 - ent:GetUp()*4 - ent:GetForward()*70, ent:GetPos() + ent:GetRight()*70 - ent:GetUp()*4 + ent:GetForward()*-4, 10, 10, 10, color )
  196. render.DrawBeam( ent:GetPos() - ent:GetRight()*66 - ent:GetUp()*4 - ent:GetForward()*70, ent:GetPos() - ent:GetRight()*66 - ent:GetUp()*4 + ent:GetForward()*-4, 10, 10, 10, color )
  197. end
  198.  
  199. hook.Add("PreDrawTranslucentRenderables","DrawNeon",function()
  200. for k,ent in pairs(ents.FindByClass("prop_physics")) do
  201. if(ent:GetNWBool("IsGarageDoor",false)) then
  202. render.SetMaterial( Laser )
  203.  
  204. local col = HSVToColor( CurTime() % 6 * 60, 1, 1 )
  205. local color = Color(col.r,col.g,col.b,255 + math.cos(CurTime()*math.random(1,100))*65)
  206.  
  207. drawBeams(ent,Color(150,150,150,255))
  208. drawBeams(ent,color)
  209.  
  210. local offset = Vector( 0, 0, 85 )
  211. local ang = Angle(0,0,0)
  212. local pos = ent:GetPos() + offset - ent:GetUp()*6 + ent:GetForward() * 32
  213.  
  214. ang:RotateAroundAxis( ang:Forward(), 90 )
  215.  
  216. cam.Start3D2D( pos, ang, 0.5 )
  217. surface.SetMaterial(letter)
  218. surface.SetDrawColor(255,255,255)
  219. surface.DrawTexturedRect(-256/2+8,-26,316,116)
  220. cam.End3D2D()
  221. end
  222. end
  223.  
  224. for k,b in pairs(ents.FindByClass("prop_dynamic")) do
  225. if(b:GetNWBool("Waypoint",false)) then
  226. local col = HSVToColor( CurTime() % 6 * 60, 1, 1 )
  227. render.SetMaterial( Laser )
  228. render.DrawBeam( b:GetPos() + b:GetRight()*151 + b:GetUp()*2 + b:GetForward()*148, b:GetPos() + b:GetForward()*148 - b:GetRight()*151 + b:GetUp()*2, 10, 1, 1, col )
  229. render.DrawBeam( b:GetPos() - b:GetRight()*148 + b:GetUp()*2 - b:GetForward()*148, b:GetPos() + b:GetForward()*148 - b:GetRight()*148 + b:GetUp()*2, 10, 1, 1, col )
  230. render.DrawBeam( b:GetPos() + b:GetRight()*148 + b:GetUp()*2 - b:GetForward()*148, b:GetPos() + b:GetForward()*148 + b:GetRight()*148 + b:GetUp()*2, 10, 1, 1, col )
  231.  
  232. render.DrawBeam( b:GetPos() + b:GetRight()*151 + b:GetUp()*2 + b:GetForward()*148 + Vector(0,0,140), b:GetPos() + b:GetForward()*148 - b:GetRight()*151 + b:GetUp()*2 + Vector(0,0,140), 10, 1, 1, col )
  233. render.DrawBeam( b:GetPos() - b:GetRight()*148 + b:GetUp()*2 - b:GetForward()*148 + Vector(0,0,140), b:GetPos() + b:GetForward()*148 - b:GetRight()*148 + b:GetUp()*2 + Vector(0,0,140), 10, 1, 1, col )
  234. render.DrawBeam( b:GetPos() + b:GetRight()*148 + b:GetUp()*2 - b:GetForward()*148 + Vector(0,0,140), b:GetPos() + b:GetForward()*148 + b:GetRight()*148 + b:GetUp()*2 + Vector(0,0,140), 10, 1, 1, col )
  235. end
  236. end
  237.  
  238. end)
  239.  
  240. hook.Add("Initialize","CreateGarages",function()
  241. timer.Simple(1,function()
  242. local t = util.JSONToTable(file.Read("garage_data.dat","DATA") or "[]")
  243. if(istable(t)) then
  244. for k,v in pairs(t) do
  245. PRELOAD_DOORS(v[1],v[2])
  246. end
  247. end
  248. end)
  249. end)
  250.  
  251.  
  252. function PRELOAD_DOORS(pos,ang,ply)
  253.  
  254. local bs = pos
  255. local an = Angle(0,ang.y,0)
  256.  
  257. if(!IsValid(ply)) then
  258. ply = ents.Create("prop_dynamic")
  259. ply:SetModel("models/Gibs/HGIBS.mdl")
  260. ply:SetAngles(Angle(0,ang.y,0))
  261. ply:SetPos(pos)
  262. ply:Spawn()
  263. end
  264. local undoList = {}
  265. for k=1,4 do
  266. local fPos = bs + ply:GetForward()*MX[k].y + ply:GetRight()*MX[k].x + Vector(0,0,72) + ply:GetForward()*142 - ply:GetRight()*142
  267. local ent = ents.Create("prop_physics")
  268. ent:SetModel(plt)
  269. ent:SetAngles(Angle(90,an.y+90*k*-1,0))
  270. ent:SetPos(fPos)
  271. ent:Spawn()
  272. ent.IsGarage = true
  273. if(k==4) then
  274. ent.IsGarageDoor = true
  275. ent.Base = ent:GetPos()
  276. ent:SetNWBool("IsGarageDoor",true)
  277. ent:SetMaterial("phoenix_storms/dome")
  278. else
  279. ent:SetMaterial("brick/brick_model")
  280. end
  281. ent:GetPhysicsObject():EnableMotion(false)
  282. table.insert(GARAGE_PROPS,ent)
  283. table.insert(undoList,ent)
  284. end
  285.  
  286. local ent = ents.Create("prop_physics")
  287. ent:SetModel(pltB)
  288. ent:SetAngles(Angle(0,an.y,0))
  289. ent:SetPos(bs + Vector(0,0,144))
  290. ent:Spawn()
  291. ent.IsGarage = true
  292. ent.IsTop = true
  293. ent:SetMaterial("models/props_foliage/tree_deciduous_01a_trunk")
  294. ent:GetPhysicsObject():EnableMotion(false)
  295.  
  296. local wp = ents.Create("prop_dynamic")
  297. wp:SetModel("models/Gibs/HGIBS.mdl")
  298. wp:SetPos(bs + Vector(0,0,0))
  299. wp:SetAngles(Angle(0,an.y,0))
  300. wp:Spawn()
  301. wp:SetNWBool("Waypoint",true)
  302. wp.Owner = nil
  303. wp:SetRenderMode(RENDERMODE_TRANSALPHA)
  304. wp:SetColor(Color(0,0,0,0))
  305. wp:SetMoveType(MOVETYPE_NONE)
  306.  
  307. table.insert(undoList,ent)
  308. table.insert(undoList,wp)
  309. table.insert(GARAGE_PROPS,ent)
  310. table.insert(GARAGE_PROPS,wp)
  311.  
  312. if(ply:IsPlayer()) then
  313. undo.Create( "prop" )
  314. for k,v in pairs(undoList) do
  315. undo.AddEntity( v )
  316. end
  317. undo.SetPlayer( ply )
  318. undo.SetCustomUndoText( "Undone Garage" )
  319. undo.Finish()
  320. else
  321. ply:Remove()
  322. end
  323.  
  324. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement