Advertisement
Pipeline

door.lua

Jun 24th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Door stool by High6*/
  2. /* v1.6b */
  3. /* */
  4. local defaultlimit = 5
  5.  
  6. TOOL.ClientConVar[ "class" ] = "prop_dynamic"
  7. TOOL.ClientConVar[ "model" ] = "models/props_combine/combine_door01.mdl"
  8. TOOL.ClientConVar[ "open" ] = "1"
  9. TOOL.ClientConVar[ "close" ] = "2"
  10. TOOL.ClientConVar[ "autoclose" ] = "0"
  11. TOOL.ClientConVar[ "closetime" ] = "5"
  12. TOOL.ClientConVar[ "hardware" ] = "1"
  13. TOOL.ClientConVar[ "skin" ] = "0"
  14. cleanup.Register( "door" )
  15.  
  16. TOOL.Category = "Construction" // Name of the category
  17. TOOL.Name = "#Door" // Name to display
  18. TOOL.Command = nil // Command on click (nil for default)
  19. TOOL.ConfigName = "" // Config file name (nil for default)
  20.  
  21. local GhostEntity
  22. --prop_door_rotating
  23. --prop_dynamic
  24. if SERVER then
  25. local Doors = {}
  26.  
  27. local function Save( save )
  28.  
  29. saverestore.WriteTable( Doors, save )
  30.  
  31. end
  32.  
  33. local function Restore( restore )
  34.  
  35. Doors = saverestore.ReadTable( restore )
  36.  
  37. end
  38.  
  39. saverestore.AddSaveHook( "Doors", Save )
  40. saverestore.AddRestoreHook( "Doors", Restore )
  41.  
  42.  
  43. if !ConVarExists("sbox_maxdoors") then CreateConVar("sbox_maxdoors", defaultlimit, FCVAR_NOTIFY ) end
  44. function opendoor(ply,ent,autoclose,closetime)
  45. if not ent:IsValid() then return end
  46. ent:Fire("setanimation","open","0")
  47. if autoclose == 1 then ent:Fire("setanimation","close",closetime) end
  48. end
  49. function closedoor(ply,ent)
  50. if not ent:IsValid() then return end
  51. ent:Fire("setanimation","close","0")
  52. end
  53. numpad.Register( "door_open", opendoor )
  54. numpad.Register( "door_close", closedoor )
  55. function makedoor(ply,trace,ang,model,open,close,autoclose,closetime,class,hardware,skin)
  56. if ( !ply:CheckLimit( "doors" ) ) then return nil end
  57. local entit = ents.Create(class)
  58. entit:SetModel(model)
  59. local minn = entit:OBBMins()
  60. local newpos = Vector(trace.HitPos.X,trace.HitPos.Y,trace.HitPos.Z - (trace.HitNormal.z * minn.z) )
  61. entit:SetPos( newpos )
  62. entit:SetAngles(Angle(0,ang.Yaw,0))
  63. if tostring(class) == "prop_dynamic" then
  64. entit:SetKeyValue("solid","6")
  65. entit:SetKeyValue("MinAnimTime","1")
  66. entit:SetKeyValue("MaxAnimTime","5")
  67. elseif tostring(class) == "prop_door_rotating" then
  68. entit:SetKeyValue("hardware",hardware)
  69. entit:SetKeyValue("distance","90")
  70. entit:SetKeyValue("speed","100")
  71. entit:SetKeyValue("returndelay","-1")
  72. entit:SetKeyValue("spawnflags","8192")
  73. entit:SetKeyValue("forceclosed","0")
  74. entit:Fire( "Skin", skin )
  75. else
  76. Msg(class .. " is not a valid class. Bitch at high6 about this error.\n") --HeHe
  77. return
  78. end
  79. entit:Spawn()
  80. entit:Activate()
  81. numpad.OnDown(ply,open,"door_open",entit,autoclose,closetime)
  82. if tostring(class) != "prop_door_rotating" then
  83. numpad.OnDown(ply,close,"door_close",entit,autoclose,closetime)
  84. end
  85. ply:AddCount( "doors", entit )
  86. ply:AddCleanup( "doors", entit )
  87.  
  88. local index = ply:UniqueID()
  89. Doors[ index ] = Doors[ index ] or {}
  90. Doors[ index ][1] = Doors[ index ][1] or {}
  91. table.insert( Doors[ index ][1], entit )
  92.  
  93.  
  94. undo.Create("Door")
  95. undo.AddEntity( entit )
  96. undo.SetPlayer( ply )
  97. undo.Finish()
  98. end
  99. end
  100.  
  101. if ( CLIENT ) then
  102.  
  103. language.Add( "Tool_door_name", "Door" )
  104. language.Add( "Tool_door_desc", "Spawn a Door" )
  105. language.Add( "Tool_door_0", "Click somewhere to spawn a door." )
  106.  
  107. language.Add( "Undone_door", "Undone door" )
  108. language.Add( "Cleanup_door", "door" )
  109. language.Add( "SBoxLimit_doors", "Max Doors Reached!" )
  110. language.Add( "Cleaned_door", "Cleaned up all doors" )
  111.  
  112. end
  113.  
  114.  
  115. function TOOL:LeftClick( tr )
  116. if CLIENT then return true end
  117. local model = self:GetClientInfo( "model" )
  118. local open = self:GetClientNumber( "open" )
  119. local close = self:GetClientNumber( "close" )
  120. local class = self:GetClientInfo( "class" )
  121. local ply = self:GetOwner()
  122. local ang = ply:GetAimVector():Angle()
  123. local autoclose = self:GetClientNumber( "autoclose" )
  124. local closetime = self:GetClientNumber( "closetime" )
  125. local hardware = self:GetClientNumber( "hardware" )
  126. local skin = self:GetClientNumber( "skin" )
  127. if ( !self:GetSWEP():CheckLimit( "doors" ) ) then return false end
  128. makedoor(ply,tr,ang,model,open,close,autoclose,closetime,class,hardware,skin)
  129.  
  130. return true
  131.  
  132. end
  133.  
  134. function TOOL.BuildCPanel( CPanel )
  135.  
  136. // HEADER
  137. CPanel:AddControl( "Header", { Text = "#Tool_door_name", Description = "#Tool_door_desc" } )
  138.  
  139. // PRESETS
  140. local params = { Label = "#Presets", MenuButton = 1, Folder = "door", Options = {}, CVars = {} }
  141.  
  142. params.Options.default = {
  143. door_model = "models/props_combine/combine_door01.mdl",
  144. door_open = 1,
  145. door_close = 2 }
  146.  
  147. table.insert( params.CVars, "door_open" )
  148. table.insert( params.CVars, "door_close" )
  149. table.insert( params.CVars, "door_model" )
  150.  
  151. CPanel:AddControl( "ComboBox", params )
  152.  
  153.  
  154. // KEY
  155. CPanel:AddControl( "Numpad", { Label = "#Door Open",Label2 = "#Door Close", Command = "door_open",Command2 = "door_close", ButtonSize = 22 } )
  156.  
  157.  
  158. // EMITTERS
  159. local params = { Label = "#Models", Height = 150, Options = {} }
  160. params.Options[ "Tall Combine Door" ] = { door_class = "prop_dynamic",door_model = "models/props_combine/combine_door01.mdl" }
  161. params.Options[ "Elevator Door" ] = { door_class = "prop_dynamic",door_model = "models/props_lab/elevatordoor.mdl" }
  162. params.Options[ "Combine Door" ] = { door_class = "prop_dynamic",door_model = "models/combine_gate_Vehicle.mdl" }
  163. params.Options[ "Small Combine Door" ] = { door_class = "prop_dynamic",door_model = "models/combine_gate_citizen.mdl" }
  164. params.Options[ "Door, no handle" ] = { door_hardware = "0",door_class = "prop_door_rotating",door_model = "models/props_c17/door01_left.mdl" }
  165. params.Options[ "Door, handle" ] = { door_hardware = "1",door_class = "prop_door_rotating",door_model = "models/props_c17/door01_left.mdl" }
  166. params.Options[ "Door, push bar" ] = { door_hardware = "2",door_class = "prop_door_rotating",door_model = "models/props_c17/door01_left.mdl" }
  167. params.Options[ "Blast Door" ] = { door_class = "prop_dynamic",door_model = "models/props_doors/doorKLab01.mdl" }
  168. CPanel:AddControl( "ListBox", params )
  169. CPanel:AddControl( "Slider", { Label = "#Skin (Rotating doors only)",
  170. Type = "Integer",
  171. Min = 0,
  172. Max = 13,
  173. Command = "door_skin" } )
  174.  
  175. CPanel:AddControl( "Slider", { Label = "#AutoClose Delay",
  176. Type = "Float",
  177. Min = 0,
  178. Max = 100,
  179. Command = "door_closetime" } )
  180. CPanel:AddControl( "Checkbox", { Label = "#AutoClose", Command = "door_autoclose" } )
  181.  
  182. end
  183.  
  184. function TOOL:UpdateGhostThruster( ent, Player )
  185.  
  186. if ( !ent ) then return end
  187. if ( !ent:IsValid() ) then return end
  188.  
  189. local tr = utilx.GetPlayerTrace( Player, Player:GetCursorAimVector() )
  190. local trace = util.TraceLine( tr )
  191.  
  192. if (!trace.Hit) then return end
  193.  
  194. local ang = Player:GetAimVector():Angle()
  195. local minn = ent:OBBMins()
  196. local newpos = Vector(trace.HitPos.X,trace.HitPos.Y,trace.HitPos.Z - (trace.HitNormal.z * minn.z))
  197. ent:SetPos( newpos )
  198. ent:SetAngles(Angle(0,ang.Yaw,0))
  199. ent:SetSkin( self:GetClientNumber( "skin" ) )
  200.  
  201. end
  202.  
  203.  
  204. function TOOL:Think()
  205.  
  206. if (!self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() != self:GetClientInfo( "model" )) then
  207. self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector(0,0,0), Angle(0,0,0) )
  208. end
  209.  
  210. self:UpdateGhostThruster( self.GhostEntity, self:GetOwner() )
  211.  
  212. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement