Guest User

Untitled

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