Advertisement
Roite

swdf

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