adding wire lamp (don't remember who is the author)
This commit is contained in:
60
wire/lua/entities/gmod_wire_lamp/cl_init.lua
Normal file
60
wire/lua/entities/gmod_wire_lamp/cl_init.lua
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
include('shared.lua')
|
||||||
|
|
||||||
|
local matLight = Material( "sprites/light_ignorez" )
|
||||||
|
local matBeam = Material( "effects/lamp_beam" )
|
||||||
|
|
||||||
|
ENT.RenderGroup = RENDERGROUP_BOTH
|
||||||
|
|
||||||
|
function ENT:Initialize()
|
||||||
|
|
||||||
|
self.PixVis = util.GetPixelVisibleHandle()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
/*---------------------------------------------------------
|
||||||
|
Name: Draw
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
function ENT:Draw()
|
||||||
|
|
||||||
|
self.BaseClass.Draw( self )
|
||||||
|
|
||||||
|
Wire_Render(self.Entity)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
/*---------------------------------------------------------
|
||||||
|
Name: DrawTranslucent
|
||||||
|
Desc: Draw translucent
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
function ENT:DrawTranslucent()
|
||||||
|
|
||||||
|
local LightNrm = self.Entity:GetAngles():Up()
|
||||||
|
local ViewDot = EyeVector():Dot( LightNrm )
|
||||||
|
local r, g, b, a = self.Entity:GetColor()
|
||||||
|
local LightPos = self.Entity:GetPos() + LightNrm * -6
|
||||||
|
|
||||||
|
// glow sprite
|
||||||
|
/*
|
||||||
|
render.SetMaterial( matBeam )
|
||||||
|
|
||||||
|
local BeamDot = BeamDot = 0.25
|
||||||
|
|
||||||
|
render.StartBeam( 3 )
|
||||||
|
render.AddBeam( LightPos + LightNrm * 1, 128, 0.0, Color( r, g, b, 255 * BeamDot) )
|
||||||
|
render.AddBeam( LightPos - LightNrm * 100, 128, 0.5, Color( r, g, b, 64 * BeamDot) )
|
||||||
|
render.AddBeam( LightPos - LightNrm * 200, 128, 1, Color( r, g, b, 0) )
|
||||||
|
render.EndBeam()
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ViewDot < 0 ) then return end
|
||||||
|
|
||||||
|
render.SetMaterial( matLight )
|
||||||
|
local Visibile = util.PixelVisible( LightPos, 16, self.PixVis )
|
||||||
|
local Size = math.Clamp( 512 * (1 - Visibile*ViewDot),128, 512 )
|
||||||
|
|
||||||
|
local Col = Color( r, g, b, 200*Visibile*ViewDot )
|
||||||
|
|
||||||
|
render.DrawSprite( LightPos, Size, Size, Col, Visibile * ViewDot )
|
||||||
|
|
||||||
|
end
|
||||||
104
wire/lua/entities/gmod_wire_lamp/init.lua
Normal file
104
wire/lua/entities/gmod_wire_lamp/init.lua
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
|
||||||
|
AddCSLuaFile( "cl_init.lua" )
|
||||||
|
AddCSLuaFile( "shared.lua" )
|
||||||
|
|
||||||
|
ENT.WireDebugName = "Lamp"
|
||||||
|
|
||||||
|
local MODEL = Model( "models/props_wasteland/prison_lamp001c.mdl" )
|
||||||
|
|
||||||
|
/*---------------------------------------------------------
|
||||||
|
Name: Initialize
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
function ENT:Initialize()
|
||||||
|
|
||||||
|
self.Entity:SetModel( MODEL )
|
||||||
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
||||||
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
||||||
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
||||||
|
|
||||||
|
self.flashlight = ents.Create("effect_flashlight")
|
||||||
|
self.flashlight:SetPos( self.Entity:GetPos() )
|
||||||
|
self.flashlight:SetAngles( self.Entity:GetAngles() )
|
||||||
|
self.flashlight:SetParent( self.Entity )
|
||||||
|
self.flashlight:SetColor( self.Entity:GetVar( "lightr", 255 ), self.Entity:GetVar( "lightg", 255 ), self.Entity:GetVar( "lightb", 255 ), 255 )
|
||||||
|
self.flashlight:Spawn()
|
||||||
|
|
||||||
|
local phys = self.Entity:GetPhysicsObject()
|
||||||
|
|
||||||
|
if (phys:IsValid()) then
|
||||||
|
phys:Wake()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.r = self.Entity:GetVar( "lightr", 255 )
|
||||||
|
self.g = self.Entity:GetVar( "lightg", 255 )
|
||||||
|
self.b = self.Entity:GetVar( "lightb", 255 )
|
||||||
|
|
||||||
|
self.Inputs = Wire_CreateInputs(self.Entity, { "Red", "Green", "Blue" })
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function ENT:Setup( r, g, b )
|
||||||
|
|
||||||
|
self:SetOverlayText( "Red:" .. r .. " Green:" .. g .. " Blue" .. b )
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------
|
||||||
|
Name: Sets the color of the light
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
function ENT:SetLightColor( r, g, b )
|
||||||
|
|
||||||
|
self.Entity:SetVar( "lightr", r )
|
||||||
|
self.Entity:SetVar( "lightg", g )
|
||||||
|
self.Entity:SetVar( "lightb", b )
|
||||||
|
|
||||||
|
self.Entity:SetColor( r, g, b, 255 )
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
/*---------------------------------------------------------
|
||||||
|
Name: OnTakeDamage
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
function ENT:OnTakeDamage( dmginfo )
|
||||||
|
self.Entity:TakePhysicsDamage( dmginfo )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------
|
||||||
|
Name: Use
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
function ENT:Use( activator, caller )
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
/*---------------------------------------------------------
|
||||||
|
Name: TriggerInput
|
||||||
|
Desc: the inputs
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
function ENT:TriggerInput(iname, value)
|
||||||
|
if (iname == "Red") then
|
||||||
|
self.r = value
|
||||||
|
elseif (iname == "Green") then
|
||||||
|
self.g = value
|
||||||
|
elseif (iname == "Blue") then
|
||||||
|
self.b = value
|
||||||
|
end
|
||||||
|
self:SetLightColor( self.r, self.g, self.b)
|
||||||
|
self.flashlight:SetColor( self.Entity:GetVar( "lightr", 255 ), self.Entity:GetVar( "lightg", 255 ), self.Entity:GetVar( "lightb", 255 ), 255 )
|
||||||
|
self:SetOverlayText( "Red:" .. self.r .. " Green:" .. self.g .. " Blue" .. self.b )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function ENT:OnRemove()
|
||||||
|
Wire_Remove(self.Entity)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ENT:OnRestore()
|
||||||
|
Wire_Restored(self.Entity)
|
||||||
|
end
|
||||||
|
|
||||||
|
include('shared.lua')
|
||||||
|
|
||||||
13
wire/lua/entities/gmod_wire_lamp/shared.lua
Normal file
13
wire/lua/entities/gmod_wire_lamp/shared.lua
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
ENT.Type = "anim"
|
||||||
|
ENT.Base = "base_gmodentity"
|
||||||
|
|
||||||
|
ENT.PrintName = ""
|
||||||
|
ENT.Author = ""
|
||||||
|
ENT.Contact = ""
|
||||||
|
ENT.Purpose = ""
|
||||||
|
ENT.Instructions = ""
|
||||||
|
|
||||||
|
ENT.Spawnable = false
|
||||||
|
ENT.AdminSpawnable = false
|
||||||
196
wire/lua/weapons/gmod_tool/stools/wire_lamp.lua
Normal file
196
wire/lua/weapons/gmod_tool/stools/wire_lamp.lua
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
|
||||||
|
TOOL.Category = "Wire - Display"
|
||||||
|
TOOL.Name = "Lamps"
|
||||||
|
TOOL.Command = nil
|
||||||
|
TOOL.ConfigName = ""
|
||||||
|
|
||||||
|
if ( CLIENT ) then
|
||||||
|
language.Add( "Tool_wire_lamp_name", "Wire Lamps" )
|
||||||
|
language.Add( "Tool_wire_lamp_desc", "Spawns a lamp for use with the wire system." )
|
||||||
|
language.Add( "Tool_wire_lamp_0", "Primary: Create hanging lamp Secondary: Create unattached lamp" )
|
||||||
|
language.Add( "WireLampTool_RopeLength", "Rope Length:")
|
||||||
|
language.Add( "WireLampTool_Color", "Color:" )
|
||||||
|
language.Add( "SBoxLimit_wire_lamps", "You've hit the wire lamps limit!" )
|
||||||
|
language.Add( "undone_WireLamp", "Undone Wire Lamp" )
|
||||||
|
language.Add( "Cleanup_wire_lamp", "Wire Lamps" )
|
||||||
|
language.Add( "Cleaned_wire_lamp", "Cleaned up all Wire Lamps" )
|
||||||
|
end
|
||||||
|
|
||||||
|
if (SERVER) then
|
||||||
|
CreateConVar('sbox_maxwire_lamps', 10)
|
||||||
|
end
|
||||||
|
|
||||||
|
TOOL.ClientConVar[ "ropelength" ] = "64"
|
||||||
|
TOOL.ClientConVar[ "ropematerial" ] = "cable/rope"
|
||||||
|
TOOL.ClientConVar[ "r" ] = "255"
|
||||||
|
TOOL.ClientConVar[ "g" ] = "255"
|
||||||
|
TOOL.ClientConVar[ "b" ] = "255"
|
||||||
|
|
||||||
|
cleanup.Register( "wire_lamp" )
|
||||||
|
|
||||||
|
function TOOL:LeftClick( trace, attach )
|
||||||
|
|
||||||
|
if trace.Entity && trace.Entity:IsPlayer() then return false end
|
||||||
|
if (CLIENT) then return true end
|
||||||
|
if (attach == nil) then attach = true end
|
||||||
|
|
||||||
|
// If there's no physics object then we can't constraint it!
|
||||||
|
if ( SERVER && attach && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
|
||||||
|
|
||||||
|
local ply = self:GetOwner()
|
||||||
|
|
||||||
|
local pos, ang = trace.HitPos + trace.HitNormal * 10, trace.HitNormal:Angle() - Angle( 90, 0, 0 )
|
||||||
|
|
||||||
|
local r = math.Clamp( self:GetClientNumber( "r" ), 0, 255 )
|
||||||
|
local g = math.Clamp( self:GetClientNumber( "g" ), 0, 255 )
|
||||||
|
local b = math.Clamp( self:GetClientNumber( "b" ), 0, 255 )
|
||||||
|
|
||||||
|
if trace.Entity:IsValid() &&
|
||||||
|
trace.Entity:GetClass() == "gmod_wire_lamp" &&
|
||||||
|
trace.Entity:GetTable():GetPlayer() == ply
|
||||||
|
then
|
||||||
|
trace.Entity:GetTable():SetLightColor( r, g, b )
|
||||||
|
trace.Entity:GetTable().r = r
|
||||||
|
trace.Entity:GetTable().g = g
|
||||||
|
trace.Entity:GetTable().b = b
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if ( !self:GetSWEP():CheckLimit( "wire_lamps" ) ) then return false end
|
||||||
|
wire_lamp = MakeWireLamp( ply, pos, ang, r, g, b )
|
||||||
|
|
||||||
|
if (!attach) then
|
||||||
|
|
||||||
|
undo.Create("WireLamp")
|
||||||
|
undo.AddEntity( wire_lamp )
|
||||||
|
undo.SetPlayer( self:GetOwner() )
|
||||||
|
undo.Finish()
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local length = self:GetClientNumber( "ropelength" )
|
||||||
|
local material = self:GetClientInfo( "ropematerial" )
|
||||||
|
|
||||||
|
local LPos1 = Vector( 0, 0, 5 )
|
||||||
|
local LPos2 = trace.Entity:WorldToLocal( trace.HitPos )
|
||||||
|
|
||||||
|
if (trace.Entity:IsValid()) then
|
||||||
|
|
||||||
|
local phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
|
||||||
|
if (phys:IsValid()) then
|
||||||
|
LPos2 = phys:WorldToLocal( trace.HitPos )
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local constraint, rope = constraint.Rope( wire_lamp, trace.Entity,
|
||||||
|
0, trace.PhysicsBone,
|
||||||
|
LPos1, LPos2,
|
||||||
|
0, length,
|
||||||
|
0,
|
||||||
|
1.5,
|
||||||
|
material,
|
||||||
|
nil )
|
||||||
|
|
||||||
|
undo.Create("WireLamp")
|
||||||
|
undo.AddEntity( wire_lamp )
|
||||||
|
undo.AddEntity( rope )
|
||||||
|
undo.AddEntity( constraint )
|
||||||
|
undo.SetPlayer( ply )
|
||||||
|
undo.Finish()
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function TOOL:RightClick( trace )
|
||||||
|
|
||||||
|
return self:LeftClick( trace, false )
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function MakeWireLamp( pl, Pos, Ang, r, g, b, Vel, aVel, frozen )
|
||||||
|
|
||||||
|
if ( !pl:CheckLimit( "wire_lamps" ) ) then return false end
|
||||||
|
|
||||||
|
local wire_lamp = ents.Create( "gmod_wire_lamp" )
|
||||||
|
if (!wire_lamp:IsValid()) then return end
|
||||||
|
wire_lamp:SetPos( Pos )
|
||||||
|
wire_lamp:SetAngles( Ang )
|
||||||
|
wire_lamp:GetTable():SetLightColor( r, g, b )
|
||||||
|
wire_lamp:Spawn()
|
||||||
|
|
||||||
|
wire_lamp:Setup( r, g, b )
|
||||||
|
wire_lamp:GetTable():SetPlayer( pl )
|
||||||
|
|
||||||
|
|
||||||
|
if (wire_lamp:GetPhysicsObject():IsValid()) then
|
||||||
|
Phys = wire_lamp:GetPhysicsObject()
|
||||||
|
if Vel then Phys:SetVelocity(Vel) end
|
||||||
|
if Vel then Phys:AddAngleVelocity(aVel) end
|
||||||
|
Phys:EnableMotion(frozen != true)
|
||||||
|
end
|
||||||
|
|
||||||
|
pl:AddCount( "wire_lamps", wire_lamp )
|
||||||
|
pl:AddCleanup( "wire_lamp", wire_lamp )
|
||||||
|
|
||||||
|
return wire_lamp
|
||||||
|
end
|
||||||
|
|
||||||
|
duplicator.RegisterEntityClass( "gmod_wire_lamp", MakeWireLamp, "Pos", "Ang", "lightr", "lightg", "lightb", "Vel", "aVel", "frozen" )
|
||||||
|
|
||||||
|
function TOOL.BuildCPanel(panel)
|
||||||
|
panel:AddControl("Header", { Text = "#Tool_wire_lamp_name", Description = "#Tool_wire_lamp_desc" })
|
||||||
|
|
||||||
|
panel:AddControl("ComboBox", {
|
||||||
|
Label = "#Presets",
|
||||||
|
MenuButton = "1",
|
||||||
|
Folder = "wire_lamp",
|
||||||
|
|
||||||
|
Options = {
|
||||||
|
["#Default"] = {
|
||||||
|
wire_lamp_ropelength = "64",
|
||||||
|
wire_lamp_ropematerial = "cable/rope",
|
||||||
|
wire_lamp_r = "0",
|
||||||
|
wire_lamp_g = "0",
|
||||||
|
wire_lamp_b = "0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
CVars = {
|
||||||
|
[0] = "wire_lamp_ropelength",
|
||||||
|
[1] = "wire_lamp_ropematerial",
|
||||||
|
[2] = "wire_lamp_r",
|
||||||
|
[3] = "wire_lamp_g",
|
||||||
|
[4] = "wire_lamp_b",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
panel:AddControl("Slider", {
|
||||||
|
Label = "#WireLampTool_RopeLength",
|
||||||
|
Type = "Float",
|
||||||
|
Min = "4",
|
||||||
|
Max = "400",
|
||||||
|
Command = "wire_lamp_ropelength"
|
||||||
|
})
|
||||||
|
|
||||||
|
panel:AddControl("Color", {
|
||||||
|
Label = "#WireLampTool_Color",
|
||||||
|
Red = "wire_lamp_r",
|
||||||
|
Green = "wire_lamp_g",
|
||||||
|
Blue = "wire_lamp_b",
|
||||||
|
ShowAlpha = "0",
|
||||||
|
ShowHSV = "1",
|
||||||
|
ShowRGB = "1",
|
||||||
|
Multiplier = "255"
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
TOOL.ClientConVar[ "ropelength" ] = "64"
|
||||||
|
TOOL.ClientConVar[ "ropematerial" ] = "cable/rope"
|
||||||
|
TOOL.ClientConVar[ "r" ] = "255"
|
||||||
|
TOOL.ClientConVar[ "g" ] = "255"
|
||||||
|
TOOL.ClientConVar[ "b" ] = "255"
|
||||||
Reference in New Issue
Block a user