Advertisement
wifiboost

Untitled

Mar 11th, 2023
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. TOOL.Category = "Render"
  2. TOOL.Name = "One Way Prop"
  3. TOOL.Command = nil
  4. TOOL.ConfigName = ""
  5. local MAX_ONEWAY_PROPS_PER_PLAYER = 5
  6. if CLIENT then
  7. language.Add("Tool.onewayprop.name", "One Way Prop")
  8. language.Add("Tool.onewayprop.desc", "Make a prop transparent from one side, but not from the other.")
  9. language.Add("Tool.onewayprop.0", "Left-click to make the prop transparent from the front, right-click to make it transparent from the back.")
  10.  
  11. function TOOL.BuildCPanel(panel)
  12. panel:AddControl("Header", {Text = "One Way Prop", Description = "Make a prop transparent from one side, but not from the other."})
  13. end
  14. end
  15.  
  16. function TOOL:LeftClick(trace)
  17. if CLIENT then return true end
  18. if not self:CheckLimit() then return false end
  19. if self:GetOwner():GetNWInt("onewayprop_count", 0) >= MAX_ONEWAY_PROPS_PER_PLAYER then
  20. self:GetOwner():ChatPrint("You have reached the maximum number of one-way props allowed.")
  21. return false
  22. end
  23. if not trace.HitNonWorld then return false end
  24.  
  25. local ent = trace.Entity
  26. if not IsValid(ent) then return false end
  27. if CLIENT then return true end
  28.  
  29. if not self:GetSWEP():CheckLimit("onewayprops") then return false end
  30.  
  31. local ang = trace.HitNormal:Angle()
  32. ang:RotateAroundAxis(ang:Right(), -90)
  33.  
  34. local onewayprop = ents.Create("prop_physics")
  35. onewayprop:SetModel(ent:GetModel())
  36. onewayprop:SetPos(trace.HitPos)
  37. onewayprop:SetAngles(ang)
  38. onewayprop:Spawn()
  39.  
  40. ent:SetNoDraw(true)
  41.  
  42. constraint.Weld(ent, onewayprop, 0, 0, 0, true)
  43.  
  44. undo.Create("One Way Prop")
  45. undo.AddEntity(onewayprop)
  46. undo.AddEntity(ent)
  47. undo.SetPlayer(self:GetOwner())
  48. undo.Finish()
  49.  
  50. self:GetOwner():AddCleanup("onewayprops", onewayprop)
  51. self:GetOwner():AddCleanup("onewayprops", ent)
  52.  
  53. return true
  54. end
  55.  
  56. function TOOL:RightClick(trace)
  57. if not trace.HitNonWorld then return false end
  58. local ent = trace.Entity
  59. if not IsValid(ent) then return false end
  60. if CLIENT then return true end
  61.  
  62. if not self:GetSWEP():CheckLimit("onewayprops") then return false end
  63.  
  64. local ang = trace.HitNormal:Angle()
  65. ang:RotateAroundAxis(ang:Right(), 90)
  66.  
  67. local onewayprop = ents.Create("prop_physics")
  68. onewayprop:SetModel(ent:GetModel())
  69. onewayprop:SetPos(trace.HitPos)
  70. onewayprop:SetAngles(ang)
  71. onewayprop:Spawn()
  72.  
  73. ent:SetNoDraw(true)
  74.  
  75. constraint.Weld(ent, onewayprop, 0, 0, 0, true)
  76.  
  77. -- Set the render mode of the onewayprop to "rendering only one way" (13) to make it transparent from one side only.
  78. onewayprop:SetRenderMode(RENDERMODE_TRANSCOLOR)
  79. onewayprop:SetKeyValue("renderamt", "0")
  80. onewayprop:SetKeyValue("rendercolor", "255 255 255")
  81.  
  82. undo.Create("One Way Prop")
  83. undo.AddEntity(onewayprop)
  84. undo.AddEntity(ent)
  85. undo.SetPlayer(self:GetOwner())
  86. undo.Finish()
  87.  
  88. self:GetOwner():AddCleanup("onewayprops", onewayprop)
  89. self:GetOwner():AddCleanup("onewayprops", ent)
  90.  
  91. return true
  92. end
  93.  
  94. function TOOL:PostEntityPaste(ply, ent, created_entities)
  95. if CLIENT then return end
  96. if not IsValid(ply) or not ply:IsPlayer() then return end
  97. local count = ply:GetNWInt("onewayprop_count", 0)
  98. ply:SetNWInt("onewayprop_count", count + 1)
  99. end
  100.  
  101. function TOOL:Holster()
  102. if CLIENT then return end
  103. if not IsValid(self:GetOwner()) or not self:GetOwner():IsPlayer() then return end
  104. local count = self:GetOwner():GetNWInt("onewayprop_count", 0)
  105. self:GetOwner():SetNWInt("onewayprop_count", count - 1)
  106. end
  107.  
  108. function TOOL:Reload(trace)
  109. if not trace.HitNonWorld then return false end
  110. local ent = trace.Entity
  111. if not IsValid(ent) then return false end
  112. if CLIENT then return true end
  113.  
  114. if not ent:GetNoDraw() then return false end
  115.  
  116. local onewayprop = constraint.GetAllConstrainedEntities(ent)[2]
  117. if not IsValid(onewayprop) then return false end
  118.  
  119. onewayprop:Remove()
  120.  
  121. ent:SetNoDraw(false)
  122.  
  123. undo.Create("One Way Prop")
  124. undo.AddEntity(ent)
  125. undo.SetPlayer(self:GetOwner())
  126. undo.Finish()
  127.  
  128. self:GetOwner():AddCleanup("onewayprops", ent)
  129.  
  130. return true
  131. end
  132.  
  133. -- Add the tool to the spawn menu
  134. if CLIENT then
  135. language.Add("Tool.onewayprop.name", "One Way Prop")
  136. language.Add("Tool.onewayprop.desc", "Make a prop transparent from one side, but not from the other.")
  137. language.Add("Tool.onewayprop.0", "Left-click to make the prop transparent from the front, right-click to make it transparent from the back.")
  138. function TOOL.BuildCPanel(panel)
  139. panel:AddControl("Header", {Text = "One Way Prop", Description = "Make a prop transparent from one side, but not from the other."})
  140. end
  141. end
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement