Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TOOL.Category = "Render"
- TOOL.Name = "One Way Prop"
- TOOL.Command = nil
- TOOL.ConfigName = ""
- local MAX_ONEWAY_PROPS_PER_PLAYER = 5
- if CLIENT then
- language.Add("Tool.onewayprop.name", "One Way Prop")
- language.Add("Tool.onewayprop.desc", "Make a prop transparent from one side, but not from the other.")
- language.Add("Tool.onewayprop.0", "Left-click to make the prop transparent from the front, right-click to make it transparent from the back.")
- function TOOL.BuildCPanel(panel)
- panel:AddControl("Header", {Text = "One Way Prop", Description = "Make a prop transparent from one side, but not from the other."})
- end
- end
- function TOOL:LeftClick(trace)
- if CLIENT then return true end
- if not self:CheckLimit() then return false end
- if self:GetOwner():GetNWInt("onewayprop_count", 0) >= MAX_ONEWAY_PROPS_PER_PLAYER then
- self:GetOwner():ChatPrint("You have reached the maximum number of one-way props allowed.")
- return false
- end
- if not trace.HitNonWorld then return false end
- local ent = trace.Entity
- if not IsValid(ent) then return false end
- if CLIENT then return true end
- if not self:GetSWEP():CheckLimit("onewayprops") then return false end
- local ang = trace.HitNormal:Angle()
- ang:RotateAroundAxis(ang:Right(), -90)
- local onewayprop = ents.Create("prop_physics")
- onewayprop:SetModel(ent:GetModel())
- onewayprop:SetPos(trace.HitPos)
- onewayprop:SetAngles(ang)
- onewayprop:Spawn()
- ent:SetNoDraw(true)
- constraint.Weld(ent, onewayprop, 0, 0, 0, true)
- undo.Create("One Way Prop")
- undo.AddEntity(onewayprop)
- undo.AddEntity(ent)
- undo.SetPlayer(self:GetOwner())
- undo.Finish()
- self:GetOwner():AddCleanup("onewayprops", onewayprop)
- self:GetOwner():AddCleanup("onewayprops", ent)
- return true
- end
- function TOOL:RightClick(trace)
- if not trace.HitNonWorld then return false end
- local ent = trace.Entity
- if not IsValid(ent) then return false end
- if CLIENT then return true end
- if not self:GetSWEP():CheckLimit("onewayprops") then return false end
- local ang = trace.HitNormal:Angle()
- ang:RotateAroundAxis(ang:Right(), 90)
- local onewayprop = ents.Create("prop_physics")
- onewayprop:SetModel(ent:GetModel())
- onewayprop:SetPos(trace.HitPos)
- onewayprop:SetAngles(ang)
- onewayprop:Spawn()
- ent:SetNoDraw(true)
- constraint.Weld(ent, onewayprop, 0, 0, 0, true)
- -- Set the render mode of the onewayprop to "rendering only one way" (13) to make it transparent from one side only.
- onewayprop:SetRenderMode(RENDERMODE_TRANSCOLOR)
- onewayprop:SetKeyValue("renderamt", "0")
- onewayprop:SetKeyValue("rendercolor", "255 255 255")
- undo.Create("One Way Prop")
- undo.AddEntity(onewayprop)
- undo.AddEntity(ent)
- undo.SetPlayer(self:GetOwner())
- undo.Finish()
- self:GetOwner():AddCleanup("onewayprops", onewayprop)
- self:GetOwner():AddCleanup("onewayprops", ent)
- return true
- end
- function TOOL:PostEntityPaste(ply, ent, created_entities)
- if CLIENT then return end
- if not IsValid(ply) or not ply:IsPlayer() then return end
- local count = ply:GetNWInt("onewayprop_count", 0)
- ply:SetNWInt("onewayprop_count", count + 1)
- end
- function TOOL:Holster()
- if CLIENT then return end
- if not IsValid(self:GetOwner()) or not self:GetOwner():IsPlayer() then return end
- local count = self:GetOwner():GetNWInt("onewayprop_count", 0)
- self:GetOwner():SetNWInt("onewayprop_count", count - 1)
- end
- function TOOL:Reload(trace)
- if not trace.HitNonWorld then return false end
- local ent = trace.Entity
- if not IsValid(ent) then return false end
- if CLIENT then return true end
- if not ent:GetNoDraw() then return false end
- local onewayprop = constraint.GetAllConstrainedEntities(ent)[2]
- if not IsValid(onewayprop) then return false end
- onewayprop:Remove()
- ent:SetNoDraw(false)
- undo.Create("One Way Prop")
- undo.AddEntity(ent)
- undo.SetPlayer(self:GetOwner())
- undo.Finish()
- self:GetOwner():AddCleanup("onewayprops", ent)
- return true
- end
- -- Add the tool to the spawn menu
- if CLIENT then
- language.Add("Tool.onewayprop.name", "One Way Prop")
- language.Add("Tool.onewayprop.desc", "Make a prop transparent from one side, but not from the other.")
- language.Add("Tool.onewayprop.0", "Left-click to make the prop transparent from the front, right-click to make it transparent from the back.")
- function TOOL.BuildCPanel(panel)
- panel:AddControl("Header", {Text = "One Way Prop", Description = "Make a prop transparent from one side, but not from the other."})
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement