Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. if CLIENT then return end
  2.  
  3. -- This entire thing is just the portion of my Door Locker code that allows for the door to be broken down.
  4. -- Its all my code but the idea started as a copy of a concept I saw on Coderhire but I didnt want to pay for
  5. -- Edited by Rynoxx (http://steamcommunity.com/profiles/76561198004177027) to allow doors to automaticly respawn and be respawned by command(s).
  6.  
  7. CreateConVar("db_doorhealth", 300, {FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE, FCVAR_NOTIFY},"How strong the doors are.")
  8. CreateConVar("db_respawntimer", 30, {FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE, FCVAR_NOTIFY},"How long it should take for doors to respawn.")
  9. CreateConVar("db_lockopen", 1, {FCVAR_SERVER_CAN_EXECUTE, FCVAR_ARCHIVE, FCVAR_NOTIFY},"Whether or not doors should be opened and unlocked after being shot open.")
  10.  
  11. cvars.AddChangeCallback("db_doorhealth", function()
  12. for k,v in pairs(ents.GetAll() ) do
  13. if v:GetClass() == "prop_door_rotating" then
  14. local health = GetConVar("db_doorhealth"):GetInt()
  15. v:SetHealth(health)
  16. end
  17. end
  18. print("[DoorBuster] Health changed. Updating doors...")
  19. end)
  20.  
  21. hook.Add( "InitPostEntity", "ITSALLIIIVVEEE", function()
  22. timer.Simple(5, function()
  23. for k,v in pairs( ents.GetAll() ) do
  24. if v:GetClass() == "prop_door_rotating" then
  25. local health = GetConVar("db_doorhealth"):GetInt()
  26. v:SetHealth(health)
  27. end
  28. end
  29. print("[DoorBuster] All doors have been prepped")
  30. end )
  31. end)
  32.  
  33. knockedDoors = knockedDoors or {}
  34.  
  35. hook.Add("EntityTakeDamage","BigBadWolfIsJealous", function(prop, dmginfo)
  36. if (prop:GetClass() == "prop_door_rotating" and IsValid(prop) and dmginfo:GetAttacker():GetActiveWeapon() == "m9k_spas12")then
  37. local doorhealth = prop:Health()
  38. local dmgtaken = dmginfo:GetDamage()
  39.  
  40. prop:SetHealth(doorhealth - dmgtaken) -- Takes damage for the door
  41.  
  42. if prop:Health() <= 0 and (!prop.phys_door or !IsValid(prop.phys_door)) then
  43.  
  44. -- Now we create a prop version of the door to be knocked down for looks
  45. local dprop = ents.Create( "prop_physics" )
  46. dprop:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
  47. dprop:SetMoveType(MOVETYPE_VPHYSICS)
  48. dprop:SetSolid(SOLID_BBOX)
  49. dprop:SetPos( prop:GetPos() + Vector(0, 0, 2))
  50. dprop:SetAngles( prop:GetAngles() )
  51. dprop:SetModel( prop:GetModel() )
  52. dprop:SetSkin( prop:GetSkin() )
  53. table.insert(knockedDoors, prop)
  54. -- prop:Remove() -- do NOT remove the door
  55. prop:Extinguish() -- A fix for the fire glitch
  56. prop:SetNoDraw(true) -- Instead we're going to hide it
  57. prop:SetNotSolid(true) -- And remove the collision of it
  58.  
  59. if GetConVar("db_lockopen"):GetInt() > 0 then
  60. prop:Fire("unlock", 0)
  61. prop:Fire("open", 0)
  62. end
  63.  
  64. dprop:Spawn()
  65. -- Who doesnt like a little pyrotechnics eh?
  66. dprop:EmitSound( "physics/wood/wood_crate_break3.wav" )
  67. local effectdata = EffectData()
  68. effectdata:SetOrigin( dprop:GetPos() + dprop:OBBCenter() )
  69. effectdata:SetMagnitude( 5 )
  70. effectdata:SetScale( 2 )
  71. effectdata:SetRadius( 5 )
  72. util.Effect( "Sparks", effectdata )
  73.  
  74. prop.phys_door = dprop
  75.  
  76. if GetConVar("db_respawntimer"):GetInt() > 0 then
  77. timer.Simple(GetConVar("db_respawntimer"):GetInt(), function()
  78. ResetDoor(prop)
  79. end)
  80. end
  81. end
  82. end
  83. end)
  84.  
  85. function ResetDoor(prop)
  86. if IsValid(prop) then
  87. prop:SetHealth(GetConVar("db_doorhealth"):GetInt())
  88. prop:SetNoDraw(false)
  89. prop:SetNotSolid(false)
  90. if IsValid(prop.phys_door) then
  91. SafeRemoveEntity(prop.phys_door)
  92. prop.phys_door = nil
  93. end
  94.  
  95. for i = 1, #knockedDoors do
  96. if knockedDoors[i] == prop then
  97. knockedDoors[i] = nil
  98. end
  99. end
  100. end
  101. end
  102.  
  103. function ResetAllDoors()
  104. for i = 1, #knockedDoors do
  105. ResetDoor(knockedDoors[i])
  106. end
  107. end
  108.  
  109. concommand.Add("db_resetdoors", function(ply)
  110. if IsValid(ply) and !ply:IsAdmin() then return end -- Admin and RCon/Server Console only
  111. ResetAllDoors()
  112. end)
  113.  
  114. hook.Add("PlayerSay", "DoorsAndDoorAccessories", function(ply, text) -- Chat commands to make life easier
  115. local text = string.lower(text)
  116.  
  117. if ( string.sub( text, 1, 11 ) == "!checkdoor" ) then
  118. local tr = ply:GetEyeTrace()
  119. local door = tr.Entity
  120. if (IsValid(door)) then
  121. if door:GetClass() == "prop_door_rotating" then
  122. ply:ChatPrint("That is a valid door!")
  123. else
  124. ply:ChatPrint("That is not a valid door!")
  125. end
  126. else
  127. ply:ChatPrint("That is not a door!")
  128. end
  129. return false
  130. end
  131.  
  132. if ( string.sub( text, 1, 11 ) == "!doorhealth" ) then
  133. local tr = ply:GetEyeTrace()
  134. local door = tr.Entity
  135. if (IsValid(door) and door:GetClass() == "prop_door_rotating") then
  136. ply:ChatPrint("That door's health is " .. door:Health())
  137. else
  138. ply:ChatPrint("That is not a valid door!")
  139. end
  140. return false
  141. end
  142.  
  143. if ( string.sub(text, 1, 11) == "!resetdoor" ) then
  144. if ply:IsAdmin() or ply:IsSuperAdmin() then
  145. ResetAllDoors()
  146. end
  147. end
  148. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement