Initial commit

This commit is contained in:
2026-03-15 14:54:49 +03:00
commit 64f8029c06
4027 changed files with 254888 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
function EFFECT:Init( data )
local vOffset = data:GetOrigin()
local Color = data:GetStart()
sound.Play( "garrysmod/balloon_pop_cute.wav", vOffset, 90, math.random( 90, 120 ) )
local NumParticles = 32
local emitter = ParticleEmitter( vOffset, true )
for i = 0, NumParticles do
local Pos = Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), math.Rand( -1, 1 ) )
local particle = emitter:Add( "particles/balloon_bit", vOffset + Pos * 8 )
if ( particle ) then
particle:SetVelocity( Pos * 500 )
particle:SetLifeTime( 0 )
particle:SetDieTime( 10 )
particle:SetStartAlpha( 255 )
particle:SetEndAlpha( 255 )
local Size = math.Rand( 1, 3 )
particle:SetStartSize( Size )
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0, 360 ) )
particle:SetRollDelta( math.Rand( -2, 2 ) )
particle:SetAirResistance( 100 )
particle:SetGravity( Vector( 0, 0, -300 ) )
local RandDarkness = math.Rand( 0.8, 1.0 )
particle:SetColor( Color.r * RandDarkness, Color.g * RandDarkness, Color.b * RandDarkness )
particle:SetCollide( true )
particle:SetAngleVelocity( Angle( math.Rand( -160, 160 ), math.Rand( -160, 160 ), math.Rand( -160, 160 ) ) )
particle:SetBounce( 1 )
particle:SetLighting( true )
end
end
emitter:Finish()
end
function EFFECT:Think()
return false
end
function EFFECT:Render()
end

View File

@@ -0,0 +1,29 @@
function EFFECT:Init( data )
local vOffset = data:GetOrigin()
local ent = data:GetEntity()
local dlight = DynamicLight( ent:EntIndex() )
if ( dlight ) then
dlight.Pos = vOffset
dlight.r = 255
dlight.g = 255
dlight.b = 255
dlight.Brightness = 10
dlight.Size = 512
dlight.DieTime = CurTime() + 0.02
dlight.Decay = 512
end
end
function EFFECT:Think()
return false
end
function EFFECT:Render()
end

View File

@@ -0,0 +1,53 @@
function EFFECT:Init( data )
if ( GetConVarNumber( "gmod_drawtooleffects" ) == 0 ) then return end
local TargetEntity = data:GetEntity()
if ( !IsValid( TargetEntity ) ) then return end
local vOffset = TargetEntity:GetPos()
local Low, High = TargetEntity:WorldSpaceAABB()
local NumParticles = TargetEntity:BoundingRadius()
NumParticles = NumParticles * 4
NumParticles = math.Clamp( NumParticles, 32, 256 )
local emitter = ParticleEmitter( vOffset )
for i = 0, NumParticles do
local vPos = Vector( math.Rand( Low.x, High.x ), math.Rand( Low.y, High.y ), math.Rand( Low.z, High.z ) )
local particle = emitter:Add( "effects/spark", vPos )
if ( particle ) then
particle:SetVelocity( ( vPos - vOffset ) * 5 )
particle:SetLifeTime( 0 )
particle:SetDieTime( math.Rand( 0.5, 1.0 ) )
particle:SetStartAlpha( math.Rand( 200, 255 ) )
particle:SetEndAlpha( 0 )
particle:SetStartSize( 2 )
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0, 360 ) )
particle:SetRollDelta( 0 )
particle:SetAirResistance( 100 )
particle:SetGravity( Vector( 0, 0, -700 ) )
particle:SetCollide( true )
particle:SetBounce( 0.3 )
end
end
emitter:Finish()
end
function EFFECT:Think()
return false
end
function EFFECT:Render()
end

View File

@@ -0,0 +1,46 @@
function EFFECT:Init( data )
if ( GetConVarNumber( "gmod_drawtooleffects" ) == 0 ) then return end
local vOffset = data:GetOrigin()
local NumParticles = 16
local emitter = ParticleEmitter( vOffset )
for i = 0, NumParticles do
local particle = emitter:Add( "effects/spark", vOffset )
if ( particle ) then
particle:SetDieTime( 0.5 )
particle:SetStartAlpha( 255 )
particle:SetEndAlpha( 0 )
particle:SetStartSize( 1 )
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( 0, 360 ) )
particle:SetRollDelta( math.Rand( -200, 200 ) )
particle:SetAirResistance( 400 )
particle:SetVelocity( VectorRand() * 50 )
particle:SetGravity( Vector( 0, 0, 100 ) )
end
end
emitter:Finish()
end
function EFFECT:Think()
return false
end
function EFFECT:Render()
end

View File

@@ -0,0 +1,66 @@
EFFECT.Mat = Material( "effects/spark" )
function EFFECT:Init( data )
self.StartPos = data:GetStart()
self.EndPos = data:GetOrigin()
local ent = data:GetEntity()
local attid = data:GetAttachment()
if ( IsValid( ent ) && attid > 0 ) then
if ( ent.Owner == LocalPlayer() && LocalPlayer():GetViewModel() == LocalPlayer() ) then ent = ent.Owner:GetViewModel() end
local att = ent:GetAttachment( attid )
if ( att ) then
self.StartPos = att.Pos
end
end
self.Dir = self.EndPos - self.StartPos
self:SetRenderBoundsWS( self.StartPos, self.EndPos )
self.TracerTime = math.min( 1, self.StartPos:Distance( self.EndPos ) / 10000 )
self.Length = math.Rand( 0.1, 0.15 )
-- Die when it reaches its target
self.DieTime = CurTime() + self.TracerTime
end
function EFFECT:Think()
if ( CurTime() > self.DieTime ) then
-- Awesome End Sparks
local effectdata = EffectData()
effectdata:SetOrigin( self.EndPos + self.Dir:GetNormalized() * -2 )
effectdata:SetNormal( self.Dir:GetNormalized() * -3 )
effectdata:SetMagnitude( 1 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 6 )
util.Effect( "Sparks", effectdata )
return false
end
return true
end
function EFFECT:Render()
local fDelta = ( self.DieTime - CurTime() ) / self.TracerTime
fDelta = math.Clamp( fDelta, 0, 1 ) ^ 0.5
render.SetMaterial( self.Mat )
local sinWave = math.sin( fDelta * math.pi )
render.DrawBeam( self.EndPos - self.Dir * ( fDelta - sinWave * self.Length ),
self.EndPos - self.Dir * ( fDelta + sinWave * self.Length ),
2 + sinWave * 16, 1, 0, Color( 0, 255, 0, 255 ) )
end

View File

@@ -0,0 +1,31 @@
local effects_freeze = CreateClientConVar( "effects_freeze", "1", true, false, "Whether to display Physics Gun freeze effects?" )
function EFFECT:Init( data )
if ( effects_freeze:GetBool() == false ) then return end
self.Target = data:GetEntity()
self.StartTime = CurTime()
self.Length = 0.3
end
function EFFECT:Think()
if ( effects_freeze:GetBool() == false ) then return false end
return self.StartTime + self.Length > CurTime()
end
function EFFECT:Render()
if ( !IsValid( self.Target ) ) then return end
local delta = ( ( CurTime() - self.StartTime ) / self.Length ) ^ 0.5
local idelta = 1 - delta
local size = 1
halo.Add( { self.Target }, Color( 0, 255, 0, 255 * idelta ), size, size, 1, true, false )
end

View File

@@ -0,0 +1,31 @@
local effects_unfreeze = CreateClientConVar( "effects_unfreeze", "1", true, false, "Whether to display Physics Gun unfreeze effects?" )
function EFFECT:Init( data )
if ( effects_unfreeze:GetBool() == false ) then return end
self.Target = data:GetEntity()
self.StartTime = CurTime()
self.Length = 0.3
end
function EFFECT:Think()
if ( effects_unfreeze:GetBool() == false ) then return false end
return self.StartTime + self.Length > CurTime()
end
function EFFECT:Render()
if ( !IsValid( self.Target ) ) then return end
local delta = ( ( CurTime() - self.StartTime ) / self.Length ) ^ 0.5
local idelta = 1 - delta
local size = 1
halo.Add( { self.Target }, Color( 255, 0, 0, 255 * idelta ), size, size, 1, true, false )
end

View File

@@ -0,0 +1,139 @@
local cl_drawspawneffect = CreateConVar( "cl_drawspawneffect", "1", { FCVAR_ARCHIVE }, "Whether to draw the spawn effect when spawning objects." )
local matRefract = Material( "models/spawn_effect" )
function EFFECT:Init( data )
if ( !cl_drawspawneffect:GetBool() ) then return end
-- This is how long the spawn effect
-- takes from start to finish.
self.Time = 0.5
self.LifeTime = CurTime() + self.Time
local ent = data:GetEntity()
if ( !IsValid( ent ) ) then return end
if ( !ent:GetModel() ) then return end
self.ParentEntity = ent
self:SetModel( ent:GetModel() )
self:SetPos( ent:GetPos() )
self:SetAngles( ent:GetAngles() )
self:SetParent( ent )
self.OldRenderOverride = self.ParentEntity.RenderOverride
self.ParentEntity.SpawnEffect = self
self.ParentEntity.RenderOverride = self.RenderParent
end
function EFFECT:Think()
if ( !cl_drawspawneffect:GetBool() ) then return false end
if ( !IsValid( self.ParentEntity ) ) then return false end
local PPos = self.ParentEntity:GetPos()
self:SetPos( PPos + ( EyePos() - PPos ):GetNormal() )
if ( self.LifeTime > CurTime() ) then
return true
end
-- Remove the override only if our override was not overridden.
if ( self.ParentEntity.RenderOverride == self.RenderParent ) then
self.ParentEntity.RenderOverride = self.OldRenderOverride
end
self.ParentEntity.SpawnEffect = nil
return false
end
function EFFECT:Render()
end
function EFFECT:RenderOverlay( entity )
local Fraction = ( self.LifeTime - CurTime() ) / self.Time
local ColFrac = ( Fraction - 0.5 ) * 2
Fraction = math.Clamp( Fraction, 0, 1 )
ColFrac = math.Clamp( ColFrac, 0, 1 )
-- Change our model's alpha so the texture will fade out
--entity:SetColor( 255, 255, 255, 1 + 254 * (ColFrac) )
-- Place the camera a tiny bit closer to the entity.
-- It will draw a big bigger and we will skip any z buffer problems
local EyeNormal = entity:GetPos() - EyePos()
local Distance = EyeNormal:Length()
EyeNormal:Normalize()
local Pos = EyePos() + EyeNormal * Distance * 0.01
-- Start the new 3d camera position
local bClipping = self:StartClip( entity, 1.2 )
cam.Start3D( Pos, EyeAngles() )
-- If our card is DX8 or above draw the refraction effect
if ( render.GetDXLevel() >= 80 ) then
-- Update the refraction texture with whatever is drawn right now
render.UpdateRefractTexture()
matRefract:SetFloat( "$refractamount", Fraction * 0.1 )
-- Draw model with refraction texture
render.MaterialOverride( matRefract )
entity:DrawModel()
render.MaterialOverride()
end
-- Set the camera back to how it was
cam.End3D()
render.PopCustomClipPlane()
render.EnableClipping( bClipping )
end
function EFFECT:RenderParent()
if ( !IsValid( self ) ) then return end
if ( !IsValid( self.SpawnEffect ) ) then self.RenderOverride = nil return end
local bClipping = self.SpawnEffect:StartClip( self, 1 )
self:DrawModel()
render.PopCustomClipPlane()
render.EnableClipping( bClipping )
self.SpawnEffect:RenderOverlay( self )
end
function EFFECT:StartClip( model, spd )
local mn, mx = model:GetRenderBounds()
local Up = ( mx - mn ):GetNormal()
local Bottom = model:GetPos() + mn
local Top = model:GetPos() + mx
local Fraction = ( self.LifeTime - CurTime() ) / self.Time
Fraction = math.Clamp( Fraction / spd, 0, 1 )
local Lerped = LerpVector( Fraction, Bottom, Top )
local normal = Up
local distance = normal:Dot( Lerped )
local bEnabled = render.EnableClipping( true )
render.PushCustomClipPlane( normal, distance )
return bEnabled
end

View File

@@ -0,0 +1,55 @@
EFFECT.Mat = Material( "effects/select_dot" )
function EFFECT:Init( data )
local pos = data:GetOrigin()
local att = data:GetAttachment()
local ent = data:GetEntity()
local nrml = data:GetNormal()
self:SetRenderBounds( Vector( -8, -8, -8 ), Vector( 8, 8, 8 ) )
self:SetPos( pos )
-- This 0.01 is a hack.. to prevent the angle being weird and messing up when we change it back to a normal
self:SetAngles( nrml:Angle() + Angle( 0.01, 0.01, 0.01 ) )
if ( IsValid( ent ) ) then
self:SetParentPhysNum( att )
self:SetParent( ent )
end
self.Size = 4
self.Alpha = 255
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( nrml )
effectdata:SetEntity( ent )
effectdata:SetAttachment( att )
for i = 0, 5 do
util.Effect( "selection_ring", effectdata )
end
end
function EFFECT:Think()
self.Alpha = self.Alpha - 255 * FrameTime()
if ( self.Alpha < 0 ) then return false end
return true
end
function EFFECT:Render()
if ( self.Alpha < 1 ) then return end
render.SetMaterial( self.Mat )
render.DrawQuadEasy( self:GetPos(), self:GetAngles():Forward(), self.Size, self.Size, Color( 255, 255, 255, self.Alpha ) )
end

View File

@@ -0,0 +1,51 @@
EFFECT.Mat = Material( "effects/select_ring" )
function EFFECT:Init( data )
local size = 8
self:SetCollisionBounds( Vector( -size, -size, -size ), Vector( size, size, size ) )
local Pos = data:GetOrigin() + data:GetNormal() * 2
self:SetPos( Pos )
-- This 0.01 is a hack.. to prevent the angle being weird and messing up when we change it back to a normal
self:SetAngles( data:GetNormal():Angle() + Angle( 0.01, 0.01, 0.01 ) )
self:SetParentPhysNum( data:GetAttachment() )
if ( IsValid( data:GetEntity() ) ) then
self:SetParent( data:GetEntity() )
end
self.Pos = data:GetOrigin()
self.Normal = data:GetNormal()
self.Speed = math.Rand( 0.5, 1.5 )
self.Size = 4
self.Alpha = 255
self.Life = 0.5
end
function EFFECT:Think()
self.Alpha = self.Alpha - FrameTime() * 255 * 5 * self.Speed
self.Size = self.Size + FrameTime() * 256 * self.Speed
if ( self.Alpha < 0 ) then return false end
return true
end
function EFFECT:Render()
if ( self.Alpha < 1 ) then return end
render.SetMaterial( self.Mat )
render.DrawQuadEasy( self:GetPos(), self:GetAngles():Forward(), self.Size, self.Size, Color( math.Rand( 10, 150 ), math.Rand( 170, 220 ), math.Rand( 240, 255 ), self.Alpha ) )
end

View File

@@ -0,0 +1,57 @@
EFFECT.Mat = Material( "effects/wheel_ring" )
function EFFECT:Init( data )
self.Wheel = data:GetEntity()
if ( !IsValid( self.Wheel ) ) then return end
self.Axis = data:GetOrigin() / 100 -- see gmod_wheel.lua
self.Direction = data:GetScale()
-- This 0.01 is a hack.. to prevent the angle being weird and messing up when we change it back to a normal
-- Removed, we are never even setting the normal on effect data
--self:SetAngles( data:GetNormal():Angle() + Angle( 0.01, 0.01, 0.01 ) )
self.Alpha = 1
self.Size = self.Wheel:BoundingRadius() + 8
self:SetPos( self.Wheel:LocalToWorld( self.Axis ) )
self:SetParent( self.Wheel )
local size = 64
self:SetCollisionBounds( Vector( -size, -size, -size ), Vector( size, size, size ) )
end
function EFFECT:Think()
if ( !IsValid( self.Wheel ) ) then return false end
local speed = FrameTime()
self.Alpha = self.Alpha - speed * 0.8
self.Size = self.Size + speed * 5
if ( self.Alpha < 0 ) then return false end
return true
end
function EFFECT:Render()
if ( !IsValid( self.Wheel ) ) then return end
if ( self.Alpha < 0 ) then return end
render.SetMaterial( self.Mat )
local offset = self.Wheel:LocalToWorld( self.Axis ) - self.Wheel:GetPos()
render.DrawQuadEasy( self.Wheel:GetPos() + offset,
offset:GetNormalized() * self.Direction,
self.Size, self.Size,
Color( 255, 255, 255, ( self.Alpha ^ 1.1 ) * 255 ),
self.Alpha * 200 )
end

View File

@@ -0,0 +1,53 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_anim" )
ENT.Spawnable = false
ENT.AdminOnly = false
ENT.Editable = true
function ENT:Initialize()
if ( CLIENT ) then return end
self:SetModel( "models/maxofs2d/cube_tool.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetUseType( ONOFF_USE )
end
function ENT:SpawnFunction( ply, tr, ClassName )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 10
local SpawnAng = ply:EyeAngles()
SpawnAng.p = 0
SpawnAng.y = SpawnAng.y + 180
-- Make sure the spawn position is not out of bounds
local oobTr = util.TraceLine( {
start = tr.HitPos,
endpos = SpawnPos,
mask = MASK_SOLID_BRUSHONLY
} )
if ( oobTr.Hit ) then
SpawnPos = oobTr.HitPos + oobTr.HitNormal * ( tr.HitPos:Distance( oobTr.HitPos ) / 2 )
end
local ent = ents.Create( ClassName )
ent:SetPos( SpawnPos )
ent:SetAngles( SpawnAng )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:EnableForwardArrow()
self:SetBodygroup( 1, 1 )
end

View File

@@ -0,0 +1,145 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_anim" )
ENT.Spawnable = false
if ( CLIENT ) then
ENT.MaxWorldTipDistance = 256
function ENT:BeingLookedAtByLocalPlayer()
local ply = LocalPlayer()
if ( !IsValid( ply ) ) then return false end
local view = ply:GetViewEntity()
local dist = self.MaxWorldTipDistance
dist = dist * dist
-- If we're spectating a player, perform an eye trace
if ( view:IsPlayer() ) then
return view:EyePos():DistToSqr( self:GetPos() ) <= dist && view:GetEyeTrace().Entity == self
end
-- If we're not spectating a player, perform a manual trace from the entity's position
local pos = view:GetPos()
if ( pos:DistToSqr( self:GetPos() ) <= dist ) then
return util.TraceLine( {
start = pos,
endpos = pos + ( view:GetAngles():Forward() * dist ),
filter = view
} ).Entity == self
end
return false
end
function ENT:Think()
local text = self:GetOverlayText()
if ( text != "" && self:BeingLookedAtByLocalPlayer() && !self:GetNoDraw() ) then
AddWorldTip( self:EntIndex(), text, 0.5, self:GetPos(), self )
halo.Add( { self }, color_white, 1, 1, 1, true, true )
end
end
end
function ENT:SetOverlayText( text )
self:SetNWString( "GModOverlayText", text )
end
function ENT:GetOverlayText()
local txt = self:GetNWString( "GModOverlayText" )
if ( txt == "" ) then
return ""
end
if ( game.SinglePlayer() ) then
return txt
end
local PlayerName = self:GetPlayerName()
if ( !PlayerName or PlayerName == "" ) then
return txt
end
return txt .. "\n(" .. PlayerName .. ")"
end
function ENT:SetPlayer( ply )
self.Founder = ply
self:SetCreator( ply )
if ( IsValid( ply ) ) then
self:SetNWString( "FounderName", ply:Nick() )
self.FounderSID = ply:SteamID64()
self.FounderIndex = ply:UniqueID()
else
self:SetNWString( "FounderName", "" )
self.FounderSID = nil
self.FounderIndex = nil
end
end
function ENT:GetPlayer()
if ( self.Founder == nil ) then
-- SetPlayer has not been called
return NULL
elseif ( IsValid( self.Founder ) ) then
-- Normal operations
return self.Founder
end
-- See if the player has left the server then rejoined
local ply = player.GetBySteamID64( self.FounderSID )
if ( !IsValid( ply ) ) then
-- Oh well
return NULL
end
-- Save us the check next time
self:SetPlayer( ply )
return ply
end
function ENT:GetPlayerIndex()
return self.FounderIndex or 0
end
function ENT:GetPlayerSteamID()
return self.FounderSID or ""
end
function ENT:GetPlayerName()
local ply = self:GetPlayer()
if ( IsValid( ply ) ) then
return ply:Nick()
end
return self:GetNWString( "FounderName", "" )
end

View File

@@ -0,0 +1,102 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_edit" )
ENT.Spawnable = true
ENT.AdminOnly = true
ENT.PrintName = "#edit_fog"
ENT.Category = "#spawnmenu.category.editors"
ENT.Information = "Right click on this entity via the context menu (hold C by default) and select 'Edit Properties' to edit the fog."
function ENT:Initialize()
BaseClass.Initialize( self )
self:SetMaterial( "gmod/edit_fog" )
if ( CLIENT ) then
hook.Add( "SetupWorldFog", self, self.SetupWorldFog )
hook.Add( "SetupSkyboxFog", self, self.SetupSkyFog )
end
end
function ENT:SetupWorldFog()
render.FogMode( MATERIAL_FOG_LINEAR )
render.FogStart( self:GetFogStart() )
render.FogEnd( self:GetFogEnd() )
render.FogMaxDensity( self:GetDensity() )
local col = self:GetFogColor()
render.FogColor( col.x * 255, col.y * 255, col.z * 255 )
return true
end
function ENT:SetupSkyFog( skyboxscale )
render.FogMode( MATERIAL_FOG_LINEAR )
render.FogStart( self:GetFogStart() * skyboxscale )
render.FogEnd( self:GetFogEnd() * skyboxscale )
render.FogMaxDensity( self:GetDensity() )
local col = self:GetFogColor()
render.FogColor( col.x * 255, col.y * 255, col.z * 255 )
return true
end
function ENT:SetupDataTables()
self:NetworkVar( "Float", 0, "FogStart", { KeyName = "fogstart", Edit = { type = "Float", min = 0, max = 1000000, order = 1 } } )
self:NetworkVar( "Float", 1, "FogEnd", { KeyName = "fogend", Edit = { type = "Float", min = 0, max = 1000000, order = 2 } } )
self:NetworkVar( "Float", 2, "Density", { KeyName = "density", Edit = { type = "Float", min = 0, max = 1, order = 3 } } )
self:NetworkVar( "Vector", 0, "FogColor", { KeyName = "fogcolor", Edit = { type = "VectorColor", order = 3 } } )
--
-- TODO: Should skybox fog be edited seperately?
--
if ( SERVER ) then
-- defaults
self:SetFogStart( 0.0 )
self:SetFogEnd( 10000 )
self:SetDensity( 0.9 )
self:SetFogColor( Vector( 0.6, 0.7, 0.8 ) )
end
end
--
-- This edits something global - so always network - even when not in PVS
--
function ENT:UpdateTransmitState()
return TRANSMIT_ALWAYS
end
-- Player just spawned this entity from the spawnmenu - not from a duplication.
-- Copy over the settings of the map
hook.Add( "PlayerSpawnedSENT", "CopyOverEditFogSettings", function( ply, ent )
if ( ent:GetClass() != "edit_fog" ) then return end
local fogCntrl = ents.FindByClass( "env_fog_controller" )[ 1 ];
if ( !IsValid( fogCntrl ) ) then return end
ent:SetFogStart( fogCntrl:GetInternalVariable( "fogstart" ) )
ent:SetFogEnd( fogCntrl:GetInternalVariable( "fogend" ) )
ent:SetDensity( fogCntrl:GetInternalVariable( "fogmaxdensity" ) )
ent:SetFogColor( Vector( fogCntrl:GetInternalVariable( "fogcolor" ) ) / 255 )
end )

View File

@@ -0,0 +1,107 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_edit" )
ENT.Spawnable = true
ENT.AdminOnly = true
ENT.PrintName = "#edit_sky"
ENT.Category = "#spawnmenu.category.editors"
ENT.Information = "Right click on this entity via the context menu (hold C by default) and select 'Edit Properties' to edit the sky."
function ENT:Initialize()
BaseClass.Initialize( self )
self:SetMaterial( "gmod/edit_sky" )
--
-- Over-ride the sky controller with this.
--
if ( CLIENT ) then
g_SkyPaint = self
end
end
function ENT:Think()
--
-- Find an env_sun - if we don't already have one.
--
if ( SERVER and self.EnvSun == nil ) then
-- so this closure only gets called once - even if it fails
self.EnvSun = false
local list = ents.FindByClass( "env_sun" )
if ( #list > 0 ) then
self.EnvSun = list[ 1 ]
end
end
--
-- If we have a sun - force our sun normal to its value
--
if ( SERVER and IsValid( self.EnvSun ) ) then
local vec = self.EnvSun:GetInternalVariable( "m_vDirection" )
if ( isvector( vec ) ) then
self:SetSunNormal( vec )
end
end
end
--
-- This needs to be a 1:1 copy of env_skypaint
--
function ENT:SetupDataTables()
local SetupDataTables = scripted_ents.GetMember( "env_skypaint", "SetupDataTables" )
SetupDataTables( self )
end
--
-- This edits something global - so always network - even when not in PVS
--
function ENT:UpdateTransmitState()
return TRANSMIT_ALWAYS
end
-- Player just spawned this entity from the spawnmenu - not from a duplication.
-- Copy over the settings of the maps' skypaint
hook.Add( "PlayerSpawnedSENT", "CopyOverEditSkySettings", function( ply, ent )
if ( ent:GetClass() != "edit_sky" ) then return end
local skyPaint = ents.FindByClass( "env_skypaint" )[ 1 ];
if ( !IsValid( skyPaint ) ) then return end
ent:SetTopColor( skyPaint:GetTopColor() )
ent:SetBottomColor( skyPaint:GetBottomColor() )
ent:SetFadeBias( skyPaint:GetFadeBias() )
ent:SetHDRScale( skyPaint:GetHDRScale() )
ent:SetStarLayers( skyPaint:GetStarLayers() )
ent:SetDrawStars( skyPaint:GetDrawStars() )
ent:SetStarTexture( skyPaint:GetStarTexture() )
ent:SetStarSpeed( skyPaint:GetStarSpeed() )
ent:SetStarFade( skyPaint:GetStarFade() )
ent:SetStarScale( skyPaint:GetStarScale() )
ent:SetDuskIntensity( skyPaint:GetDuskIntensity() )
ent:SetDuskScale( skyPaint:GetDuskScale() )
ent:SetDuskColor( skyPaint:GetDuskColor() )
ent:SetSunSize( skyPaint:GetSunSize() )
ent:SetSunColor( skyPaint:GetSunColor() )
end )

View File

@@ -0,0 +1,125 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_edit" )
ENT.Spawnable = true
ENT.AdminOnly = true
ENT.PrintName = "#edit_sun"
ENT.Category = "#spawnmenu.category.editors"
ENT.Information = "Right click on this entity via the context menu (hold C by default) and select 'Edit Properties' to edit the sun. Rotate the entity to move the sun."
function ENT:Initialize()
BaseClass.Initialize( self )
self:EnableForwardArrow()
self:SetMaterial( "gmod/edit_sun" )
if ( SERVER ) then
--
-- Notify us when the entity angle changes, so we can update the sun entity
--
self:AddCallback( "OnAngleChange", self.OnAngleChange )
--
-- Find an env_sun entity
--
local list = ents.FindByClass( "env_sun" )
if ( #list > 0 ) then
self.EnvSun = list[ 1 ]
end
end
end
function ENT:SetupDataTables()
self:NetworkVar( "Float", 0, "SunSize", { KeyName = "sunsize", Edit = { type = "Float", min = 0, max = 100, order = 1 } } )
self:NetworkVar( "Float", 1, "OverlaySize", { KeyName = "overlaysize", Edit = { type = "Float", min = 0, max = 200, order = 2 } } )
self:NetworkVar( "Vector", 0, "SunColor", { KeyName = "suncolor", Edit = { type = "VectorColor", order = 3 } } )
self:NetworkVar( "Vector", 1, "OverlayColor", { KeyName = "overlaycolor", Edit = { type = "VectorColor", order = 4 } } )
if ( SERVER ) then
-- defaults
self:SetSunSize( 20 )
self:SetOverlaySize( 20 )
self:SetOverlayColor( Vector( 1, 1, 1 ) )
self:SetSunColor( Vector( 1, 1, 1 ) )
-- call this function when something changes these variables
self:NetworkVarNotify( "SunSize", self.OnVariableChanged )
self:NetworkVarNotify( "OverlaySize", self.OnVariableChanged )
self:NetworkVarNotify( "SunColor", self.OnVariableChanged )
self:NetworkVarNotify( "OverlayColor", self.OnVariableChanged )
end
end
--
-- Callback - serverside - added in :Initialize
--
function ENT:OnAngleChange( newang )
if ( IsValid( self.EnvSun ) ) then
self.EnvSun:SetKeyValue( "sun_dir", tostring( newang:Forward() ) )
end
end
--
-- Force update everything after being pasted in
--
function ENT:PostEntityPaste( ply, ent )
self:OnAngleChange( ent:GetAngles() )
self:OnVariableChanged()
end
--
-- Update all the variables on the sun, from our variables in this entity
--
function ENT:OnVariableChanged()
if ( !IsValid( self.EnvSun ) ) then return end
self.EnvSun:SetKeyValue( "size", self:GetSunSize() )
self.EnvSun:SetKeyValue( "overlaysize", self:GetOverlaySize() )
local overlay = self:GetOverlayColor()
self.EnvSun:SetKeyValue( "overlaycolor", Format( "%i %i %i", overlay.x * 255, overlay.y * 255, overlay.z * 255 ) )
local sun = self:GetSunColor()
self.EnvSun:SetKeyValue( "suncolor", Format( "%i %i %i", sun.x * 255, sun.y * 255, sun.z * 255 ) )
end
--
-- This edits something global - so always network - even when not in PVS
--
function ENT:UpdateTransmitState()
return TRANSMIT_ALWAYS
end
-- Player just spawned this entity from the spawnmenu - not from a duplication.
-- Copy over the settings of the map
hook.Add( "PlayerSpawnedSENT", "CopyOverEditSunSettings", function( ply, ent )
if ( ent:GetClass() != "edit_sun" ) then return end
local envSun = ents.FindByClass( "env_sun" )[ 1 ];
if ( !IsValid( envSun ) ) then return end
ent:SetSunSize( envSun:GetInternalVariable( "size" ) )
ent:SetOverlaySize( envSun:GetInternalVariable( "overlaysize" ) )
ent:SetOverlayColor( Vector( envSun:GetInternalVariable( "overlaycolor" ) ) / 255 )
ent:SetSunColor( Vector( envSun:GetInternalVariable( "rendercolor" ) ) / 255 )
end )

View File

@@ -0,0 +1,26 @@
AddCSLuaFile()
ENT.Type = "anim"
ENT.PrintName = "World Anchor"
if ( CLIENT ) then return end
function ENT:Initialize()
self:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetNotSolid( true )
self:SetNoDraw( true )
self:DrawShadow( false )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:EnableMotion( false )
phys:EnableCollisions( false )
end
self:SetUnFreezable( true )
end

View File

@@ -0,0 +1,88 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Balloon"
ENT.Editable = true
function ENT:SetupDataTables()
self:NetworkVar( "Float", 0, "Force", { KeyName = "force", Edit = { type = "Float", order = 1, min = -2000, max = 2000, title = "#tool.balloon.force" } } )
if ( SERVER ) then
self:NetworkVarNotify( "Force", function() self:PhysWake() end )
end
end
function ENT:Initialize()
if ( CLIENT ) then return end
self:PhysicsInit( SOLID_VPHYSICS )
self:SetRenderMode( RENDERMODE_TRANSCOLOR )
-- Set up our physics object here
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:SetMass( 100 )
phys:Wake()
phys:EnableGravity( false )
end
self:SetForce( 1 )
self:StartMotionController()
end
function ENT:GetOverlayText()
local txt = language.GetPhrase( "tool.balloon.force" ) .. " " .. math.floor( self:GetForce() )
if ( txt == "" ) then return "" end
if ( game.SinglePlayer() ) then return txt end
return txt .. "\n(" .. self:GetPlayerName() .. ")"
end
function ENT:OnTakeDamage( dmginfo )
if ( self.Indestructible ) then return end
local c = self:GetColor()
local effectdata = EffectData()
effectdata:SetOrigin( self:GetPos() )
effectdata:SetStart( Vector( c.r, c.g, c.b ) )
util.Effect( "balloon_pop", effectdata )
if ( self.Explosive ) then
local ed_expl = EffectData()
ed_expl:SetOrigin( self:GetPos() )
ed_expl:SetScale( 1 )
ed_expl:SetMagnitude( 25 )
util.Effect( "Explosion", ed_expl, true, true )
end
local attacker = dmginfo:GetAttacker()
if ( IsValid( attacker ) && attacker:IsPlayer() ) then
attacker:SendLua( "achievements.BalloonPopped()" )
end
self:Remove()
end
function ENT:PhysicsSimulate( phys, deltatime )
local force = math.Clamp( self:GetForce(), -1E34, 1E34 ) * 5000
local vLinear = Vector( 0, 0, force ) * deltatime
local vAngular = vector_origin
return vAngular, vLinear, SIM_GLOBAL_FORCE
end

View File

@@ -0,0 +1,154 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Button"
ENT.Editable = true
function ENT:SetupDataTables()
self:NetworkVar( "Int", 0, "Key" )
self:NetworkVar( "Bool", 0, "On" )
self:NetworkVar( "Bool", 1, "IsToggle", { KeyName = "tg", Edit = { type = "Boolean", order = 1, title = "#tool.button.toggle" } } )
self:NetworkVar( "String", 0, "Label", { KeyName = "lbl", Edit = { type = "Generic", order = 2, title = "#tool.button.text" } } )
if ( SERVER ) then
self:SetOn( false )
self:SetIsToggle( false )
end
end
function ENT:Initialize()
if ( SERVER ) then
self:PhysicsInit( SOLID_VPHYSICS )
self:SetUseType( ONOFF_USE )
else
self.PosePosition = 0
end
end
function ENT:GetOverlayText()
local text = self:GetLabel()
text = string.gsub( text, "\\", "" )
text = string.sub( text, 0, 20 )
if ( text == "" ) then return "" end
local txt = "\"" .. text .. "\""
if ( txt == "" ) then return "" end
if ( game.SinglePlayer() ) then return txt end
return txt .. "\n(" .. self:GetPlayerName() .. ")"
end
function ENT:Use( activator, caller, type, value )
if ( !activator:IsPlayer() ) then return end -- Who the frig is pressing this shit!?
if ( self:GetIsToggle() ) then
if ( type == USE_ON ) then
self:Toggle( !self:GetOn(), activator )
end
return
end
if ( IsValid( self.LastUser ) ) then return end -- Someone is already using this button
--
-- Switch off
--
if ( self:GetOn() ) then
self:Toggle( false, activator )
return
end
--
-- Switch on
--
self:Toggle( true, activator )
self:NextThink( CurTime() )
self.LastUser = activator
end
function ENT:Think()
-- Add a world tip if the player is looking at it
self.BaseClass.Think( self )
-- Update the animation
if ( CLIENT ) then
self:UpdateLever()
end
--
-- If the player looks away while holding down use it will stay on
-- Lets fix that..
--
if ( SERVER && self:GetOn() && !self:GetIsToggle() ) then
if ( !IsValid( self.LastUser ) || !self.LastUser:KeyDown( IN_USE ) ) then
self:Toggle( false, self.LastUser )
self.LastUser = nil
end
self:NextThink( CurTime() )
end
end
--
-- Makes the button trigger the keys
--
function ENT:Toggle( bEnable, ply )
-- If a button has a valid player on it, use that, if not, use activator
local targetPly = self:GetPlayer()
if ( !IsValid( targetPly ) ) then targetPly = ply end
if ( bEnable ) then
numpad.Activate( targetPly, self:GetKey(), true )
self:SetOn( true )
else
numpad.Deactivate( targetPly, self:GetKey(), true )
self:SetOn( false )
end
end
--
-- Update the lever animation
--
function ENT:UpdateLever()
local TargetPos = 0.0
if ( self:GetOn() ) then TargetPos = 1.0 end
self.PosePosition = math.Approach( self.PosePosition, TargetPos, FrameTime() * 5.0 )
self:SetPoseParameter( "switch", self.PosePosition )
self:InvalidateBoneCache()
end

View File

@@ -0,0 +1,227 @@
AddCSLuaFile()
if ( CLIENT ) then
CreateConVar( "cl_drawcameras", "1", 0, "Should Sandbox cameras be visible?" )
end
ENT.Type = "anim"
ENT.PrintName = "Camera"
local CAMERA_MODEL = Model( "models/dav0r/camera.mdl" )
function ENT:SetupDataTables()
self:NetworkVar( "Int", 0, "Key" )
self:NetworkVar( "Bool", 0, "On" )
self:NetworkVar( "Vector", 0, "vecTrack" )
self:NetworkVar( "Entity", 0, "entTrack" )
self:NetworkVar( "Entity", 1, "Player" )
end
-- Custom drive mode
function ENT:GetEntityDriveMode()
return "drive_noclip"
end
function ENT:Initialize()
if ( SERVER ) then
self:SetModel( CAMERA_MODEL )
self:PhysicsInit( SOLID_VPHYSICS )
self:DrawShadow( false )
-- Don't collide with the player
self:SetCollisionGroup( COLLISION_GROUP_WEAPON )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Sleep() end
end
end
function ENT:SetTracking( Ent, LPos )
if ( IsValid( Ent ) ) then
self:SetMoveType( MOVETYPE_NONE )
self:SetSolid( SOLID_BBOX )
else
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
end
self:NextThink( CurTime() )
self:SetvecTrack( LPos )
self:SetentTrack( Ent )
end
function ENT:SetLocked( locked )
if ( locked == 1 ) then
self.PhysgunDisabled = true
self:SetMoveType( MOVETYPE_NONE )
self:SetSolid( SOLID_BBOX )
self:SetCollisionGroup( COLLISION_GROUP_WORLD )
else
self.PhysgunDisabled = false
end
self.locked = locked
end
function ENT:OnTakeDamage( dmginfo )
if ( self.locked ) then return end
self:TakePhysicsDamage( dmginfo )
end
function ENT:OnRemove()
if ( IsValid( self.UsingPlayer ) ) then
self.UsingPlayer:SetViewEntity( self.UsingPlayer )
end
end
if ( SERVER ) then
function ENT:ApplyKeybinds( ply )
if ( self.toggle == 1 ) then
numpad.OnDown( ply, self:GetKey(), "Camera_Toggle", self )
else
numpad.OnDown( ply, self:GetKey(), "Camera_On", self )
numpad.OnUp( ply, self:GetKey(), "Camera_Off", self )
end
end
function ENT:OnRestore()
-- HACK: Restore keybinds on level transitions, which can only happen in single player
self:ApplyKeybinds( nil )
end
numpad.Register( "Camera_On", function( ply, ent )
if ( !IsValid( ent ) ) then return false end
if ( !IsValid( ply ) ) then return false end
ply:SetViewEntity( ent )
ply.UsingCamera = ent
ent.UsingPlayer = ply
end )
numpad.Register( "Camera_Toggle", function( ply, ent, idx, buttoned )
-- The camera was deleted or something - return false to remove this entry
if ( !IsValid( ent ) ) then return false end
if ( !IsValid( ply ) ) then return false end
-- Something else changed players view entity
if ( ply.UsingCamera and ply.UsingCamera == ent and ply:GetViewEntity() != ent ) then
ply.UsingCamera = nil
ent.UsingPlayer = nil
end
if ( ply.UsingCamera and ply.UsingCamera == ent ) then
ply:SetViewEntity( ply )
ply.UsingCamera = nil
ent.UsingPlayer = nil
else
ply:SetViewEntity( ent )
ply.UsingCamera = ent
ent.UsingPlayer = ply
end
end )
numpad.Register( "Camera_Off", function( ply, ent )
if ( !IsValid( ent ) ) then return false end
if ( !IsValid( ply ) ) then return false end
if ( ply.UsingCamera and ply.UsingCamera == ent ) then
ply:SetViewEntity( ply )
ply.UsingCamera = nil
ent.UsingPlayer = nil
end
end )
end
function ENT:Think()
if ( CLIENT ) then
self:TrackEntity( self:GetentTrack(), self:GetvecTrack() )
end
end
function ENT:TrackEntity( ent, lpos )
if ( !IsValid( ent ) ) then return end
local WPos = ent:LocalToWorld( lpos )
if ( ent:IsPlayer() ) then
WPos = WPos + ent:GetViewOffset() * 0.85
end
local ang = WPos - self:GetPos()
self:SetAngles( ang:Angle() )
end
function ENT:CanTool( ply, trace, mode, tool, click )
if ( self:GetMoveType() == MOVETYPE_NONE ) then return false end
return true
end
function ENT:Draw( flags )
if ( GetConVarNumber( "cl_drawcameras" ) == 0 ) then return end
-- Don't draw the camera if we're taking pics
local wep = LocalPlayer():GetActiveWeapon()
if ( IsValid( wep ) and wep:GetClass() == "gmod_camera" ) then
return
end
self:DrawModel( flags )
end

View File

@@ -0,0 +1,80 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Dynamite"
ENT.Editable = true
function ENT:SetupDataTables()
self:NetworkVar( "Bool", 0, "ShouldRemove", { KeyName = "sr", Edit = { type = "Boolean", order = 1, title = "#tool.dynamite.remove" } } )
self:NetworkVar( "Float", 0, "Damage", { KeyName = "force", Edit = { type = "Float", order = 2, min = 0, max = 500, title = "#tool.dynamite.damage" } } )
self:NetworkVar( "Float", 1, "Delay", { KeyName = "delay", Edit = { type = "Float", order = 3, min = 0, max = 10, title = "#tool.dynamite.delay" } } )
end
function ENT:Initialize()
if ( SERVER ) then
self:PhysicsInit( SOLID_VPHYSICS )
end
end
function ENT:Setup( damage )
self:SetDamage( damage )
end
function ENT:GetOverlayText()
local txt = string.format( "%s %g\n%s %g",
language.GetPhrase( "#tool.dynamite.damage" ), math.Clamp( self:GetDamage(), 0, 1500 ),
language.GetPhrase( "#tool.dynamite.delay" ), self:GetDelay() )
if ( game.SinglePlayer() ) then return txt end
return txt .. "\n(" .. self:GetPlayerName() .. ")"
end
function ENT:OnTakeDamage( dmginfo )
if ( dmginfo:GetInflictor():GetClass() == "gmod_dynamite" ) then return end
self:TakePhysicsDamage( dmginfo )
end
--
-- Blow that mother fucker up, BAATCHH
--
function ENT:Explode( delay, ply )
if ( !IsValid( self ) ) then return end
if ( !IsValid( ply ) ) then ply = self end
local _delay = delay or self:GetDelay()
if ( _delay == 0 ) then
local radius = 300
util.BlastDamage( self, ply, self:GetPos(), radius, math.Clamp( self:GetDamage(), 0, 1500 ) )
local effectdata = EffectData()
effectdata:SetOrigin( self:GetPos() )
util.Effect( "Explosion", effectdata, true, true )
if ( self:GetShouldRemove() ) then self:Remove() return end
if ( self:GetMaxHealth() > 0 && self:Health() <= 0 ) then self:SetHealth( self:GetMaxHealth() ) end
else
timer.Simple( _delay, function() if ( !IsValid( self ) ) then return end self:Explode( 0, ply ) end )
end
end

View File

@@ -0,0 +1,401 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Emitter"
ENT.Editable = true
function ENT:SetupDataTables()
self:NetworkVar( "Bool", 1, "On", { KeyName = "on", Edit = { type = "Boolean", order = 1, title = "#entedit.enabled" } } )
self:NetworkVar( "Bool", 0, "Toggle", { KeyName = "tg", Edit = { type = "Boolean", order = 1, title = "#tool.emitter.toggle" } } )
self:NetworkVar( "Float", 0, "Delay", { KeyName = "dl", Edit = { type = "Float", order = 1, min = 0.01, max = 2, title = "#tool.emitter.delay" } } )
self:NetworkVar( "Float", 1, "Scale", { KeyName = "sc", Edit = { type = "Float", order = 1, min = 0, max = 6, title = "#tool.emitter.scale" } } )
self:NetworkVar( "String", 0, "Effect" )
end
function ENT:Initialize()
if ( SERVER ) then
self:SetModel( "models/props_lab/tpplug.mdl" ) -- TODO: Find something better than this
self:PhysicsInit( SOLID_VPHYSICS )
self:DrawShadow( false )
self:SetCollisionGroup( COLLISION_GROUP_WEAPON )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() end
end
end
function ENT:Draw( flags )
-- Don't draw if the player is holding Camera SWEP in their hands
local ply = LocalPlayer()
local wep = ply:GetActiveWeapon()
if ( IsValid( wep ) ) then
local weapon_name = wep:GetClass()
if ( weapon_name == "gmod_camera" ) then return end
end
BaseClass.Draw( self, flags )
end
function ENT:Think()
if ( SERVER ) then return end
BaseClass.Think( self )
if ( !self:GetOn() ) then return end
self.Delay = self.Delay or 0
if ( self.Delay > CurTime() ) then return end
self.Delay = CurTime() + self:GetDelay()
--
-- Find our effect table
--
local EffectTable = list.GetEntry( "EffectType", self:GetEffect() )
if ( !EffectTable ) then return end
local Angle = self:GetAngles()
EffectTable.func( self, self:GetPos() + Angle:Forward() * 12, Angle, self:GetScale() )
end
--[[---------------------------------------------------------
Overridden because I want to show the name of the player that spawned it..
-----------------------------------------------------------]]
function ENT:GetOverlayText()
return self:GetPlayerName()
end
if ( SERVER ) then
numpad.Register( "Emitter_On", function( ply, ent )
if ( !IsValid( ent ) ) then return end
if ( ent:GetToggle() ) then
ent:SetOn( !ent:GetOn() )
return end
ent:SetOn( true )
end )
numpad.Register( "Emitter_Off", function( ply, ent )
if ( !IsValid( ent ) ) then return end
if ( ent:GetToggle() ) then return end
ent:SetOn( false )
end )
end
game.AddParticles( "particles/gmod_effects.pcf" )
PrecacheParticleSystem( "generic_smoke" )
list.Set( "EffectType", "smoke", {
print = "#effecttype.smoke",
material = "gui/effects/smoke.png",
func = function( ent, pos, angle, scale )
ParticleEffect( "generic_smoke", pos, angle, ent )
end
} )
list.Set( "EffectType", "sparks", {
print = "#effecttype.sparks",
material = "gui/effects/sparks.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( angle:Forward() * scale )
effectdata:SetMagnitude( scale / 2 )
effectdata:SetRadius( 8 - scale )
util.Effect( "Sparks", effectdata, true, true )
end
} )
list.Set( "EffectType", "stunstickimpact", {
print = "#effecttype.stunstick",
material = "gui/effects/stunstickimpact.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( angle:Forward() )
util.Effect( "stunstickimpact", effectdata, true, true )
end
} )
list.Set( "EffectType", "manhacksparks", {
print = "#effecttype.manhack",
material = "gui/effects/manhacksparks.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( angle:Forward() * scale )
util.Effect( "manhacksparks", effectdata, true, true )
end
} )
list.Set( "EffectType", "bloodspray", {
print = "#effecttype.blood",
material = "gui/effects/bloodspray.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( angle:Forward() * math.max( 3, scale ) / 3 )
effectdata:SetMagnitude( 1 )
effectdata:SetScale( scale + 9 )
effectdata:SetColor( 0 )
effectdata:SetFlags( 3 )
util.Effect( "bloodspray", effectdata, true, true )
end
} )
list.Set( "EffectType", "striderblood", {
print = "#effecttype.strider",
material = "gui/effects/striderblood.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( angle:Forward() * ( 6 - scale ) / 2 )
effectdata:SetScale( scale / 2 )
util.Effect( "StriderBlood", effectdata, true, true )
end
} )
list.Set( "EffectType", "shells", {
print = "#effecttype.pistol",
material = "gui/effects/shells.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetAngles( angle )
util.Effect( "ShellEject", effectdata, true, true )
end
} )
list.Set( "EffectType", "rifleshells", {
print = "#effecttype.rifle",
material = "gui/effects/rifleshells.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetAngles( angle )
util.Effect( "RifleShellEject", effectdata, true, true )
end
} )
list.Set( "EffectType", "shotgunshells", {
print = "#effecttype.shotgun",
material = "gui/effects/shotgunshells.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetAngles( angle )
util.Effect( "ShotgunShellEject", effectdata, true, true )
end
} )
list.Set( "EffectType", "cball_explode", {
print = "#effecttype.cball_explode",
material = "gui/effects/cball_explode.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
util.Effect( "cball_explode", effectdata, true, true )
end
} )
list.Set( "EffectType", "cball_bounce", {
print = "#effecttype.cball_bounce",
material = "gui/effects/cball_bounce.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( angle:Forward() * scale / 4 )
effectdata:SetRadius( scale * 2 )
util.Effect( "cball_bounce", effectdata, true, true )
end
} )
list.Set( "EffectType", "thumperdust", {
print = "#effecttype.thumperdust",
material = "gui/effects/thumperdust.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetScale( scale * 24 )
util.Effect( "ThumperDust", effectdata, true, true )
end
} )
list.Set( "EffectType", "ar2impact", {
print = "#effecttype.ar2impact",
material = "gui/effects/ar2impact.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetNormal( angle:Forward() )
util.Effect( "AR2Impact", effectdata, true, true )
end
} )
list.Set( "EffectType", "ar2explosion", {
print = "#effecttype.ar2explosion",
material = "gui/effects/ar2explosion.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetRadius( scale * 4 )
effectdata:SetNormal( angle:Forward() )
util.Effect( "AR2Explosion", effectdata, true, true )
end
} )
list.Set( "EffectType", "explosion", {
print = "#effecttype.explosion",
material = "gui/effects/explosion.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetFlags( 4 )
util.Effect( "explosion", effectdata, true, true )
end
} )
list.Set( "EffectType", "helicoptermegabomb", {
print = "#effecttype.helicoptermegabomb",
material = "gui/effects/helicoptermegabomb.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
util.Effect( "helicoptermegabomb", effectdata, true, true )
end
} )
list.Set( "EffectType", "underwaterexplosion", {
print = "#effecttype.waterexplosion",
material = "gui/effects/waterexplosion.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
util.Effect( "WaterSurfaceExplosion", effectdata, true, true )
end
} )
list.Set( "EffectType", "watersplash", {
print = "#effecttype.watersplash",
material = "gui/effects/watersplash.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetScale( scale * 2 )
effectdata:SetFlags( 0 )
util.Effect( "WaterSplash", effectdata, true, true )
end
} )
list.Set( "EffectType", "dirtywatersplash", {
print = "#effecttype.dirtywatersplash",
material = "gui/effects/dirtywatersplash.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
effectdata:SetScale( scale * 2 )
effectdata:SetFlags( 1 )
util.Effect( "WaterSplash", effectdata, true, true )
end
} )
list.Set( "EffectType", "glassimpact", {
print = "#effecttype.glassimpact",
material = "gui/effects/glassimpact.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
util.Effect( "GlassImpact", effectdata, true, true )
end
} )
list.Set( "EffectType", "bloodimpact", {
print = "#effecttype.bloodimpact",
material = "gui/effects/bloodimpact.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos )
util.Effect( "BloodImpact", effectdata, true, true )
end
} )
list.Set( "EffectType", "muzzleeffect", {
print = "#effecttype.muzzleeffect",
material = "gui/effects/muzzleeffect.png",
func = function( ent, pos, angle, scale )
local effectdata = EffectData()
effectdata:SetOrigin( pos + angle:Forward() * 4 )
effectdata:SetAngles( angle )
effectdata:SetScale( scale )
util.Effect( "MuzzleEffect", effectdata, true, true )
end
} )

View File

@@ -0,0 +1,33 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.Type = "anim"
ENT.PrintName = "Tool Ghost"
function ENT:Initialize()
if ( SERVER ) then
self:PhysicsInitBox( Vector( -4, -4, -4 ), Vector( 4, 4, 4 ) )
end
end
function ENT:SetNetworkedBonePosition( i, Pos, Angle )
self:SetNWVector( "Vector" .. i, Pos )
self:SetNWAngle( "Angle" .. i, Angle )
end
function ENT:Draw( flags )
-- Don't draw it if we're a ragdoll and haven't
-- received all of the bone positions yet.
if ( self:GetModelPhysBoneCount() > 1 and !self:GetNWVector( "Vector0", false ) ) then
return
end
BaseClass.Draw( self, flags )
end

View File

@@ -0,0 +1,258 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Hoverball"
ENT.Editable = true
function ENT:SetupDataTables()
self:NetworkVar( "Bool", 0, "Enabled" )
self:NetworkVar( "Float", 0, "TargetZ" )
self:NetworkVar( "Float", 1, "SpeedVar", { KeyName = "speed", Edit = { type = "Float", order = 1, min = 0, max = 20, title = "#tool.hoverball.speed" } } )
self:NetworkVar( "Float", 2, "AirResistanceVar", { KeyName = "resistance", Edit = { type = "Float", order = 2, min = 0, max = 10, title = "#tool.hoverball.resistance" } } )
end
function ENT:Initialize()
if ( CLIENT ) then
self.Glow = Material( "sprites/light_glow02_add" )
end
if ( SERVER ) then
self:PhysicsInit( SOLID_VPHYSICS )
-- Wake up our physics object so we don't start asleep
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:EnableGravity( !self:GetEnabled() )
phys:Wake()
end
-- Start the motion controller (so PhysicsSimulate gets called)
self:StartMotionController()
self.Fraction = 0
self.ZVelocity = 0
self:SetTargetZ( self:GetPos().z )
self:SetSpeed( 1 )
self:SetEnabled( true )
end
end
function ENT:OnRestore()
self.ZVelocity = 0
end
function ENT:GetSpeed()
if ( !game.SinglePlayer() ) then return math.Clamp( self:GetSpeedVar(), 0, 10 ) end
return self:GetSpeedVar()
end
function ENT:SetSpeed( s )
self:SetSpeedVar( s )
self:UpdateLabel()
end
function ENT:UpdateLabel()
local strength = 0
if ( self:GetPhysicsObject() ) then strength = self:GetPhysicsObject():GetMass() / 150 end
self:SetOverlayText( string.format( "Speed: %g\nResistance: %g\nStrength: %g", self:GetSpeed(), self:GetAirResistance(), strength ) )
end
function ENT:DrawEffects()
if ( !self:GetEnabled() ) then return end
local vOffset = self:GetPos()
local vPlayerEyes = LocalPlayer():EyePos()
local vDiff = ( vOffset - vPlayerEyes ):GetNormalized()
render.SetMaterial( self.Glow )
local color = Color( 70, 180, 255, 255 )
render.DrawSprite( vOffset - vDiff * 2, 22, 22, color )
local Distance = math.abs( ( self:GetTargetZ() - self:GetPos().z ) * math.sin( CurTime() * 20 ) ) * 0.05
color.r = color.r * math.Clamp( Distance, 0, 1 )
color.b = color.b * math.Clamp( Distance, 0, 1 )
color.g = color.g * math.Clamp( Distance, 0, 1 )
render.DrawSprite( vOffset + vDiff * 4, 48, 48, color )
render.DrawSprite( vOffset + vDiff * 4, 52, 52, color )
end
ENT.WantsTranslucency = true -- If model is opaque, still call DrawTranslucent
function ENT:DrawTranslucent( flags )
self:DrawEffects()
BaseClass.DrawTranslucent( self, flags )
end
function ENT:PhysicsSimulate( phys, deltatime )
if ( !self:GetEnabled() ) then return end
if ( self.ZVelocity != 0 ) then
self:SetTargetZ( self:GetTargetZ() + ( self.ZVelocity * deltatime * self:GetSpeed() ) )
self:GetPhysicsObject():Wake()
end
phys:Wake()
local Pos = phys:GetPos()
local Distance = self:GetTargetZ() - Pos.z
local AirResistance = self:GetAirResistance()
if ( Distance == 0 ) then return end
local Exponent = Distance^2
if ( Distance < 0 ) then
Exponent = Exponent * -1
end
Exponent = Exponent * deltatime * 300
local physVel = phys:GetVelocity()
local zVel = physVel.z
Exponent = Exponent - ( zVel * deltatime * 600 * ( AirResistance + 1 ) )
-- The higher you make this 300 the less it will flop about
-- I'm thinking it should actually be relative to any objects we're connected to
-- Since it seems to flop more and more the heavier the object
Exponent = math.Clamp( Exponent, -5000, 5000 )
local Linear = Vector( 0, 0, Exponent )
if ( AirResistance > 0 ) then
Linear.y = physVel.y * -1 * AirResistance
Linear.x = physVel.x * -1 * AirResistance
end
return vector_origin, Linear, SIM_GLOBAL_ACCELERATION
end
function ENT:SetZVelocity( z )
if ( z != 0 ) then
self:GetPhysicsObject():Wake()
end
self.ZVelocity = z * FrameTime() * 5000
end
function ENT:Toggle()
self:SetEnabled( !self:GetEnabled() )
if ( self:GetEnabled() ) then
self:SetTargetZ( self:GetPos().z )
end
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:EnableGravity( !self:GetEnabled() )
phys:Wake()
-- Make the mass not insane when they are turned off
if ( self.Strength ) then
if ( self:GetEnabled() ) then
phys:SetMass( 150 * self.Strength )
else
phys:SetMass( 15 )
end
end
end
end
function ENT:GetAirResistance()
return self:GetAirResistanceVar()
end
function ENT:SetAirResistance( num )
self:SetAirResistanceVar( num )
self:UpdateLabel()
end
function ENT:SetStrength( strength )
self.Strength = strength
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then
phys:SetMass( 150 * self.Strength )
end
self:UpdateLabel()
end
--
-- This gets called after the entity has been duplicated.
-- We use it to set the target z to the spawned z.. because we want
-- to hover in place rather than zoom up to the saved level!
--
function ENT:OnDuplicated( v )
self:SetTargetZ( v.Pos.z )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) && !self:GetEnabled() ) then
phys:SetMass( 15 )
end
end
if ( SERVER ) then
numpad.Register( "Hoverball_Up", function( ply, ent, keydown )
if ( !IsValid( ent ) ) then return false end
if ( keydown ) then ent:SetZVelocity( 1 ) else ent:SetZVelocity( 0 ) end
return true
end )
numpad.Register( "Hoverball_Down", function( ply, ent, keydown )
if ( !IsValid( ent ) ) then return false end
if ( keydown ) then ent:SetZVelocity( -1 ) else ent:SetZVelocity( 0 ) end
return true
end )
numpad.Register( "Hoverball_Toggle", function( ply, ent )
if ( !IsValid( ent ) ) then return false end
ent:Toggle()
return true
end )
end

View File

@@ -0,0 +1,261 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Lamp"
ENT.Editable = true
AccessorFunc( ENT, "Texture", "FlashlightTexture" )
-- Set up our data table
function ENT:SetupDataTables()
self:NetworkVar( "Bool", 0, "On", { KeyName = "on", Edit = { type = "Boolean", order = 1, title = "#entedit.enabled" } } )
self:NetworkVar( "Bool", 1, "Toggle", { KeyName = "toggle", Edit = { type = "Boolean", order = 2, title = "#tool.lamp.toggle" } } )
self:NetworkVar( "Float", 0, "LightFOV", { KeyName = "fov", Edit = { type = "Float", order = 3, min = 10, max = 170, title = "#tool.lamp.fov" } } )
self:NetworkVar( "Float", 1, "Distance", { KeyName = "dist", Edit = { type = "Float", order = 4, min = 64, max = 2048, title = "#tool.lamp.distance" } } )
self:NetworkVar( "Float", 2, "Brightness", { KeyName = "bright", Edit = { type = "Float", order = 5, min = 0, max = 8, title = "#tool.lamp.brightness" } } )
if ( SERVER ) then
self:NetworkVarNotify( "On", self.OnUpdateLight )
self:NetworkVarNotify( "LightFOV", self.OnUpdateLight )
self:NetworkVarNotify( "Brightness", self.OnUpdateLight )
self:NetworkVarNotify( "Distance", self.OnUpdateLight )
end
end
-- Custom drive mode
function ENT:GetEntityDriveMode()
return "drive_noclip"
end
function ENT:Initialize()
if ( SERVER ) then
self:PhysicsInit( SOLID_VPHYSICS )
self:DrawShadow( false )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() end
local lightInfo = self:GetLightInfo()
self:SetSkin( lightInfo.Skin )
end
if ( CLIENT ) then
self.PixVis = util.GetPixelVisibleHandle()
end
end
local defaultOffset = Vector( 5, 0, 0 )
local defaultAngle = Angle( 0, 0, 0 )
function ENT:GetLightInfo()
local lightInfo = {}
local lampEntry = list.GetEntry( "LampModels", self:GetModel() )
if ( lampEntry ) then
lightInfo = lampEntry
end
lightInfo.Offset = lightInfo.Offset or defaultOffset
lightInfo.Angle = lightInfo.Angle or defaultAngle
lightInfo.NearZ = lightInfo.NearZ or 12
lightInfo.Scale = lightInfo.Scale or 2
lightInfo.Skin = lightInfo.Skin or 1
return lightInfo
end
if ( SERVER ) then
function ENT:Think()
self.BaseClass.Think( self )
if ( !IsValid( self.flashlight ) ) then return end
if ( string.FromColor( self.flashlight:GetColor() ) != string.FromColor( self:GetColor() ) ) then
self.flashlight:SetColor( self:GetColor() )
self:UpdateLight()
end
end
function ENT:OnTakeDamage( dmginfo )
self:TakePhysicsDamage( dmginfo )
end
function ENT:Switch( bOn )
self:SetOn( bOn )
end
function ENT:OnSwitch( bOn )
if ( bOn && IsValid( self.flashlight ) ) then return end
if ( !bOn ) then
SafeRemoveEntity( self.flashlight )
self.flashlight = nil
return
end
local lightInfo = self:GetLightInfo()
self.flashlight = ents.Create( "env_projectedtexture" )
self.flashlight:SetParent( self )
-- The local positions are the offsets from parent..
local offset = lightInfo.Offset * -1
offset.x = offset.x + 5 -- Move the position a bit back to preserve old behavior. Ideally this would be moved by NearZ?
self.flashlight:SetLocalPos( -offset )
self.flashlight:SetLocalAngles( lightInfo.Angle )
self.flashlight:SetKeyValue( "enableshadows", 1 )
self.flashlight:SetKeyValue( "nearz", lightInfo.NearZ )
self.flashlight:SetKeyValue( "lightfov", math.Clamp( self:GetLightFOV(), 10, 170 ) )
local dist = self:GetDistance()
if ( !game.SinglePlayer() ) then dist = math.Clamp( dist, 64, 2048 ) end
self.flashlight:SetKeyValue( "farz", dist )
local c = self:GetColor()
local b = self:GetBrightness()
if ( !game.SinglePlayer() ) then b = math.Clamp( b, 0, 8 ) end
self.flashlight:SetKeyValue( "lightcolor", Format( "%i %i %i 255", c.r * b, c.g * b, c.b * b ) )
self.flashlight:Spawn()
self.flashlight:Input( "SpotlightTexture", NULL, NULL, self:GetFlashlightTexture() )
end
function ENT:Toggle()
self:SetOn( !self:GetOn() )
end
function ENT:OnUpdateLight( name, old, new )
if ( name == "On" ) then
self:OnSwitch( new )
end
if ( !IsValid( self.flashlight ) ) then return end
if ( name == "LightFOV" ) then
self.flashlight:Input( "FOV", NULL, NULL, tostring( math.Clamp( new, 10, 170 ) ) )
elseif ( name == "Distance" ) then
if ( !game.SinglePlayer() ) then new = math.Clamp( new, 64, 2048 ) end
self.flashlight:SetKeyValue( "farz", new )
elseif ( name == "Brightness" ) then
local c = self:GetColor()
local b = new
if ( !game.SinglePlayer() ) then b = math.Clamp( b, 0, 8 ) end
self.flashlight:SetKeyValue( "lightcolor", Format( "%i %i %i 255", c.r * b, c.g * b, c.b * b ) )
end
end
function ENT:UpdateLight()
if ( !IsValid( self.flashlight ) ) then return end
self.flashlight:Input( "SpotlightTexture", NULL, NULL, self:GetFlashlightTexture() )
self.flashlight:Input( "FOV", NULL, NULL, tostring( math.Clamp( self:GetLightFOV(), 10, 170 ) ) )
local dist = self:GetDistance()
if ( !game.SinglePlayer() ) then dist = math.Clamp( dist, 64, 2048 ) end
self.flashlight:SetKeyValue( "farz", dist )
local c = self:GetColor()
local b = self:GetBrightness()
if ( !game.SinglePlayer() ) then b = math.Clamp( b, 0, 8 ) end
self.flashlight:SetKeyValue( "lightcolor", Format( "%i %i %i 255", c.r * b, c.g * b, c.b * b ) )
end
-- The rest is for client only
return
end
-- Show the name of the player that spawned it..
function ENT:GetOverlayText()
return self:GetPlayerName()
end
local matLight = Material( "sprites/light_ignorez" )
--local matBeam = Material( "effects/lamp_beam" )
function ENT:DrawEffects()
-- No glow if we're not switched on!
if ( !self:GetOn() ) then return end
local lightInfo = self:GetLightInfo()
local LightPos = self:LocalToWorld( lightInfo.Offset )
local LightNrm = self:LocalToWorldAngles( lightInfo.Angle ):Forward()
-- 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()
--]]
local ViewNormal = self:GetPos() - EyePos()
local Distance = ViewNormal:Length()
ViewNormal:Normalize()
local ViewDot = ViewNormal:Dot( LightNrm * -1 )
if ( ViewDot >= 0 ) then
render.SetMaterial( matLight )
local Visibile = util.PixelVisible( LightPos, 16, self.PixVis )
if ( !Visibile ) then return end
local Size = math.Clamp( Distance * Visibile * ViewDot * lightInfo.Scale, 64, 512 )
Distance = math.Clamp( Distance, 32, 800 )
local Alpha = math.Clamp( ( 1000 - Distance ) * Visibile * ViewDot, 0, 100 )
local Col = self:GetColor()
Col.a = Alpha
render.DrawSprite( LightPos, Size, Size, Col )
render.DrawSprite( LightPos, Size * 0.4, Size * 0.4, Color( 255, 255, 255, Alpha ) )
end
end
ENT.WantsTranslucency = true -- If model is opaque, still call DrawTranslucent
function ENT:DrawTranslucent( flags )
BaseClass.DrawTranslucent( self, flags )
self:DrawEffects()
end

View File

@@ -0,0 +1,126 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Light"
ENT.Editable = true
local MODEL = Model( "models/maxofs2d/light_tubular.mdl" )
--
-- Set up our data table
--
function ENT:SetupDataTables()
self:NetworkVar( "Bool", 0, "On", { KeyName = "on", Edit = { type = "Boolean", order = 1, title = "#entedit.enabled" } } )
self:NetworkVar( "Bool", 1, "Toggle", { KeyName = "tg", Edit = { type = "Boolean", order = 2, title = "#tool.light.toggle" } } )
self:NetworkVar( "Float", 1, "LightSize", { KeyName = "sz", Edit = { type = "Float", order = 3, min = 0, max = 1024, title = "#tool.light.size" } } )
self:NetworkVar( "Float", 2, "Brightness", { KeyName = "br", Edit = { type = "Int", order = 4, min = 0, max = 6, title = "#tool.light.brightness" } } )
self:NetworkVar( "Bool", 2, "LightWorld", { KeyName = "world", Edit = { type = "Boolean", order = 5, title = "#tool.light.noworld", category = "#entedit.advanced" } } )
self:NetworkVar( "Bool", 3, "LightModels", { KeyName = "models", Edit = { type = "Boolean", order = 6, title = "#tool.light.nomodels", category = "#entedit.advanced" } } )
end
function ENT:Initialize()
if ( CLIENT ) then
self.PixVis = util.GetPixelVisibleHandle()
end
if ( SERVER ) then -- Lights are rolling around even though the model isn't round!!
self:SetModel( MODEL )
self:PhysicsInit( SOLID_VPHYSICS )
self:DrawShadow( false )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() end
end
end
function ENT:OnTakeDamage( dmginfo )
-- React to physics damage
self:TakePhysicsDamage( dmginfo )
end
function ENT:Toggle()
self:SetOn( !self:GetOn() )
end
function ENT:Think()
self.BaseClass.Think( self )
if ( CLIENT ) then
if ( !self:GetOn() ) then return end
local noworld = self:GetLightWorld()
local dlight = DynamicLight( self:EntIndex(), noworld )
if ( dlight ) then
local c = self:GetColor()
local size = self:GetLightSize()
local brght = self:GetBrightness()
-- Clamp for multiplayer
if ( !game.SinglePlayer() ) then
size = math.Clamp( size, 0, 1024 )
brght = math.Clamp( brght, 0, 6 )
end
dlight.Pos = self:GetPos()
dlight.r = c.r
dlight.g = c.g
dlight.b = c.b
dlight.Brightness = brght
dlight.Decay = size * 5
dlight.Size = size
dlight.DieTime = CurTime() + 1
dlight.noworld = noworld
dlight.nomodel = self:GetLightModels()
end
end
end
function ENT:GetOverlayText()
return self:GetPlayerName()
end
local matLight = Material( "sprites/light_ignorez" )
function ENT:DrawEffects()
if ( !self:GetOn() ) then return end
local LightPos = self:GetPos()
local Visibile = util.PixelVisible( LightPos, 4, self.PixVis )
if ( !Visibile || Visibile < 0.1 ) then return end
local c = self:GetColor()
local Alpha = 255 * Visibile
local up = self:GetAngles():Up()
render.SetMaterial( matLight )
render.DrawSprite( LightPos - up * 2, 8, 8, Color( 255, 255, 255, Alpha ) )
render.DrawSprite( LightPos - up * 4, 8, 8, Color( 255, 255, 255, Alpha ) )
render.DrawSprite( LightPos - up * 6, 8, 8, Color( 255, 255, 255, Alpha ) )
render.DrawSprite( LightPos - up * 5, 64, 64, Color( c.r, c.g, c.b, 64 ) )
end
ENT.WantsTranslucency = true -- If model is opaque, still call DrawTranslucent
function ENT:DrawTranslucent( flags )
BaseClass.DrawTranslucent( self, flags )
self:DrawEffects()
end

View File

@@ -0,0 +1,557 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Thruster"
if ( CLIENT ) then
CreateConVar( "cl_drawthrusterseffects", "1", 0, "Should Sandbox Thruster effects be visible?" )
end
function ENT:SetEffect( name )
self:SetNWString( "Effect", name )
end
function ENT:GetEffect()
return self:GetNWString( "Effect", "" )
end
function ENT:SetOn( on )
self:SetNWBool( "On", on )
end
function ENT:IsOn()
return self:GetNWBool( "On", false )
end
function ENT:SetOffset( v )
self:SetNWVector( "Offset", v )
end
function ENT:GetOffset()
return self:GetNWVector( "Offset" )
end
function ENT:Initialize()
if ( CLIENT ) then
self.ShouldDraw = true
-- Make the render bounds a bigger so the effect doesn't get snipped off
local mx, mn = self:GetRenderBounds()
self:SetRenderBounds( mn + Vector( 0, 0, 128 ), mx )
self.Seed = math.Rand( 0, 10000 )
else
self:PhysicsInit( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() end
local max = self:OBBMaxs()
local min = self:OBBMins()
self.ThrustOffset = Vector( 0, 0, max.z )
self.ThrustOffsetR = Vector( 0, 0, min.z )
self.ForceAngle = self.ThrustOffset:GetNormalized() * -1
self:SetForce( 2000 )
self:SetEffect( "Fire" )
self:SetOffset( self.ThrustOffset )
self:StartMotionController()
self:Switch( false )
self.ActivateOnDamage = true
self.SoundName = Sound( "PhysicsCannister.ThrusterLoop" )
end
end
if ( CLIENT ) then
function ENT:DrawEffects()
if ( !self:IsOn() ) then return end
if ( self.ShouldDraw == false ) then return end
if ( self:GetEffect() == "" or self:GetEffect() == "none" ) then return end
for id, t in pairs( list.GetForEdit( "ThrusterEffects" ) ) do
if ( t.thruster_effect != self:GetEffect() or !t.effectDraw ) then continue end
t.effectDraw( self )
break
end
end
ENT.WantsTranslucency = true -- If model is opaque, still call DrawTranslucent
function ENT:DrawTranslucent( flags )
BaseClass.DrawTranslucent( self, flags )
self:DrawEffects()
end
end
function ENT:Think()
BaseClass.Think( self )
if ( SERVER and self.SwitchOffTime and self.SwitchOffTime < CurTime() ) then
self.SwitchOffTime = nil
self:Switch( false )
end
if ( CLIENT ) then
self.ShouldDraw = GetConVarNumber( "cl_drawthrusterseffects" ) != 0
if ( !self:IsOn() ) then self.OnStart = nil return end
self.OnStart = self.OnStart or CurTime()
if ( self.ShouldDraw == false ) then return end
if ( self:GetEffect() == "" or self:GetEffect() == "none" ) then return end
for id, t in pairs( list.GetForEdit( "ThrusterEffects" ) ) do
if ( t.thruster_effect != self:GetEffect() or !t.effectThink ) then continue end
t.effectThink( self )
break
end
end
end
if ( CLIENT ) then
--[[---------------------------------------------------------
Use the same emitter, but get a new one every 2 seconds
This will fix any draw order issues
-----------------------------------------------------------]]
function ENT:GetEmitter( Pos, b3D )
if ( self.Emitter and self.EmitterIs3D == b3D and self.EmitterTime > CurTime() ) then
return self.Emitter
end
if ( IsValid( self.Emitter ) ) then
self.Emitter:Finish()
end
self.Emitter = ParticleEmitter( Pos, b3D )
self.EmitterIs3D = b3D
self.EmitterTime = CurTime() + 2
return self.Emitter
end
end
function ENT:OnRemove()
if ( IsValid( self.Emitter ) ) then
self.Emitter:Finish()
end
if ( self.Sound ) then
self.Sound:Stop()
end
end
if ( SERVER ) then
function ENT:SetForce( force, mul )
if ( force ) then self.force = force end
mul = mul or 1
local phys = self:GetPhysicsObject()
if ( !IsValid( phys ) ) then
Msg( "Warning: [gmod_thruster] Physics object isn't valid!\n" )
return
end
-- Get the data in worldspace
local ThrusterWorldPos = phys:LocalToWorld( self.ThrustOffset )
local ThrusterWorldForce = phys:LocalToWorldVector( self.ThrustOffset * -1 )
-- Calculate the velocity
ThrusterWorldForce = ThrusterWorldForce * self.force * mul * 50
local motionEnabled = phys:IsMotionEnabled()
phys:EnableMotion( true ) -- Dirty hack for PhysObj.CalculateVelocityOffset while frozen
self.ForceLinear, self.ForceAngle = phys:CalculateVelocityOffset( ThrusterWorldForce, ThrusterWorldPos )
phys:EnableMotion( motionEnabled )
self.ForceLinear = phys:WorldToLocalVector( self.ForceLinear )
if ( mul > 0 ) then
self:SetOffset( self.ThrustOffset )
else
self:SetOffset( self.ThrustOffsetR )
end
self:SetNWVector( "1", self.ForceAngle )
self:SetNWVector( "2", self.ForceLinear )
self:SetOverlayText( "Force: " .. math.floor( self.force ) )
end
function ENT:AddMul( mul, bDown )
if ( self:GetToggle() ) then
if ( !bDown ) then return end
if ( self.Multiply == mul ) then
self.Multiply = 0
else
self.Multiply = mul
end
else
self.Multiply = self.Multiply or 0
self.Multiply = self.Multiply + mul
end
self:SetForce( nil, self.Multiply )
self:Switch( self.Multiply != 0 )
end
function ENT:OnTakeDamage( dmginfo )
self:TakePhysicsDamage( dmginfo )
if ( !self.ActivateOnDamage ) then return end
self:Switch( true )
self.SwitchOffTime = CurTime() + 5
end
function ENT:Use( activator, caller )
end
function ENT:PhysicsSimulate( phys, deltatime )
if ( !self:IsOn() ) then return SIM_NOTHING end
return self.ForceAngle, self.ForceLinear, SIM_LOCAL_ACCELERATION
end
-- Switch thruster on or off
function ENT:Switch( on )
if ( !IsValid( self ) ) then return false end
self:SetOn( on )
if ( on ) then
self:StartThrustSound()
else
self:StopThrustSound()
end
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() end
return true
end
function ENT:SetSound( sound )
-- No change, don't do shit
if ( self.SoundName == sound ) then return end
-- Gracefully shutdown
if ( self:IsOn() ) then
self:StopThrustSound()
end
self.SoundName = Sound( sound )
self.Sound = nil
-- Now start the new sound
if ( self:IsOn() ) then
self:StartThrustSound()
end
end
-- Starts the looping sound
function ENT:StartThrustSound()
if ( !self.SoundName or self.SoundName == "" ) then return end
local valid = false
for _, v in pairs( list.Get( "ThrusterSounds" ) ) do
if ( v.thruster_soundname == self.SoundName ) then valid = true break end
end
if ( !valid ) then return end
if ( !self.Sound ) then
-- Make sure the fadeout gets to every player!
local filter = RecipientFilter()
filter:AddPAS( self:GetPos() )
self.Sound = CreateSound( self, self.SoundName, filter )
end
self.Sound:PlayEx( 0.5, 100 )
end
-- Stop the looping sound
function ENT:StopThrustSound()
if ( self.Sound ) then
self.Sound:ChangeVolume( 0.0, 0.25 )
end
end
-- Sets whether this is a toggle thruster or not
function ENT:SetToggle( tog )
self.Toggle = tog
end
-- Returns true if this is a toggle thruster
function ENT:GetToggle()
return self.Toggle
end
numpad.Register( "Thruster_On", function( ply, ent, mul )
if ( !IsValid( ent ) ) then return false end
ent:AddMul( mul, true )
return true
end )
numpad.Register( "Thruster_Off", function( ply, ent, mul )
if ( !IsValid( ent ) ) then return false end
ent:AddMul( mul * -1, false )
return true
end )
end
--[[---------------------------------------------------------
Register the effects
-----------------------------------------------------------]]
list.Set( "ThrusterEffects", "#thrustereffect.none", { thruster_effect = "none" } )
local matHeatWave = Material( "sprites/heatwave" )
local matFire = Material( "effects/fire_cloud1" )
list.Set( "ThrusterEffects", "#thrustereffect.flames", {
thruster_effect = "fire",
effectDraw = function( self )
local vOffset = self:LocalToWorld( self:GetOffset() )
local vNormal = ( vOffset - self:GetPos() ):GetNormalized()
local scroll = self.Seed + ( CurTime() * -10 )
local size = self:OBBMaxs() - self:OBBMins()
size = math.min( size.x, size.y, 50 )
local Scale = math.Clamp( ( CurTime() - self.OnStart ) * 5, 0, 1 )
render.SetMaterial( matFire )
render.StartBeam( 3 )
render.AddBeam( vOffset, size * Scale, scroll, Color( 0, 0, 255, 128 ) )
render.AddBeam( vOffset + vNormal * 60 * Scale, 32 * Scale, scroll + 1, Color( 255, 255, 255, 128 ) )
render.AddBeam( vOffset + vNormal * 148 * Scale, 32 * Scale, scroll + 3, Color( 255, 255, 255, 0 ) )
render.EndBeam()
scroll = scroll * 0.5
render.UpdateRefractTexture()
render.SetMaterial( matHeatWave )
render.StartBeam( 3 )
render.AddBeam( vOffset, size * Scale, scroll, Color( 0, 0, 255, 128 ) )
render.AddBeam( vOffset + vNormal * 32 * Scale, 32 * Scale, scroll + 2, color_white )
render.AddBeam( vOffset + vNormal * 128 * Scale, 48 * Scale, scroll + 5, Color( 0, 0, 0, 0 ) )
render.EndBeam()
scroll = scroll * 1.3
render.SetMaterial( matFire )
render.StartBeam( 3 )
render.AddBeam( vOffset, size * Scale, scroll, Color( 0, 0, 255, 128 ) )
render.AddBeam( vOffset + vNormal * 60 * Scale, 16 * Scale, scroll + 1, Color( 255, 255, 255, 128 ) )
render.AddBeam( vOffset + vNormal * 148 * Scale, 16 * Scale, scroll + 3, Color( 255, 255, 255, 0 ) )
render.EndBeam()
end
} )
local matPlasma = Material( "effects/strider_muzzle" )
list.Set( "ThrusterEffects", "#thrustereffect.plasma", {
thruster_effect = "plasma",
effectDraw = function( self )
local vOffset = self:LocalToWorld( self:GetOffset() )
local vNormal = ( vOffset - self:GetPos() ):GetNormalized()
local scroll = self.Seed + ( CurTime() * -20 )
local size = self:OBBMaxs() - self:OBBMins()
size = math.min( size.x, size.y ) * 1.5
render.SetMaterial( matPlasma )
scroll = scroll * 0.9
render.StartBeam( 3 )
render.AddBeam( vOffset, size, scroll, Color( 0, 255, 255, 255 ) )
render.AddBeam( vOffset + vNormal * 8, size, scroll + 0.01, color_white )
render.AddBeam( vOffset + vNormal * 64, size, scroll + 0.02, Color( 0, 255, 255, 0 ) )
render.EndBeam()
scroll = scroll * 0.9
render.StartBeam( 3 )
render.AddBeam( vOffset, size, scroll, Color( 0, 255, 255, 255 ) )
render.AddBeam( vOffset + vNormal * 8, size, scroll + 0.01, color_white )
render.AddBeam( vOffset + vNormal * 64, size, scroll + 0.02, Color( 0, 255, 255, 0 ) )
render.EndBeam()
scroll = scroll * 0.9
render.StartBeam( 3 )
render.AddBeam( vOffset, size, scroll, Color( 0, 255, 255, 255 ) )
render.AddBeam( vOffset + vNormal * 8, size, scroll + 0.01, color_white )
render.AddBeam( vOffset + vNormal * 64, size, scroll + 0.02, Color( 0, 255, 255, 0 ) )
render.EndBeam()
end
} )
list.Set( "ThrusterEffects", "#thrustereffect.magic", {
thruster_effect = "magic",
effectThink = function( self )
self.SmokeTimer = self.SmokeTimer or 0
if ( self.SmokeTimer > CurTime() ) then return end
self.SmokeTimer = CurTime() + 0.01
local vOffset = self:LocalToWorld( self:GetOffset() )
local vNormal = ( vOffset - self:GetPos() ):GetNormalized()
local size = self:OBBMaxs() - self:OBBMins()
vOffset = vOffset + VectorRand() * math.min( size.x, size.y ) / 3
local emitter = self:GetEmitter( vOffset, false )
if ( !IsValid( emitter ) ) then return end
local particle = emitter:Add( "sprites/gmdm_pickups/light", vOffset )
if ( !particle ) then return end
particle:SetVelocity( vNormal * math.Rand( 80, 160 ) )
particle:SetDieTime( 0.5 )
particle:SetStartAlpha( 255 )
particle:SetEndAlpha( 255 )
particle:SetStartSize( math.Rand( 1, 3 ) )
particle:SetEndSize( 0 )
particle:SetRoll( math.Rand( -0.2, 0.2 ) )
end
} )
list.Set( "ThrusterEffects", "#thrustereffect.rings", {
thruster_effect = "rings",
effectThink = function( self )
self.RingTimer = self.RingTimer or 0
if ( self.RingTimer > CurTime() ) then return end
self.RingTimer = CurTime() + 0.01
local vOffset = self:LocalToWorld( self:GetOffset() )
local vNormal = ( vOffset - self:GetPos() ):GetNormalized()
local size = self:OBBMaxs() - self:OBBMins()
vOffset = vOffset + vNormal * 5
local emitter = self:GetEmitter( vOffset, true )
if ( !IsValid( emitter ) ) then return end
local particle = emitter:Add( "effects/select_ring", vOffset )
if ( !particle ) then return end
particle:SetVelocity( vNormal * 300 )
particle:SetLifeTime( 0 )
particle:SetDieTime( 0.2 )
particle:SetStartAlpha( 255 )
particle:SetEndAlpha( 0 )
particle:SetStartSize( math.min( size.x, size.y ) / 2 )
particle:SetEndSize( 10 )
particle:SetAngles( vNormal:Angle() )
particle:SetColor( math.Rand( 10, 100 ), math.Rand( 100, 220 ), math.Rand( 240, 255 ) )
end
} )
list.Set( "ThrusterEffects", "#thrustereffect.smoke", {
thruster_effect = "smoke",
effectThink = function( self )
self.SmokeTimer = self.SmokeTimer or 0
if ( self.SmokeTimer > CurTime() ) then return end
self.SmokeTimer = CurTime() + 0.015
local size = self:OBBMaxs() - self:OBBMins()
size = math.min( size.x, size.y ) / 2
local vOffset = self:LocalToWorld( self:GetOffset() )
-- Make the offset farther so the normal isn't jumping around crazily on certain models
local vNormalRand = vOffset + ( vOffset - self:GetPos() ):GetNormalized() * 32 + VectorRand() * 3
local vNormal = ( vNormalRand - self:GetPos() ):GetNormalized()
local emitter = self:GetEmitter( vOffset, false )
if ( !IsValid( emitter ) ) then return end
local particle = emitter:Add( "particles/smokey", vOffset + VectorRand() * 3 )
if ( !particle ) then return end
local vel_scale = math.Rand( 10, 30 ) * 10 / math.Clamp( self:GetVelocity():Length() / 200, 1, 10 )
local velocity = vNormal * vel_scale
particle:SetVelocity( velocity )
particle:SetDieTime( 2.0 )
particle:SetGravity( Vector( 0, 0, 32 ) )
particle:SetStartAlpha( math.Rand( 50, 150 ) )
particle:SetStartSize( size )
particle:SetEndSize( math.Rand( 64, 128 ) )
particle:SetRoll( math.Rand( -0.2, 0.2 ) )
particle:SetColor( 200, 200, 210 )
end
} )

View File

@@ -0,0 +1,204 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Wheel"
-- Set up our data table
function ENT:SetupDataTables()
self:NetworkVar( "Bool", 0, "Toggle" )
self:NetworkVar( "Float", 0, "Direction" )
end
function ENT:Initialize()
if ( SERVER ) then
self:PhysicsInit( SOLID_VPHYSICS )
self:SetUseType( SIMPLE_USE )
self:SetToggle( false )
self.ToggleState = false
self.BaseTorque = 1
self.TorqueScale = 1
end
end
-- Sets the base torque
function ENT:SetBaseTorque( base )
self.BaseTorque = base
if ( self.BaseTorque == 0 ) then self.BaseTorque = 1 end
self:UpdateOverlayText()
end
-- Refresh the entity overlay text
function ENT:UpdateOverlayText()
self:SetOverlayText( "Torque: " .. math.floor( self.BaseTorque ) )
end
-- Sets the axis (world space)
function ENT:SetAxis( vec )
self.Axis = self:GetPos() + vec * 512
self.Axis = self:NearestPoint( self.Axis )
self.Axis = self:WorldToLocal( self.Axis )
end
function ENT:OnTakeDamage( dmginfo )
self:TakePhysicsDamage( dmginfo )
end
-- Set the motor constraint
function ENT:SetMotor( Motor )
self.Motor = Motor
end
-- Get the motor constraint :)
function ENT:GetMotor()
-- Fuck knows why it's doing this here.
if ( !IsValid( self.Motor ) ) then
self.Motor = constraint.FindConstraintEntity( self, "Motor" )
end
return self.Motor
end
-- Forward key is pressed/released
function ENT:Forward( onoff, mul )
--
-- Is this entity invalid now?
-- If so return false to remove it
--
if ( !IsValid( self ) ) then return false end
local Motor = self:GetMotor()
if ( !IsValid( Motor ) ) then return false end
local toggle = self:GetToggle()
--
-- If we're toggle mode and the key has been
-- released then just return.
--
if ( toggle and !onoff ) then return true end
mul = mul or 1
local Speed = Motor.direction * mul * self.TorqueScale
if ( !onoff ) then Speed = 0 end
if ( toggle and onoff ) then
self.ToggleState = !self.ToggleState
if ( !self.ToggleState ) then
Speed = 0
end
end
Motor:Fire( "Scale", Speed, 0 )
Motor.forcescale = Speed
Motor:Fire( "Activate", "", 0 )
return true
end
-- Reverse key is pressed/released
function ENT:Reverse( onoff )
return self:Forward( onoff, -1 )
end
-- Register numpad functions
if ( SERVER ) then
numpad.Register( "WheelForward", function( ply, ent, onoff )
if ( !IsValid( ent ) ) then return false end
return ent:Forward( onoff )
end )
numpad.Register( "WheelReverse", function( ply, ent, onoff )
if ( !IsValid( ent ) ) then return false end
return ent:Reverse( onoff )
end )
end
-- Todo? Scale Motor.direction?
function ENT:SetTorque( torque )
if ( self.BaseTorque == 0 ) then self.BaseTorque = 1 end
self.TorqueScale = torque / self.BaseTorque
local Motor = self:GetMotor()
if ( !IsValid( Motor ) ) then return end
Motor:Fire( "Scale", Motor.direction * Motor.forcescale * self.TorqueScale, 0 )
self:SetOverlayText( "Torque: " .. math.floor( torque ) )
end
-- Creates the direction arrows on the wheel
function ENT:DoDirectionEffect()
local Motor = self:GetMotor()
if ( !IsValid( Motor ) ) then return end
local effectdata = EffectData()
effectdata:SetOrigin( self.Axis * 100 ) -- Ugly hack, but necessary due to network precision problems of EffectData()
effectdata:SetEntity( self )
effectdata:SetScale( Motor.direction )
util.Effect( "wheel_indicator", effectdata, true, true )
end
-- Reverse the wheel direction when a player uses the wheel
function ENT:Use( activator, caller, type, value )
local Motor = self:GetMotor()
local Owner = self:GetPlayer()
if ( IsValid( Motor ) and ( Owner == nil or Owner == activator ) ) then
if ( Motor.direction == 1 ) then
Motor.direction = -1
else
Motor.direction = 1
end
Motor:Fire( "Scale", Motor.direction * Motor.forcescale * self.TorqueScale, 0 )
self:SetDirection( Motor.direction )
self:DoDirectionEffect()
end
end

View File

@@ -0,0 +1,245 @@
ENT.Type = "point"
if ( CLIENT ) then return end
local DIR_BACKWARD = -1
local DIR_NONE = 0
local DIR_FORWARD = 1
local TYPE_NORMAL = 0
local TYPE_MUSCLE = 1
function ENT:Initialize()
self.last_time = CurTime()
self.init_time = CurTime()
self.min_length = self.min_length or 1
self.type = self.type or TYPE_NORMAL
self.ctime = self.ctime or 0
self.isexpanded = false
end
function ENT:KeyValue( key, value )
if ( key == "minlength" ) then self.min_length = tonumber( value )
elseif ( key == "maxlength" ) then self.max_length = tonumber( value )
elseif ( key == "type" ) then self.type = tonumber( value )
end
end
function ENT:Think()
self:NextThink( CurTime() + 0.01 )
local TimeDiff = CurTime() - self.last_time
self.last_time = CurTime()
if ( !self.constraint ) then return true end
if ( !self.direction ) then return true end
if ( self.direction == DIR_NONE ) then return true end
local current_length = self.current_length
if ( self.type == TYPE_NORMAL ) then
local dist = 0
if ( self.direction == DIR_FORWARD ) then
local speed = self.constraint.fwd_speed
dist = speed * TimeDiff
elseif ( self.direction == DIR_BACKWARD ) then
local speed = self.constraint.bwd_speed
dist = -speed * TimeDiff
end
if ( dist == 0 ) then return true end
current_length = current_length + dist
if ( self.min_length && current_length < self.min_length ) then
current_length = self.min_length
if ( self.toggle ) then self.direction = DIR_NONE end
end
if ( self.max_length ) then
if ( current_length > self.max_length ) then
current_length = self.max_length
self.isexpanded = true
if ( self.toggle ) then self.direction = DIR_NONE end
else
self.isexpanded = false
end
end
elseif ( self.type == TYPE_MUSCLE ) then
local amp = self.constraint.amplitude
local per = self.constraint.period
if ( per == 0 ) then return true end
local spos = ( math.sin( self.ctime * math.pi * per ) + 1 ) * ( amp / 2 )
if ( spos > amp ) then spos = amp end
if ( spos < 0 ) then spos = 0 end
if ( self.direction != DIR_NONE ) then
current_length = self.min_length + spos
end
self.ctime = self.ctime + TimeDiff
end
self.current_length = current_length
self.constraint:Fire( "SetSpringLength", current_length, 0 )
if ( self.rope ) then self.rope:Fire( "SetLength", current_length, 0 ) end
return true
end
function ENT:GetSomePos( ent, phys, lpos )
if ( ent:EntIndex() == 0 ) then
return lpos
end
if ( IsValid( phys ) ) then
return phys:LocalToWorld( lpos )
else
return ent:LocalToWorld( lpos )
end
end
function ENT:SetConstraint( c )
self.constraint = c
self.direction = DIR_NONE
self.toggle = c.toggle
local p1 = self:GetSomePos( c.Ent1, c.Phys1, c.LPos1 )
local p2 = self:GetSomePos( c.Ent2, c.Phys2, c.LPos2 )
local dist = ( p1 - p2 ):Length()
self.current_length = dist
if ( self.max_length ) then
self.isexpanded = ( self.current_length >= self.max_length )
end
if ( self.type == TYPE_MUSCLE ) then
local amp = self.constraint.amplitude
local per = self.constraint.period
local spos = self.current_length - self.min_length
spos = spos / ( amp * 2 )
spos = spos - 1
spos = math.Clamp( spos, -1, 1 ) -- just in case!
spos = math.asin( spos )
spos = spos / ( per * math.pi )
self.ctime = spos
end
end
function ENT:SetRope( r )
self.rope = r
end
function ENT:SetDirection( n )
self.direction = n
end
function ENT:GetDirection()
return self.direction
end
function ENT:IsExpanded()
return self.isexpanded
end
--[[----------------------------------------------------------------------
HydraulicToggle - Toggle hydraulic on and off
------------------------------------------------------------------------]]
local function HydraulicToggle( ply, hyd )
if ( !IsValid( hyd ) ) then return false end
-- I hate this, shouldn't we just be calling hyd:Toggle()
if ( hyd:GetDirection() == 0 ) then
if ( hyd:IsExpanded() ) then
hyd:SetDirection( -1 )
else
hyd:SetDirection( 1 )
end
elseif ( hyd:GetDirection() == -1 ) then
hyd:SetDirection( 1 )
elseif ( hyd:GetDirection() == 1 ) then
hyd:SetDirection( -1 )
end
end
numpad.Register( "HydraulicToggle", HydraulicToggle )
--[[----------------------------------------------------------------------
WinchOn - Called to switch the winch on
------------------------------------------------------------------------]]
local function WinchOn( ply, winch, dir )
if ( !IsValid( winch ) ) then return false end
winch:SetDirection( dir )
end
numpad.Register( "WinchOn", WinchOn )
numpad.Register( "HydraulicDir", WinchOn ) -- A little cheat
--[[----------------------------------------------------------------------
WinchOff - Called to switch the winch off
------------------------------------------------------------------------]]
local function WinchOff( ply, winch )
if ( !IsValid( winch ) ) then return false end
winch:SetDirection( 0 )
end
numpad.Register( "WinchOff", WinchOff )
--[[----------------------------------------------------------------------
WinchToggle - Called to toggle the winch
------------------------------------------------------------------------]]
local function WinchToggle( ply, winch, dir )
if ( !IsValid( winch ) ) then return false end
if ( winch:GetDirection() == dir ) then
winch:SetDirection( 0 )
else
winch:SetDirection( dir )
end
end
numpad.Register( "WinchToggle", WinchToggle )
--[[----------------------------------------------------------------------
MuscleToggle - Called to toggle the muslce
------------------------------------------------------------------------]]
local function MuscleToggle( ply, hyd )
if ( !IsValid( hyd ) ) then return false end
if ( hyd:GetDirection() == 0 ) then
hyd:SetDirection( 1 )
else
hyd:SetDirection( 0 )
end
end
numpad.Register( "MuscleToggle", MuscleToggle )

View File

@@ -0,0 +1,74 @@
AddCSLuaFile()
ENT.Base = "base_nextbot"
ENT.Spawnable = false
function ENT:Initialize()
--self:SetModel( "models/props_halloween/ghost_no_hat.mdl" )
--self:SetModel( "models/props_wasteland/controlroom_filecabinet002a.mdl" )
self:SetModel( "models/mossman.mdl" )
end
function ENT:RunBehaviour()
while ( true ) do
self:StartActivity( ACT_WALK ) -- walk anims
self.loco:SetDesiredSpeed( 100 ) -- walk speeds
-- Choose a random location within 400 units of our position
local targetPos = self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 400
-- Search for walkable space there, or nearby
local area = navmesh.GetNearestNavArea( targetPos )
-- We found walkable space, get the closest point on that area to where we want to be
if ( IsValid( area ) ) then targetPos = area:GetClosestPointOnArea( targetPos ) end
-- walk to the target place (yielding)
self:MoveToPos( targetPos )
self:StartActivity( ACT_IDLE ) -- revert to idle activity
self:PlaySequenceAndWait( "idle_to_sit_ground" ) -- Sit on the floor
self:SetSequence( "sit_ground" ) -- Stay sitting
coroutine.wait( self:PlayScene( "scenes/eli_lab/mo_gowithalyx01.vcd" ) ) -- play a scene and wait for it to finish before progressing
self:PlaySequenceAndWait( "sit_ground_to_idle" ) -- Get up
-- find the furthest away hiding spot
local pos = self:FindSpot( "random", { type = "hiding", radius = 5000 } )
-- if the position is valid
if ( pos ) then
self:StartActivity( ACT_RUN ) -- run anim
self.loco:SetDesiredSpeed( 200 ) -- run speed
self:PlayScene( "scenes/npc/female01/watchout.vcd" ) -- shout something while we run just for a laugh
self:MoveToPos( pos ) -- move to position (yielding)
self:PlaySequenceAndWait( "fear_reaction" ) -- play a fear animation
self:StartActivity( ACT_IDLE ) -- when we finished, go into the idle anim
else
-- some activity to signify that we didn't find shit
end
coroutine.yield()
end
end
--
-- List the NPC as spawnable
--
list.Set( "NPC", "nb_example", {
Name = "#nb_example",
Class = "nb_example"
} )
if ( CLIENT ) then language.Add( "nb_example", "Example NPC" ) end

View File

@@ -0,0 +1,241 @@
AddCSLuaFile()
SWEP.ViewModel = Model( "models/weapons/c_arms_animations.mdl" )
SWEP.WorldModel = Model( "models/MaxOfS2D/camera.mdl" )
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.PrintName = "#gmod_camera"
SWEP.Author = "Facepunch"
SWEP.Slot = 5
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.Spawnable = true
SWEP.ShootSound = Sound( "NPC_CScanner.TakePhoto" )
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
if ( SERVER ) then
--
-- A concommand to quickly switch to the camera
--
concommand.Add( "gmod_camera", function( ply, cmd, args )
ply:SelectWeapon( "gmod_camera" )
end )
end
--
-- Network/Data Tables
--
function SWEP:SetupDataTables()
self:NetworkVar( "Float", 0, "Zoom" )
self:NetworkVar( "Float", 1, "Roll" )
if ( SERVER ) then
self:SetZoom( 70 )
self:SetRoll( 0 )
end
end
--
-- Initialize Stuff
--
function SWEP:Initialize()
self:SetHoldType( "camera" )
end
--
-- Reload resets the FOV and Roll
--
function SWEP:Reload()
local owner = self:GetOwner()
if ( !owner:KeyDown( IN_ATTACK2 ) ) then self:SetZoom( owner:IsBot() && 75 || owner:GetInfoNum( "fov_desired", 75 ) ) end
self:SetRoll( 0 )
end
--
-- PrimaryAttack - make a screenshot
--
function SWEP:PrimaryAttack()
self:DoShootEffect()
-- If we're multiplayer this can be done totally clientside
if ( !game.SinglePlayer() && SERVER ) then return end
if ( CLIENT && !IsFirstTimePredicted() ) then return end
if ( CLIENT ) then
RunConsoleCommand( "jpeg" )
else
self:GetOwner():SendLua( [[RunConsoleCommand( "jpeg" )]] )
end
end
--
-- SecondaryAttack - Nothing. See Tick for zooming.
--
function SWEP:SecondaryAttack()
end
--
-- Mouse 2 action
--
function SWEP:Tick()
local owner = self:GetOwner()
if ( CLIENT && owner != LocalPlayer() ) then return end -- If someone is spectating a player holding this weapon, bail
local cmd = owner:GetCurrentCommand()
if ( !cmd:KeyDown( IN_ATTACK2 ) ) then return end -- Not holding Mouse 2, bail
self:SetZoom( math.Clamp( self:GetZoom() + cmd:GetMouseY() * FrameTime() * 6.6, 0.1, 175 ) ) -- Handles zooming
self:SetRoll( self:GetRoll() + cmd:GetMouseX() * FrameTime() * 1.65 ) -- Handles rotation
end
--
-- Override players Field Of View
--
function SWEP:TranslateFOV( current_fov )
return self:GetZoom()
end
--
-- Deploy - Allow lastinv
--
function SWEP:Deploy()
return true
end
--
-- Set FOV to players desired FOV
--
function SWEP:Equip()
local owner = self:GetOwner()
if ( self:GetZoom() == 70 && owner:IsPlayer() && !owner:IsBot() ) then
self:SetZoom( owner:GetInfoNum( "fov_desired", 75 ) )
end
end
function SWEP:ShouldDropOnDie() return false end
--
-- The effect when a weapon is fired successfully
--
function SWEP:DoShootEffect()
local owner = self:GetOwner()
self:EmitSound( self.ShootSound )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
owner:SetAnimation( PLAYER_ATTACK1 )
if ( SERVER && !game.SinglePlayer() ) then
--
-- Note that the flash effect is only
-- shown to other players!
--
local vPos = owner:GetShootPos()
local vForward = owner:GetAimVector()
local trace = {}
trace.start = vPos
trace.endpos = vPos + vForward * 256
trace.filter = owner
local tr = util.TraceLine( trace )
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
util.Effect( "camera_flash", effectdata, true )
end
end
if ( SERVER ) then return end -- Only clientside lua after this line
SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_camera" )
-- Don't draw the weapon info on the weapon selection thing
function SWEP:DrawHUD() end
function SWEP:PrintWeaponInfo( x, y, alpha ) end
function SWEP:HUDShouldDraw( name )
-- So we can change weapons
if ( name == "CHudWeaponSelection" ) then return true end
if ( name == "CHudChat" ) then return true end
return false
end
function SWEP:FreezeMovement()
local owner = self:GetOwner()
-- Don't aim if we're holding the right mouse button
if ( owner:KeyDown( IN_ATTACK2 ) || owner:KeyReleased( IN_ATTACK2 ) ) then
return true
end
return false
end
function SWEP:CalcView( ply, origin, angles, fov )
if ( self:GetRoll() != 0 ) then
angles.Roll = self:GetRoll()
end
return origin, angles, fov
end
function SWEP:AdjustMouseSensitivity()
if ( self:GetOwner():KeyDown( IN_ATTACK2 ) ) then return 1 end
return self:GetZoom() / 80
end

View File

@@ -0,0 +1,222 @@
local gmod_drawhelp = CreateClientConVar( "gmod_drawhelp", "1", true, false, "Should the tool HUD be displayed when the tool gun is active?" )
local gmod_toolmode = CreateClientConVar( "gmod_toolmode", "rope", true, true, "Currently selected tool mode for the Tool Gun." )
CreateClientConVar( "gmod_drawtooleffects", "1", true, false, "Should tools draw certain UI elements or effects? (Will not work for all tools)" )
cvars.AddChangeCallback( "gmod_toolmode", function( name, old, new )
if ( old == new ) then return end
spawnmenu.ActivateTool( new, true )
end, "gmod_toolmode_panel" )
include( "shared.lua" )
include( "cl_viewscreen.lua" )
SWEP.Slot = 5
SWEP.SlotPos = 6
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_tool" )
SWEP.Gradient = surface.GetTextureID( "gui/gradient" )
SWEP.InfoIcon = surface.GetTextureID( "gui/info" )
SWEP.ToolNameHeight = 0
SWEP.InfoBoxHeight = 0
surface.CreateFont( "GModToolName", {
font = "Roboto Bk",
size = 80,
weight = 1000,
extended = true
} )
surface.CreateFont( "GModToolSubtitle", {
font = "Roboto Bk",
size = 24,
weight = 1000,
extended = true
} )
surface.CreateFont( "GModToolHelp", {
font = "Roboto Bk",
size = 17,
weight = 1000,
extended = true
} )
--[[---------------------------------------------------------
Draws the help on the HUD (disabled if gmod_drawhelp is 0)
-----------------------------------------------------------]]
function SWEP:DrawHUD()
local mode = gmod_toolmode:GetString()
local toolObject = self:GetToolObject()
-- Don't draw help for a nonexistant tool!
if ( !toolObject ) then return end
-- Do not draw help when in a vehicle unless allowed
if ( LocalPlayer() and IsValid( LocalPlayer():GetVehicle() ) and not LocalPlayer():GetAllowWeaponsInVehicle() ) then return end
toolObject:DrawHUD()
if ( !gmod_drawhelp:GetBool() ) then return end
-- This could probably all suck less than it already does
local x, y = 50, 40
local w, h = 0, 0
local TextTable = {}
local QuadTable = {}
QuadTable.texture = self.Gradient
QuadTable.color = Color( 10, 10, 10, 180 )
QuadTable.x = 0
QuadTable.y = y - 8
QuadTable.w = 600
QuadTable.h = self.ToolNameHeight - ( y - 8 )
draw.TexturedQuad( QuadTable )
TextTable.font = "GModToolName"
TextTable.color = Color( 240, 240, 240, 255 )
TextTable.pos = { x, y }
TextTable.text = "#tool." .. mode .. ".name"
w, h = draw.TextShadow( TextTable, 2 )
y = y + h
TextTable.font = "GModToolSubtitle"
TextTable.pos = { x, y }
TextTable.text = "#tool." .. mode .. ".desc"
w, h = draw.TextShadow( TextTable, 1 )
y = y + h + 8
self.ToolNameHeight = y
QuadTable.y = y
QuadTable.h = self.InfoBoxHeight
local alpha = math.Clamp( 255 + ( toolObject.LastMessage - CurTime() ) * 800, 10, 255 )
QuadTable.color = Color( alpha, alpha, alpha, 230 )
draw.TexturedQuad( QuadTable )
y = y + 4
TextTable.font = "GModToolHelp"
if ( !toolObject.Information ) then
TextTable.pos = { x + self.InfoBoxHeight, y }
TextTable.text = toolObject:GetHelpText()
w, h = draw.TextShadow( TextTable, 1 )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( self.InfoIcon )
surface.DrawTexturedRect( x + 1, y + 1, h - 3, h - 3 )
self.InfoBoxHeight = h + 8
return
end
local h2 = 0
for _, v in pairs( toolObject.Information ) do
if ( isstring( v ) ) then v = { name = v } end
local name = v.name
if ( !name ) then continue end
if ( v.stage && v.stage != self:GetStage() ) then continue end
if ( v.op && v.op != toolObject:GetOperation() ) then continue end
local txt = "#tool." .. mode .. "." .. name
if ( name == "info" ) then txt = toolObject:GetHelpText() end
TextTable.text = txt
TextTable.pos = { x + 21, y + h2 }
w, h = draw.TextShadow( TextTable, 1 )
local icon1 = v.icon
local icon2 = v.icon2
if ( !icon1 ) then
if ( string.StartsWith( name, "info" ) ) then icon1 = "gui/info" end
if ( string.StartsWith( name, "left" ) ) then icon1 = "gui/lmb.png" end
if ( string.StartsWith( name, "right" ) ) then icon1 = "gui/rmb.png" end
if ( string.StartsWith( name, "reload" ) ) then icon1 = "gui/r.png" end
if ( string.StartsWith( name, "use" ) ) then icon1 = "gui/e.png" end
end
if ( !icon2 && !string.StartsWith( name, "use" ) && string.EndsWith( name, "use" ) ) then icon2 = "gui/e.png" end
self.Icons = self.Icons or {}
if ( icon1 && !self.Icons[ icon1 ] ) then self.Icons[ icon1 ] = Material( icon1 ) end
if ( icon2 && !self.Icons[ icon2 ] ) then self.Icons[ icon2 ] = Material( icon2 ) end
if ( icon1 && self.Icons[ icon1 ] && !self.Icons[ icon1 ]:IsError() ) then
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( self.Icons[ icon1 ] )
surface.DrawTexturedRect( x, y + h2, 16, 16 )
end
if ( icon2 && self.Icons[ icon2 ] && !self.Icons[ icon2 ]:IsError() ) then
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( self.Icons[ icon2 ] )
surface.DrawTexturedRect( x - 25, y + h2, 16, 16 )
draw.SimpleText( "+", "default", x - 8, y + h2 + 2, color_white )
end
h2 = h2 + h
end
self.InfoBoxHeight = h2 + 8
end
function SWEP:SetStage( ... )
if ( !self:GetToolObject() ) then return end
return self:GetToolObject():SetStage( ... )
end
function SWEP:GetStage( ... )
if ( !self:GetToolObject() ) then return end
return self:GetToolObject():GetStage( ... )
end
function SWEP:ClearObjects( ... )
if ( !self:GetToolObject() ) then return end
self:GetToolObject():ClearObjects( ... )
end
function SWEP:StartGhostEntities( ... )
if ( !self:GetToolObject() ) then return end
self:GetToolObject():StartGhostEntities( ... )
end
function SWEP:PrintWeaponInfo( x, y, alpha )
end
function SWEP:FreezeMovement()
if ( !self:GetToolObject() ) then return false end
return self:GetToolObject():FreezeMovement()
end
function SWEP:OnReloaded()
-- TODO: Reload the tool control panels
-- controlpanel.Clear()
end

View File

@@ -0,0 +1,74 @@
local matScreen = Material( "models/weapons/v_toolgun/screen" )
local txBackground = surface.GetTextureID( "models/weapons/v_toolgun/screen_bg" )
local toolmode = GetConVar( "gmod_toolmode" )
local TEX_SIZE = 256
-- GetRenderTarget returns the texture if it exists, or creates it if it doesn't
local RTTexture = GetRenderTarget( "GModToolgunScreen", TEX_SIZE, TEX_SIZE )
surface.CreateFont( "GModToolScreen", {
font = "Helvetica",
size = 60,
weight = 900
} )
local function DrawScrollingText( text, y, texwide )
local w, h = surface.GetTextSize( text )
w = w + 64
y = y - h / 2 -- Center text to y position
local x = RealTime() * 250 % w * -1
while ( x < texwide ) do
surface.SetTextColor( 0, 0, 0, 255 )
surface.SetTextPos( x + 3, y + 3 )
surface.DrawText( text )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( x, y )
surface.DrawText( text )
x = x + w
end
end
--[[---------------------------------------------------------
We use this opportunity to draw to the toolmode
screen's rendertarget texture.
-----------------------------------------------------------]]
function SWEP:RenderScreen()
-- Set the material of the screen to our render target
matScreen:SetTexture( "$basetexture", RTTexture )
-- Set up our view for drawing to the texture
render.PushRenderTarget( RTTexture )
cam.Start2D()
-- Background
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( txBackground )
surface.DrawTexturedRect( 0, 0, TEX_SIZE, TEX_SIZE )
-- Give our toolmode the opportunity to override the drawing
if ( self:GetToolObject() && self:GetToolObject().DrawToolScreen ) then
self:GetToolObject():DrawToolScreen( TEX_SIZE, TEX_SIZE )
else
surface.SetFont( "GModToolScreen" )
DrawScrollingText( "#tool." .. toolmode:GetString() .. ".name", 104, TEX_SIZE )
end
cam.End2D()
render.PopRenderTarget()
end

View File

@@ -0,0 +1,131 @@
--[[---------------------------------------------------------
Starts up the ghost entity
The most important part of this is making sure it gets deleted properly
-----------------------------------------------------------]]
function ToolObj:MakeGhostEntity( model, pos, angle )
util.PrecacheModel( model )
-- We do ghosting serverside in single player
-- It's done clientside in multiplayer
if ( SERVER && !game.SinglePlayer() ) then return end
if ( CLIENT && game.SinglePlayer() ) then return end
-- The reason we need this is because in multiplayer, when you holster a tool serverside,
-- either by using the spawnnmenu's Weapons tab or by simply entering a vehicle,
-- the Think hook is called once after Holster is called on the client, recreating the ghost entity right after it was removed.
if ( !IsFirstTimePredicted() ) then return end
-- Release the old ghost entity
self:ReleaseGhostEntity()
-- Don't allow ragdolls/effects to be ghosts
if ( !util.IsValidProp( model ) ) then return end
if ( CLIENT ) then
self.GhostEntity = ents.CreateClientProp( model )
else
self.GhostEntity = ents.Create( "prop_physics" )
end
-- If there's too many entities we might not spawn..
if ( !IsValid( self.GhostEntity ) ) then
self.GhostEntity = nil
return
end
self.GhostEntity:SetModel( model )
self.GhostEntity:SetPos( pos )
self.GhostEntity:SetAngles( angle )
self.GhostEntity:Spawn()
-- We do not want physics at all
self.GhostEntity:PhysicsDestroy()
-- SOLID_NONE causes issues with Entity.NearestPoint used by Wheel tool
--self.GhostEntity:SetSolid( SOLID_NONE )
self.GhostEntity:SetMoveType( MOVETYPE_NONE )
self.GhostEntity:SetNotSolid( true )
self.GhostEntity:SetRenderMode( RENDERMODE_TRANSCOLOR )
self.GhostEntity:SetColor( Color( 255, 255, 255, 150 ) )
-- Do not save this thing in saves/dupes
self.GhostEntity.DoNotDuplicate = true
-- Mark this entity as ghost prop for other code
self.GhostEntity.IsToolGhost = true
end
--[[---------------------------------------------------------
Starts up the ghost entity
The most important part of this is making sure it gets deleted properly
-----------------------------------------------------------]]
function ToolObj:StartGhostEntity( ent )
-- We do ghosting serverside in single player
-- It's done clientside in multiplayer
if ( SERVER && !game.SinglePlayer() ) then return end
if ( CLIENT && game.SinglePlayer() ) then return end
self:MakeGhostEntity( ent:GetModel(), ent:GetPos(), ent:GetAngles() )
end
--[[---------------------------------------------------------
Releases up the ghost entity
-----------------------------------------------------------]]
function ToolObj:ReleaseGhostEntity()
if ( self.GhostEntity ) then
if ( !IsValid( self.GhostEntity ) ) then self.GhostEntity = nil return end
self.GhostEntity:Remove()
self.GhostEntity = nil
end
-- This is unused!
if ( self.GhostEntities ) then
for k, v in pairs( self.GhostEntities ) do
if ( IsValid( v ) ) then v:Remove() end
self.GhostEntities[ k ] = nil
end
self.GhostEntities = nil
end
-- This is unused!
if ( self.GhostOffset ) then
for k, v in pairs( self.GhostOffset ) do
self.GhostOffset[ k ] = nil
end
end
end
--[[---------------------------------------------------------
Update the ghost entity
-----------------------------------------------------------]]
function ToolObj:UpdateGhostEntity()
if ( self.GhostEntity == nil ) then return end
if ( !IsValid( self.GhostEntity ) ) then self.GhostEntity = nil return end
local trace = self:GetOwner():GetEyeTrace()
if ( !trace.Hit ) then return end
local Ang1, Ang2 = self:GetNormal( 1 ):Angle(), ( trace.HitNormal * -1 ):Angle()
local TargetAngle = self:GetEnt( 1 ):AlignAngles( Ang1, Ang2 )
self.GhostEntity:SetPos( self:GetEnt( 1 ):GetPos() )
self.GhostEntity:SetAngles( TargetAngle )
local TranslatedPos = self.GhostEntity:LocalToWorld( self:GetLocalPos( 1 ) )
local TargetPos = trace.HitPos + ( self:GetEnt( 1 ):GetPos() - TranslatedPos ) + trace.HitNormal
self.GhostEntity:SetPos( TargetPos )
end

View File

@@ -0,0 +1,35 @@
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "ghostentity.lua" )
AddCSLuaFile( "object.lua" )
AddCSLuaFile( "stool.lua" )
AddCSLuaFile( "cl_viewscreen.lua" )
AddCSLuaFile( "stool_cl.lua" )
include( "shared.lua" )
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
-- Should this weapon be dropped when its owner dies?
function SWEP:ShouldDropOnDie()
return false
end
-- Console Command to switch weapon/toolmode
local function CC_GMOD_Tool( ply, command, arguments )
local targetMode = arguments[1]
if ( targetMode == nil ) then return end
if ( GetConVarNumber( "toolmode_allow_" .. targetMode ) != 1 ) then return end
ply:ConCommand( "gmod_toolmode " .. targetMode )
-- Switch weapons
ply:SelectWeapon( "gmod_tool" )
end
concommand.Add( "gmod_tool", CC_GMOD_Tool, nil, nil, { FCVAR_SERVER_CAN_EXECUTE } )

View File

@@ -0,0 +1,165 @@
function ToolObj:UpdateData()
self:SetStage( self:NumObjects() )
end
function ToolObj:SetStage( i )
if ( SERVER ) then
self:GetWeapon():SetNWInt( "Stage", i )
end
end
function ToolObj:GetStage()
return self:GetWeapon():GetNWInt( "Stage", 0 )
end
function ToolObj:SetOperation( i )
if ( SERVER ) then
self:GetWeapon():SetNWInt( "Op", i )
end
end
function ToolObj:GetOperation()
return self:GetWeapon():GetNWInt( "Op", 0 )
end
-- Clear the selected objects
function ToolObj:ClearObjects()
self:ReleaseGhostEntity()
self.Objects = {}
self:SetStage( 0 )
self:SetOperation( 0 )
end
--[[---------------------------------------------------------
Since we're going to be expanding this a lot I've tried
to add accessors for all of this crap to make it harder
for us to mess everything up.
-----------------------------------------------------------]]
function ToolObj:GetEnt( i )
if ( !self.Objects[i] ) then return NULL end
return self.Objects[i].Ent
end
--[[---------------------------------------------------------
Returns the world position of the numbered object hit
We store it as a local vector then convert it to world
That way even if the object moves it's still valid
-----------------------------------------------------------]]
function ToolObj:GetPos( i )
if ( self.Objects[i].Ent:EntIndex() == 0 ) then
return self.Objects[i].Pos
else
if ( IsValid( self.Objects[i].Phys ) ) then
return self.Objects[i].Phys:LocalToWorld( self.Objects[i].Pos )
else
return self.Objects[i].Ent:LocalToWorld( self.Objects[i].Pos )
end
end
end
-- Returns the local position of the numbered hit
function ToolObj:GetLocalPos( i )
return self.Objects[i].Pos
end
-- Returns the physics bone number of the hit (ragdolls)
function ToolObj:GetBone( i )
return self.Objects[i].Bone
end
function ToolObj:GetNormal( i )
if ( self.Objects[i].Ent:EntIndex() == 0 ) then
return self.Objects[i].Normal
else
local norm
if ( IsValid( self.Objects[i].Phys ) ) then
norm = self.Objects[i].Phys:LocalToWorld( self.Objects[i].Normal )
else
norm = self.Objects[i].Ent:LocalToWorld( self.Objects[i].Normal )
end
return norm - self:GetPos( i )
end
end
-- Returns the physics object for the numbered hit
function ToolObj:GetPhys( i )
if ( self.Objects[i].Phys == nil ) then
return self:GetEnt( i ):GetPhysicsObject()
end
return self.Objects[i].Phys
end
-- Sets a selected object
function ToolObj:SetObject( i, ent, pos, phys, bone, norm )
self.Objects[i] = {}
self.Objects[i].Ent = ent
self.Objects[i].Phys = phys
self.Objects[i].Bone = bone
self.Objects[i].Normal = norm
-- Worldspawn is a special case
if ( ent:EntIndex() == 0 ) then
self.Objects[i].Phys = nil
self.Objects[i].Pos = pos
else
norm = norm + pos
-- Convert the position to a local position - so it's still valid when the object moves
if ( IsValid( phys ) ) then
self.Objects[i].Normal = self.Objects[i].Phys:WorldToLocal( norm )
self.Objects[i].Pos = self.Objects[i].Phys:WorldToLocal( pos )
else
self.Objects[i].Normal = self.Objects[i].Ent:WorldToLocal( norm )
self.Objects[i].Pos = self.Objects[i].Ent:WorldToLocal( pos )
end
end
-- TODO: Make sure the client got the same info
end
-- Returns the number of objects in the list
function ToolObj:NumObjects()
if ( CLIENT ) then
return self:GetStage()
end
return #self.Objects
end
-- Returns the number of objects in the list
function ToolObj:GetHelpText()
return "#tool." .. GetConVarString( "gmod_toolmode" ) .. "." .. self:GetStage()
end

View File

@@ -0,0 +1,383 @@
-- Variables that are used on both client and server
SWEP.PrintName = "#gmod_tool"
SWEP.Author = "Facepunch"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.ViewModel = "models/weapons/c_toolgun.mdl"
SWEP.WorldModel = "models/weapons/w_toolgun.mdl"
SWEP.UseHands = true
SWEP.Spawnable = true
-- Be nice, precache the models
util.PrecacheModel( SWEP.ViewModel )
util.PrecacheModel( SWEP.WorldModel )
SWEP.ShootSound = Sound( "Airboat.FireGunRevDown" )
SWEP.Tool = {}
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.CanHolster = true
SWEP.CanDeploy = true
function SWEP:InitializeTools()
local owner = self:GetOwner()
local temp = {}
for k, v in pairs( self.Tool ) do
-- This is from saverestore.LoadEntity..
if ( !v.Init ) then continue end
temp[k] = table.Copy( v )
temp[k].SWEP = self
temp[k].Owner = owner
temp[k].Weapon = self
temp[k]:Init()
end
self.Tool = temp
end
function SWEP:SetupDataTables()
self:NetworkVar( "Entity", 0, "TargetEntity1" )
self:NetworkVar( "Entity", 1, "TargetEntity2" )
self:NetworkVar( "Entity", 2, "TargetEntity3" )
self:NetworkVar( "Entity", 3, "TargetEntity4" )
end
-- Convenience function to check object limits
function SWEP:CheckLimit( str )
return self:GetOwner():CheckLimit( str )
end
function SWEP:Initialize()
self:SetHoldType( "revolver" )
self:InitializeTools()
-- We create these here. The problem is that these are meant to be constant values.
-- in the toolmode they're not because some tools can be automatic while some tools aren't.
-- Since this is a global table it's shared between all instances of the gun.
-- By creating new tables here we're making it so each tool has its own instance of the table
-- So changing it won't affect the other tools.
self.Primary = {
ClipSize = -1,
DefaultClip = -1,
Automatic = false,
Ammo = "none"
}
self.Secondary = {
ClipSize = -1,
DefaultClip = -1,
Automatic = false,
Ammo = "none"
}
end
function SWEP:OnRestore()
self:InitializeTools()
end
function SWEP:Precache()
util.PrecacheSound( self.ShootSound )
end
-- Returns the mode we're in
function SWEP:GetMode()
return self.Mode
end
-- Think does stuff every frame
function SWEP:Think()
-- SWEP:Think is called one more time clientside
-- after holstering using Player:SelectWeapon in multiplayer
if ( CLIENT and self.m_uHolsterFrame == FrameNumber() ) then return end
local owner = self:GetOwner()
if ( !owner:IsPlayer() ) then return end
local curmode = owner:GetInfo( "gmod_toolmode" )
self.Mode = curmode
local tool = self:GetToolObject( curmode )
if ( !tool ) then return end
tool:CheckObjects()
local lastmode = self.current_mode
self.last_mode = lastmode
self.current_mode = curmode
-- Release ghost entities if we're not allowed to use this new mode?
if ( !tool:Allowed() ) then
if ( lastmode ) then
local lastmode_obj = self:GetToolObject( lastmode )
if ( lastmode_obj ) then
lastmode_obj:ReleaseGhostEntity() -- In case tool overwrites the default Holster
lastmode_obj:Holster( true )
end
end
return
end
if ( lastmode and lastmode ~= curmode ) then
local lastmode_obj = self:GetToolObject( lastmode )
if ( lastmode_obj ) then
-- We want to release the ghost entity just in case
lastmode_obj:ReleaseGhostEntity()
lastmode_obj:Holster( true )
end
-- Deploy the new tool
tool:Deploy( true )
end
self.Primary.Automatic = tool.LeftClickAutomatic or false
self.Secondary.Automatic = tool.RightClickAutomatic or false
self.RequiresTraceHit = tool.RequiresTraceHit or true
tool:Think()
end
-- The shoot effect
function SWEP:DoShootEffect( hitpos, hitnormal, entity, physbone, bFirstTimePredicted )
local owner = self:GetOwner()
self:EmitSound( self.ShootSound )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) -- View model animation
-- There's a bug with the model that's causing a muzzle to
-- appear on everyone's screen when we fire this animation.
owner:SetAnimation( PLAYER_ATTACK1 ) -- 3rd Person Animation
if ( !bFirstTimePredicted ) then return end
if ( GetConVarNumber( "gmod_drawtooleffects" ) == 0 ) then return end
local effectdata = EffectData()
effectdata:SetOrigin( hitpos )
effectdata:SetNormal( hitnormal )
effectdata:SetEntity( entity )
effectdata:SetAttachment( physbone )
util.Effect( "selection_indicator", effectdata )
local effect_tr = EffectData()
effect_tr:SetOrigin( hitpos )
effect_tr:SetStart( owner:GetShootPos() )
effect_tr:SetAttachment( 1 )
effect_tr:SetEntity( self )
util.Effect( "ToolTracer", effect_tr )
end
local toolMask = bit.bor( CONTENTS_SOLID, CONTENTS_MOVEABLE, CONTENTS_MONSTER, CONTENTS_WINDOW, CONTENTS_DEBRIS, CONTENTS_GRATE, CONTENTS_AUX )
function SWEP:DoToolTrace()
local owner = self:GetOwner()
local tr = util.GetPlayerTrace( owner )
tr.mask = toolMask
tr.mins = vector_origin
tr.maxs = tr.mins
tr.filter = { owner, owner:GetVehicle() }
local trace = util.TraceLine( tr )
if ( !trace.Hit ) then trace = util.TraceHull( tr ) end
if ( !trace.Hit ) then return end
return trace
end
-- Trace a line then send the result to a mode function
function SWEP:PrimaryAttack()
local trace = self:DoToolTrace()
if ( !trace ) then return end
local tool = self:GetToolObject()
if ( !tool ) then return end
tool:CheckObjects()
-- Does the server setting say it's ok?
if ( !tool:Allowed() ) then return end
-- Ask the gamemode if it's ok to do this
local mode = self:GetMode()
if ( !gamemode.Call( "CanTool", self:GetOwner(), trace, mode, tool, 1 ) ) then return end
if ( !tool:LeftClick( trace ) ) then return end
self:DoShootEffect( trace.HitPos, trace.HitNormal, trace.Entity, trace.PhysicsBone, IsFirstTimePredicted() )
end
function SWEP:SecondaryAttack()
local trace = self:DoToolTrace()
if ( !trace ) then return end
local tool = self:GetToolObject()
if ( !tool ) then return end
tool:CheckObjects()
-- Does the server setting say it's ok?
if ( !tool:Allowed() ) then return end
-- Ask the gamemode if it's ok to do this
local mode = self:GetMode()
if ( !gamemode.Call( "CanTool", self:GetOwner(), trace, mode, tool, 2 ) ) then return end
if ( !tool:RightClick( trace ) ) then return end
self:DoShootEffect( trace.HitPos, trace.HitNormal, trace.Entity, trace.PhysicsBone, IsFirstTimePredicted() )
end
function SWEP:Reload()
local owner = self:GetOwner()
-- This makes the reload a semi-automatic thing rather than a continuous thing
if ( !owner:KeyPressed( IN_RELOAD ) ) then return end
local trace = self:DoToolTrace()
if ( !trace ) then return end
local tool = self:GetToolObject()
if ( !tool ) then return end
tool:CheckObjects()
-- Does the server setting say it's ok?
if ( !tool:Allowed() ) then return end
-- Ask the gamemode if it's ok to do this
local mode = self:GetMode()
if ( !gamemode.Call( "CanTool", owner, trace, mode, tool, 3 ) ) then return end
if ( !tool:Reload( trace ) ) then return end
self:DoShootEffect( trace.HitPos, trace.HitNormal, trace.Entity, trace.PhysicsBone, IsFirstTimePredicted() )
end
function SWEP:Holster()
local toolobj = self:GetToolObject()
local CanHolster
if ( toolobj ) then
CanHolster = toolobj:Holster()
if ( CanHolster == nil ) then CanHolster = self.CanHolster end
else
-- Just do what the SWEP wants to do if there's no tool
CanHolster = self.CanHolster
end
-- Save the frame the weapon was holstered on to prevent
-- the extra Think call after calling Player:SelectWeapon in multiplayer
if ( CLIENT and CanHolster == true ) then self.m_uHolsterFrame = FrameNumber() end
if ( CanHolster == true and toolobj ) then toolobj:ReleaseGhostEntity() end
return CanHolster
end
-- Delete ghosts here in case the weapon gets deleted all of a sudden somehow
function SWEP:OnRemove()
if ( !self:GetToolObject() ) then return end
self:GetToolObject():ReleaseGhostEntity()
end
-- This will remove any ghosts when a player dies and drops the weapon
function SWEP:OwnerChanged()
if ( !self:GetToolObject() ) then return end
self:GetToolObject():ReleaseGhostEntity()
end
-- Deploy
function SWEP:Deploy()
-- Just do what the SWEP wants to do if there is no tool
if ( !self:GetToolObject() ) then return self.CanDeploy end
self:GetToolObject():UpdateData()
local CanDeploy = self:GetToolObject():Deploy()
if ( CanDeploy ~= nil ) then return CanDeploy end
return self.CanDeploy
end
function SWEP:GetToolObject( tool )
local mode = tool or self:GetMode()
if ( !mode ) then
local owner = self:GetOwner()
if ( IsValid( owner ) and owner:IsPlayer() and ( SERVER or owner == LocalPlayer() ) ) then
mode = owner:GetInfo( "gmod_toolmode" )
end
end
if ( !self.Tool[ mode ] ) then return false end
return self.Tool[ mode ]
end
function SWEP:FireAnimationEvent( pos, ang, event, options )
-- Disables animation based muzzle event
if ( event == 21 ) then return true end
-- Disable thirdperson muzzle flash
if ( event == 5003 ) then return true end
end
include( "stool.lua" )

View File

@@ -0,0 +1,264 @@
ToolObj = {}
include( "ghostentity.lua" )
include( "object.lua" )
if ( CLIENT ) then
include( "stool_cl.lua" )
end
function ToolObj:Create()
local o = {}
setmetatable( o, self )
self.__index = self
o.Mode = nil
o.SWEP = nil
o.Owner = nil
o.ClientConVar = {}
o.ServerConVar = {}
o.Objects = {}
o.Stage = 0
o.Message = "start"
o.LastMessage = 0
o.AllowedCVar = 0
return o
end
function ToolObj:CreateConVars()
local mode = self:GetMode()
self.AllowedCVar = CreateConVar( "toolmode_allow_" .. mode, "1", { FCVAR_NOTIFY, FCVAR_REPLICATED }, "Set to 0 to disallow players being able to use the \"" .. mode .. "\" tool." )
self.ClientConVars = {}
self.ServerConVars = {}
if ( CLIENT ) then
for cvar, default in pairs( self.ClientConVar ) do
self.ClientConVars[ cvar ] = CreateClientConVar( mode .. "_" .. cvar, default, true, true, "Tool specific client setting (" .. mode .. ")" )
end
else
for cvar, default in pairs( self.ServerConVar ) do
self.ServerConVars[ cvar ] = CreateConVar( mode .. "_" .. cvar, default, FCVAR_ARCHIVE, "Tool specific server setting (" .. mode .. ")" )
end
end
end
function ToolObj:GetServerInfo( property )
if ( self.ServerConVars[ property ] and SERVER ) then
return self.ServerConVars[ property ]:GetString()
end
return GetConVarString( self:GetMode() .. "_" .. property )
end
function ToolObj:GetClientInfo( property )
if ( self.ClientConVars[ property ] and CLIENT ) then
return self.ClientConVars[ property ]:GetString()
end
return self:GetOwner():GetInfo( self:GetMode() .. "_" .. property )
end
function ToolObj:GetClientNumber( property, default )
if ( self.ClientConVars[ property ] and CLIENT ) then
return self.ClientConVars[ property ]:GetFloat()
end
return self:GetOwner():GetInfoNum( self:GetMode() .. "_" .. property, tonumber( default ) or 0 )
end
function ToolObj:GetClientBool( property, default )
if ( self.ClientConVars[ property ] and CLIENT ) then
return self.ClientConVars[ property ]:GetBool()
end
return math.floor( self:GetOwner():GetInfoNum( self:GetMode() .. "_" .. property, tonumber( default ) or 0 ) ) != 0
end
function ToolObj:BuildConVarList()
local mode = self:GetMode()
local convars = {}
for k, v in pairs( self.ClientConVar ) do convars[ mode .. "_" .. k ] = v end
return convars
end
function ToolObj:Allowed()
return self.AllowedCVar:GetBool()
end
-- Now for all the ToolObj redirects
function ToolObj:Init() end
function ToolObj:GetMode() return self.Mode end
function ToolObj:GetWeapon() return self.SWEP end
function ToolObj:GetOwner() return self:GetWeapon():GetOwner() or self.Owner end
function ToolObj:GetSWEP() return self:GetWeapon() end
function ToolObj:LeftClick() return false end
function ToolObj:RightClick() return false end
function ToolObj:Reload() self:ClearObjects() end
function ToolObj:Deploy() self:ReleaseGhostEntity() return end
function ToolObj:Holster() self:ReleaseGhostEntity() return end
function ToolObj:Think() self:ReleaseGhostEntity() end
--[[---------------------------------------------------------
Checks the objects before any action is taken
This is to make sure that the entities haven't been removed
-----------------------------------------------------------]]
function ToolObj:CheckObjects()
for k, v in pairs( self.Objects ) do
if ( !v.Ent:IsWorld() and !v.Ent:IsValid() ) then
self:ClearObjects()
end
end
end
for _, val in ipairs( file.Find( SWEP.Folder .. "/stools/*.lua", "LUA" ) ) do
local _, _, toolmode = string.find( val, "([%w_]*).lua" )
-- In multiplayer, the clientside filename is always lowercase (due to the Lua datapack)
-- So ensure that the toolmode matches between client and server,
-- when the serverside name is not all lowercase
toolmode = toolmode:lower()
TOOL = ToolObj:Create()
TOOL.Mode = toolmode
AddCSLuaFile( "stools/" .. val )
include( "stools/" .. val )
TOOL:CreateConVars()
if ( hook.Run( "PreRegisterTOOL", TOOL, toolmode ) != false ) then
SWEP.Tool[ toolmode ] = TOOL
end
TOOL = nil
end
ToolObj = nil
if ( SERVER ) then return end
-- Keep the tool list handy
local TOOLS_LIST = SWEP.Tool
-- Add the STOOLS to the tool menu
hook.Add( "PopulateToolMenu", "AddSToolsToMenu", function()
for ToolName, tool in pairs( TOOLS_LIST ) do
if ( tool.AddToMenu != false ) then
spawnmenu.AddToolMenuOption(
tool.Tab or "Main",
tool.Category or "New Category",
ToolName,
tool.Name or ( "#" .. ToolName ),
tool.Command or ( "gmod_tool " .. ToolName ),
tool.ConfigName or ToolName,
tool.BuildCPanel
)
end
end
end )
--
-- Search
--
search.AddProvider( function( str )
local list = {}
for k, v in pairs( TOOLS_LIST ) do
local niceName = v.Name or ( "#" .. k )
if ( niceName:StartsWith( "#" ) ) then niceName = language.GetPhrase( niceName:sub( 2 ) ) end
if ( !k:lower():find( str, nil, true ) and !niceName:lower():find( str, nil, true ) ) then continue end
local entry = {
text = niceName,
icon = spawnmenu.CreateContentIcon( "tool", nil, {
spawnname = k,
nicename = v.Name or ( "#" .. k )
} ),
words = { k }
}
table.insert( list, entry )
if ( #list >= GetConVarNumber( "sbox_search_maxresults" ) / 32 ) then break end
end
return list
end )
--
-- Tool spawnmenu icon
--
spawnmenu.AddContentType( "tool", function( container, obj )
if ( !obj.spawnname ) then return end
local icon = vgui.Create( "ContentIcon", container )
icon:SetContentType( "tool" )
icon:SetSpawnName( obj.spawnname )
icon:SetName( obj.nicename or ( "#tool." .. obj.spawnname .. ".name" ) )
icon:SetMaterial( "gui/tool.png" )
icon.DoClick = function()
spawnmenu.ActivateTool( obj.spawnname )
surface.PlaySound( "ui/buttonclickrelease.wav" )
end
icon.OpenMenu = icon.OpenGenericSpawnmenuRightClickMenu
if ( IsValid( container ) ) then
container:Add( icon )
end
return icon
end )

View File

@@ -0,0 +1,20 @@
-- Tool should return true if freezing the view angles
function ToolObj:FreezeMovement()
return false
end
-- The tool's opportunity to draw to the HUD
function ToolObj:DrawHUD()
end
-- Force rebuild the Control Panel
function ToolObj:RebuildControlPanel( ... )
local cPanel = controlpanel.Get( self.Mode )
if ( !cPanel ) then ErrorNoHalt( "Couldn't find control panel to rebuild!" ) return end
cPanel:Clear()
self.BuildCPanel( cPanel, ... )
end

View File

@@ -0,0 +1,239 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.axis.name"
TOOL.ClientConVar[ "forcelimit" ] = 0
TOOL.ClientConVar[ "torquelimit" ] = 0
TOOL.ClientConVar[ "hingefriction" ] = 0
TOOL.ClientConVar[ "nocollide" ] = 0
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1, op = 1 },
{ name = "right", stage = 0 },
{ name = "right_1", stage = 1, op = 2 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( self:GetOperation() == 2 ) then return false end
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- todo: Don't attempt to constrain the first object if it's already constrained to a static object
local iNum = self:NumObjects()
-- Don't allow us to choose the world as the first object
if ( iNum == 0 && !IsValid( trace.Entity ) ) then return false end
-- Don't do jeeps (crash protection until we get it fixed)
if ( iNum == 0 && trace.Entity:GetClass() == "prop_vehicle_jeep" ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
self:SetOperation( 1 )
if ( iNum > 0 ) then
-- Clientside can bail out now
if ( CLIENT ) then
self:ClearObjects()
self:ReleaseGhostEntity()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "constraints" ) ) then
self:ClearObjects()
self:ReleaseGhostEntity()
return false
end
-- Get client's CVars
local nocollide = self:GetClientNumber( "nocollide", 0 )
local forcelimit = self:GetClientNumber( "forcelimit", 0 )
local torquelimit = self:GetClientNumber( "torquelimit", 0 )
local friction = self:GetClientNumber( "hingefriction", 0 )
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local Norm1, Norm2 = self:GetNormal( 1 ), self:GetNormal( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local Phys1 = self:GetPhys( 1 )
local WPos2 = self:GetPos( 2 )
-- Note: To keep stuff ragdoll friendly try to treat things as physics objects rather than entities
local Ang1, Ang2 = Norm1:Angle(), ( -Norm2 ):Angle()
local TargetAngle = Phys1:AlignAngles( Ang1, Ang2 )
Phys1:SetAngles( TargetAngle )
-- Move the object so that the hitpos on our object is at the second hitpos
local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) ) + ( Norm2 * 0.2 )
-- Set the position
Phys1:SetPos( TargetPos )
-- Wake up the physics object so that the entity updates
Phys1:Wake()
-- Set the hinge Axis perpendicular to the trace hit surface
LPos1 = Phys1:WorldToLocal( WPos2 + Norm2 )
-- Create a constraint axis
local constr = constraint.Axis( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, forcelimit, torquelimit, friction, nocollide )
if ( IsValid( constr ) ) then
undo.Create( "Axis" )
undo.AddEntity( constr )
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.axis.name" )
undo.Finish( "#tool.axis.name" )
ply:AddCount( "constraints", constr )
ply:AddCleanup( "constraints", constr )
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
self:ReleaseGhostEntity()
else
self:StartGhostEntity( trace.Entity )
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:RightClick( trace )
if ( self:GetOperation() == 1 ) then return false end
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
local iNum = self:NumObjects()
-- Don't allow us to choose the world as the first object
if ( iNum == 0 && !IsValid( trace.Entity ) ) then return false end
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
self:SetOperation( 2 )
if ( iNum > 0 ) then
-- Clientside can bail out now
local ply = self:GetOwner()
if ( CLIENT ) then
self:ClearObjects()
return true
end
if ( !ply:CheckLimit( "constraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local nocollide = self:GetClientNumber( "nocollide", 0 )
local forcelimit = self:GetClientNumber( "forcelimit", 0 )
local torquelimit = self:GetClientNumber( "torquelimit", 0 )
local friction = self:GetClientNumber( "hingefriction", 0 )
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local Norm1, Norm2 = self:GetNormal( 1 ), self:GetNormal( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local Phys1 = self:GetPhys( 1 )
local WPos2 = self:GetPos( 2 )
-- Note: To keep stuff ragdoll friendly try to treat things as physics objects rather than entities
--local Ang1, Ang2 = Norm1:Angle(), ( -Norm2 ):Angle()
--local TargetAngle = Phys1:AlignAngles( Ang1, Ang2 )
--Phys1:SetAngles( TargetAngle )
Phys1:Wake()
-- Set the hinge Axis perpendicular to the trace hit surface
LPos1 = Phys1:WorldToLocal( WPos2 + Norm2 )
local constr = constraint.Axis( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, forcelimit, torquelimit, friction, nocollide )
if ( IsValid( constr ) ) then
undo.Create( "Axis" )
undo.AddEntity( constr )
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.axis.name" )
undo.Finish( "#tool.axis.name" )
ply:AddCount( "constraints", constr )
ply:AddCleanup( "constraints", constr )
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
self:ReleaseGhostEntity()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Axis" )
end
function TOOL:Think()
if ( self:NumObjects() != 1 ) then return end
self:UpdateGhostEntity()
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.axis.help" )
CPanel:ToolPresets( "axis", ConVarsDefault )
CPanel:NumSlider( "#tool.forcelimit", "axis_forcelimit", 0, 50000 )
CPanel:ControlHelp( "#tool.forcelimit.help" )
CPanel:NumSlider( "#tool.torquelimit", "axis_torquelimit", 0, 50000 )
CPanel:ControlHelp( "#tool.torquelimit.help" )
CPanel:NumSlider( "#tool.hingefriction", "axis_hingefriction", 0, 200 )
CPanel:ControlHelp( "#tool.hingefriction.help" )
CPanel:CheckBox( "#tool.nocollide", "axis_nocollide" )
CPanel:ControlHelp( "#tool.nocollide.help" )
end

View File

@@ -0,0 +1,247 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.balloon.name"
TOOL.ClientConVar[ "ropelength" ] = "64"
TOOL.ClientConVar[ "force" ] = "500"
TOOL.ClientConVar[ "r" ] = "255"
TOOL.ClientConVar[ "g" ] = "255"
TOOL.ClientConVar[ "b" ] = "0"
TOOL.ClientConVar[ "model" ] = "normal_skin1"
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
cleanup.Register( "balloons" )
function TOOL:LeftClick( trace, attach )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
--
-- Right click calls this with attach = false
--
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 material = "cable/rope"
local r = self:GetClientNumber( "r", 255 )
local g = self:GetClientNumber( "g", 0 )
local b = self:GetClientNumber( "b", 0 )
local model = self:GetClientInfo( "model" )
local force = math.Clamp( self:GetClientNumber( "force", 500 ), -1E34, 1E34 )
local length = self:GetClientNumber( "ropelength", 64 )
--
-- Model is a table index on BalloonModels
-- If the model isn't defined then it can't be spawned.
--
local modeltable = list.GetEntry( "BalloonModels", model )
if ( !modeltable ) then return false end
--
-- The model table can disable colouring for its model
--
if ( modeltable.nocolor ) then
r = 255
g = 255
b = 255
end
--
-- Clicked on a balloon - modify the force/color/whatever
--
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_balloon" && trace.Entity.Player == ply ) then
if ( IsValid( trace.Entity:GetPhysicsObject() ) ) then trace.Entity:GetPhysicsObject():Wake() end
trace.Entity:SetColor( Color( r, g, b, 255 ) )
trace.Entity:SetForce( force )
trace.Entity.force = force
return true
end
--
-- Hit the balloon limit, bail
--
if ( !self:GetWeapon():CheckLimit( "balloons" ) ) then return false end
local balloon = MakeBalloon( ply, r, g, b, force, { Pos = trace.HitPos, Model = modeltable.model, Skin = modeltable.skin } )
if ( !IsValid( balloon ) ) then return false end
local CurPos = balloon:GetPos()
local NearestPoint = balloon:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local Offset = CurPos - NearestPoint
local Pos = trace.HitPos + Offset
balloon:SetPos( Pos )
undo.Create( "gmod_balloon" )
undo.AddEntity( balloon )
if ( attach ) then
-- The real model should have an attachment!
local LPos1 = balloon:WorldToLocal( Pos )
local LPos2 = trace.Entity:WorldToLocal( trace.HitPos )
if ( IsValid( trace.Entity ) ) then
local phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
if ( IsValid( phys ) ) then LPos2 = phys:WorldToLocal( trace.HitPos ) end
end
local constr, rope = constraint.Rope( balloon, trace.Entity, 0, trace.PhysicsBone, LPos1, LPos2, 0, length, 0, 0.5, material )
if ( IsValid( constr ) ) then
undo.AddEntity( constr )
ply:AddCleanup( "balloons", constr )
end
if ( IsValid( rope ) ) then
undo.AddEntity( rope )
ply:AddCleanup( "balloons", rope )
end
end
undo.SetPlayer( ply )
undo.Finish()
return true
end
function TOOL:RightClick( trace )
return self:LeftClick( trace, false )
end
if ( SERVER ) then
function MakeBalloon( ply, r, g, b, force, Data )
if ( IsValid( ply ) && !ply:CheckLimit( "balloons" ) ) then return NULL end
if ( !isnumber( r ) ) then r = 255 end
if ( !isnumber( g ) ) then g = 255 end
if ( !isnumber( b ) ) then b = 255 end
if ( !isnumber( force ) ) then force = 0 end
local balloon = ents.Create( "gmod_balloon" )
if ( !IsValid( balloon ) ) then return NULL end
duplicator.DoGeneric( balloon, Data )
balloon:Spawn()
DoPropSpawnedEffect( balloon )
duplicator.DoGenericPhysics( balloon, ply, Data )
balloon:SetColor( Color( r, g, b, 255 ) )
balloon:SetForce( force )
balloon:SetPlayer( ply )
balloon.Player = ply
balloon.r = r
balloon.g = g
balloon.b = b
balloon.force = force
if ( IsValid( ply ) ) then
ply:AddCount( "balloons", balloon )
ply:AddCleanup( "balloons", balloon )
end
return balloon
end
duplicator.RegisterEntityClass( "gmod_balloon", MakeBalloon, "r", "g", "b", "force", "Data" )
end
function TOOL:UpdateGhostBalloon( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit || IsValid( trace.Entity ) && ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_balloon" ) ) then
ent:SetNoDraw( true )
return
end
local CurPos = ent:GetPos()
local NearestPoint = ent:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local Offset = CurPos - NearestPoint
local pos = trace.HitPos + Offset
local modeltable = list.GetEntry( "BalloonModels", self:GetClientInfo( "model" ) )
if ( modeltable && modeltable.skin ) then ent:SetSkin( modeltable.skin ) end
ent:SetPos( pos )
ent:SetAngles( angle_zero )
ent:SetNoDraw( false )
end
function TOOL:Think()
if ( !IsValid( self.GhostEntity ) || self.GhostEntity.model != self:GetClientInfo( "model" ) ) then
local modeltable = list.GetEntry( "BalloonModels", self:GetClientInfo( "model" ) )
if ( !modeltable ) then self:ReleaseGhostEntity() return end
self:MakeGhostEntity( modeltable.model, vector_origin, angle_zero )
if ( IsValid( self.GhostEntity ) ) then self.GhostEntity.model = self:GetClientInfo( "model" ) end
end
self:UpdateGhostBalloon( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.balloon.help" )
CPanel:ToolPresets( "balloon", ConVarsDefault )
CPanel:NumSlider( "#tool.balloon.ropelength", "balloon_ropelength", 5, 1000 )
CPanel:NumSlider( "#tool.balloon.force", "balloon_force", -1000, 2000 )
CPanel:ControlHelp( "#tool.balloon.force.help" )
CPanel:ColorPicker( "#tool.balloon.color", "balloon_r", "balloon_g", "balloon_b" )
CPanel:PropSelect( "#tool.balloon.model", "balloon_model", list.Get( "BalloonModels" ), 0 )
end
list.Set( "BalloonModels", "normal", { model = "models/maxofs2d/balloon_classic.mdl", skin = 0 } )
list.Set( "BalloonModels", "normal_skin1", { model = "models/maxofs2d/balloon_classic.mdl", skin = 1 } )
list.Set( "BalloonModels", "normal_skin2", { model = "models/maxofs2d/balloon_classic.mdl", skin = 2 } )
list.Set( "BalloonModels", "normal_skin3", { model = "models/maxofs2d/balloon_classic.mdl", skin = 3 } )
list.Set( "BalloonModels", "gman", { model = "models/maxofs2d/balloon_gman.mdl", nocolor = true } )
list.Set( "BalloonModels", "mossman", { model = "models/maxofs2d/balloon_mossman.mdl", nocolor = true } )
list.Set( "BalloonModels", "dog", { model = "models/balloons/balloon_dog.mdl" } )
list.Set( "BalloonModels", "heart", { model = "models/balloons/balloon_classicheart.mdl" } )
list.Set( "BalloonModels", "star", { model = "models/balloons/balloon_star.mdl" } )

View File

@@ -0,0 +1,107 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.ballsocket.name"
TOOL.ClientConVar[ "forcelimit" ] = "0"
--TOOL.ClientConVar[ "torquelimit" ] = "0"
TOOL.ClientConVar[ "nocollide" ] = "0"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "constraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local nocollide = self:GetClientNumber( "nocollide", 0 )
local forcelimit = self:GetClientNumber( "forcelimit", 0 )
-- Force this to 0 for now, it does not do anything, and if we fix it in the future, this way existing contraptions won't break
local torquelimit = 0 --self:GetClientNumber( "torquelimit", 0 )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos = self:GetLocalPos( 2 )
local constr = constraint.Ballsocket( Ent1, Ent2, Bone1, Bone2, LPos, forcelimit, torquelimit, nocollide )
if ( IsValid( constr ) ) then
undo.Create( "BallSocket" )
undo.AddEntity( constr )
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.ballsocket.name" )
undo.Finish( "#tool.ballsocket.name" )
ply:AddCount( "constraints", constr )
ply:AddCleanup( "constraints", constr )
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Ballsocket" )
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.ballsocket.help" )
CPanel:ToolPresets( "ballsocket", ConVarsDefault )
CPanel:NumSlider( "#tool.forcelimit", "ballsocket_forcelimit", 0, 50000 )
CPanel:ControlHelp( "#tool.forcelimit.help" )
--CPanel:NumSlider( "#tool.torquelimit", "ballsocket_torquelimit", 0, 50000 )
--CPanel:ControlHelp( "#tool.torquelimit.help" )
CPanel:CheckBox( "#tool.nocollide", "ballsocket_nocollide" )
CPanel:ControlHelp( "#tool.nocollide.help" )
end

View File

@@ -0,0 +1,197 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.button.name"
TOOL.ClientConVar[ "model" ] = "models/maxofs2d/button_05.mdl"
TOOL.ClientConVar[ "keygroup" ] = "37"
TOOL.ClientConVar[ "description" ] = ""
TOOL.ClientConVar[ "toggle" ] = "1"
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
cleanup.Register( "buttons" )
local function IsValidButtonModel( model )
for mdl, _ in pairs( list.Get( "ButtonModels" ) ) do
if ( mdl:lower() == model:lower() ) then return true end
end
return false
end
function TOOL:RightClick( trace, worldweld )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
if ( CLIENT ) then return true end
local model = self:GetClientInfo( "model" )
local key = self:GetClientNumber( "keygroup" )
local description = self:GetClientInfo( "description" )
local toggle = self:GetClientNumber( "toggle" ) == 1
local ply = self:GetOwner()
-- If we shot a button change its settings
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_button" && trace.Entity:GetPlayer() == ply ) then
trace.Entity:SetKey( key )
trace.Entity:SetLabel( description )
trace.Entity:SetIsToggle( toggle )
return true
end
-- Check the model's validity
if ( !util.IsValidModel( model ) || !util.IsValidProp( model ) || !IsValidButtonModel( model ) ) then return false end
if ( !self:GetWeapon():CheckLimit( "buttons" ) ) then return false end
local Ang = trace.HitNormal:Angle()
Ang.pitch = Ang.pitch + 90
local button = MakeButton( ply, model, Ang, trace.HitPos, key, description, toggle )
if ( !IsValid( button ) ) then return false end
local min = button:OBBMins()
button:SetPos( trace.HitPos - trace.HitNormal * min.z )
undo.Create( "gmod_button" )
undo.AddEntity( button )
if ( worldweld && trace.Entity != NULL ) then
local weld = constraint.Weld( button, trace.Entity, 0, trace.PhysicsBone, 0, 0, true )
if ( IsValid( weld ) ) then
ply:AddCleanup( "buttons", weld )
undo.AddEntity( weld )
end
if ( IsValid( button:GetPhysicsObject() ) ) then button:GetPhysicsObject():EnableCollisions( false ) end
button:SetCollisionGroup( COLLISION_GROUP_WORLD )
button.nocollide = true
end
undo.SetPlayer( ply )
undo.Finish()
return true
end
function TOOL:LeftClick( trace )
return self:RightClick( trace, true )
end
if ( SERVER ) then
function MakeButton( ply, model, ang, pos, key, description, toggle, nocollide, Data )
if ( IsValid( ply ) && !ply:CheckLimit( "buttons" ) ) then return NULL end
if ( !IsValidButtonModel( model ) ) then return NULL end
local button = ents.Create( "gmod_button" )
if ( !IsValid( button ) ) then return NULL end
duplicator.DoGeneric( button, Data )
button:SetModel( model ) -- Backwards compatible for addons directly calling this function
button:SetAngles( ang )
button:SetPos( pos )
button:Spawn()
DoPropSpawnedEffect( button )
duplicator.DoGenericPhysics( button, ply, Data )
button:SetPlayer( ply )
button:SetKey( key )
button:SetLabel( description )
button:SetIsToggle( toggle )
if ( nocollide == true ) then
if ( IsValid( button:GetPhysicsObject() ) ) then button:GetPhysicsObject():EnableCollisions( false ) end
button:SetCollisionGroup( COLLISION_GROUP_WORLD )
end
table.Merge( button:GetTable(), {
key = key,
pl = ply,
toggle = toggle,
nocollide = nocollide,
description = description
} )
if ( IsValid( ply ) ) then
ply:AddCount( "buttons", button )
ply:AddCleanup( "buttons", button )
end
return button
end
duplicator.RegisterEntityClass( "gmod_button", MakeButton, "Model", "Ang", "Pos", "key", "description", "toggle", "nocollide", "Data" )
end
function TOOL:UpdateGhostButton( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit || IsValid( trace.Entity ) && ( trace.Entity:GetClass() == "gmod_button" || trace.Entity:IsPlayer() ) ) then
ent:SetNoDraw( true )
return
end
local ang = trace.HitNormal:Angle()
ang.pitch = ang.pitch + 90
local min = ent:OBBMins()
ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
ent:SetAngles( ang )
ent:SetNoDraw( false )
end
function TOOL:Think()
local mdl = self:GetClientInfo( "model" )
if ( !IsValidButtonModel( mdl ) ) then self:ReleaseGhostEntity() return end
if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != mdl:lower() ) then
self:MakeGhostEntity( mdl, vector_origin, angle_zero )
end
self:UpdateGhostButton( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.button.desc" )
CPanel:ToolPresets( "button", ConVarsDefault )
CPanel:KeyBinder( "#tool.button.key", "button_keygroup" )
CPanel:TextEntry( "#tool.button.text", "button_description" )
CPanel:CheckBox( "#tool.button.toggle", "button_toggle" )
CPanel:ControlHelp( "#tool.button.toggle.help" )
CPanel:PropSelect( "#tool.button.model", "button_model", list.Get( "ButtonModels" ), 0 )
end
list.Set( "ButtonModels", "models/maxofs2d/button_01.mdl", {} )
list.Set( "ButtonModels", "models/maxofs2d/button_02.mdl", {} )
list.Set( "ButtonModels", "models/maxofs2d/button_03.mdl", {} )
list.Set( "ButtonModels", "models/maxofs2d/button_04.mdl", {} )
list.Set( "ButtonModels", "models/maxofs2d/button_05.mdl", {} )
list.Set( "ButtonModels", "models/maxofs2d/button_06.mdl", {} )
list.Set( "ButtonModels", "models/maxofs2d/button_slider.mdl", {} )
--list.Set( "ButtonModels", "models/dav0r/buttons/button.mdl", {} )
--list.Set( "ButtonModels", "models/dav0r/buttons/switch.mdl", {} )

View File

@@ -0,0 +1,148 @@
TOOL.Category = "Render"
TOOL.Name = "#tool.camera.name"
TOOL.ClientConVar[ "locked" ] = "0"
TOOL.ClientConVar[ "key" ] = "37"
TOOL.ClientConVar[ "toggle" ] = "1"
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
cleanup.Register( "cameras" )
local function CheckLimit( ply, key )
-- TODO: Clientside prediction
if ( CLIENT ) then return true end
local found = false
for id, camera in ipairs( ents.FindByClass( "gmod_cameraprop" ) ) do
if ( !camera.controlkey || camera.controlkey != key ) then continue end
if ( IsValid( camera:GetPlayer() ) && ply != camera:GetPlayer() ) then continue end
found = true
break
end
if ( !found && !ply:CheckLimit( "cameras" ) ) then
return false
end
return true
end
local function MakeCamera( ply, key, locked, toggle, Data )
if ( IsValid( ply ) && !CheckLimit( ply, key ) ) then return NULL end
local ent = ents.Create( "gmod_cameraprop" )
if ( !IsValid( ent ) ) then return NULL end
duplicator.DoGeneric( ent, Data )
if ( key ) then
for id, camera in ipairs( ents.FindByClass( "gmod_cameraprop" ) ) do
if ( !camera.controlkey || camera.controlkey != key ) then continue end
if ( IsValid( ply ) && IsValid( camera:GetPlayer() ) && ply != camera:GetPlayer() ) then continue end
camera:Remove()
end
ent:SetKey( key )
ent.controlkey = key -- Legacy?
end
ent:SetPlayer( ply )
ent.toggle = toggle
ent.locked = locked
ent:Spawn()
DoPropSpawnedEffect( ent )
duplicator.DoGenericPhysics( ent, ply, Data )
ent:SetTracking( NULL, Vector( 0 ) )
ent:SetLocked( locked )
ent:ApplyKeybinds( ply ) -- Trigger the numpad assignments
if ( IsValid( ply ) ) then
ply:AddCleanup( "cameras", ent )
ply:AddCount( "cameras", ent )
end
return ent
end
if ( SERVER ) then
duplicator.RegisterEntityClass( "gmod_cameraprop", MakeCamera, "controlkey", "locked", "toggle", "Data" )
end
function TOOL:LeftClick( trace )
local ply = self:GetOwner()
local key = self:GetClientNumber( "key" )
if ( key == -1 ) then return false end
if ( !CheckLimit( ply, key ) ) then return false end
if ( CLIENT ) then return true end
local locked = self:GetClientNumber( "locked" )
local toggle = self:GetClientNumber( "toggle" )
local ent = MakeCamera( ply, key, locked, toggle, { Pos = trace.StartPos, Angle = ply:EyeAngles() } )
if ( !IsValid( ent ) ) then return false end
undo.Create( "gmod_cameraprop" )
undo.AddEntity( ent )
undo.SetPlayer( ply )
undo.Finish()
return true, ent
end
function TOOL:RightClick( trace )
local _, camera = self:LeftClick( trace, true )
if ( CLIENT ) then return true end
if ( !IsValid( camera ) ) then return false end
if ( trace.Entity:IsWorld() ) then
trace.Entity = self:GetOwner()
trace.HitPos = trace.Entity:GetPos()
end
-- We apply the view offset for players in camera entity
if ( trace.Entity:IsPlayer() ) then
trace.HitPos = trace.Entity:GetPos()
end
camera:SetTracking( trace.Entity, trace.Entity:WorldToLocal( trace.HitPos ) )
return true
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:ToolPresets( "camera", ConVarsDefault )
CPanel:KeyBinder( "#tool.camera.key", "camera_key" )
CPanel:CheckBox( "#tool.camera.static", "camera_locked" )
CPanel:ControlHelp( "#tool.camera.static.help" )
CPanel:CheckBox( "#tool.toggle", "camera_toggle" )
end

View File

@@ -0,0 +1,132 @@
TOOL.Category = "Render"
TOOL.Name = "#tool.colour.name"
TOOL.ClientConVar[ "r" ] = 255
TOOL.ClientConVar[ "g" ] = 255
TOOL.ClientConVar[ "b" ] = 255
TOOL.ClientConVar[ "a" ] = 255
TOOL.ClientConVar[ "mode" ] = "0"
TOOL.ClientConVar[ "fx" ] = "0"
TOOL.Information = {
{ name = "left" },
{ name = "right" },
{ name = "reload" }
}
local function SetColour( ply, ent, data )
--
-- If we're trying to make them transparent them make the render mode
-- a transparent type. This used to fix in the engine - but made HL:S props invisible(!)
--
if ( data.Color && data.Color.a < 255 && data.RenderMode == RENDERMODE_NORMAL ) then
data.RenderMode = RENDERMODE_TRANSCOLOR
end
if ( data.Color ) then ent:SetColor( Color( data.Color.r, data.Color.g, data.Color.b, data.Color.a ) ) end
if ( data.RenderMode ) then ent:SetRenderMode( data.RenderMode ) end
if ( data.RenderFX ) then ent:SetKeyValue( "renderfx", data.RenderFX ) end
if ( SERVER ) then
duplicator.StoreEntityModifier( ent, "colour", data )
end
end
if ( SERVER ) then
duplicator.RegisterEntityModifier( "colour", SetColour )
end
function TOOL:LeftClick( trace )
local ent = trace.Entity
if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end -- The entity is valid and isn't worldspawn
if ( CLIENT ) then return true end
local r = self:GetClientNumber( "r", 0 )
local g = self:GetClientNumber( "g", 0 )
local b = self:GetClientNumber( "b", 0 )
local a = self:GetClientNumber( "a", 0 )
local fx = self:GetClientNumber( "fx", 0 )
local mode = self:GetClientNumber( "mode", 0 )
SetColour( self:GetOwner(), ent, { Color = Color( r, g, b, a ), RenderMode = mode, RenderFX = fx } )
return true
end
function TOOL:RightClick( trace )
local ent = trace.Entity
if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end -- The entity is valid and isn't worldspawn
if ( CLIENT ) then return true end
local clr = ent:GetColor()
self:GetOwner():ConCommand( "colour_r " .. clr.r )
self:GetOwner():ConCommand( "colour_g " .. clr.g )
self:GetOwner():ConCommand( "colour_b " .. clr.b )
self:GetOwner():ConCommand( "colour_a " .. clr.a )
self:GetOwner():ConCommand( "colour_fx " .. ent:GetRenderFX() )
self:GetOwner():ConCommand( "colour_mode " .. ent:GetRenderMode() )
return true
end
function TOOL:Reload( trace )
local ent = trace.Entity
if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end -- The entity is valid and isn't worldspawn
if ( CLIENT ) then return true end
SetColour( self:GetOwner(), ent, { Color = Color( 255, 255, 255, 255 ), RenderMode = 0, RenderFX = 0 } )
return true
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.colour.desc" )
CPanel:ToolPresets( "colour", ConVarsDefault )
CPanel:ColorPicker( "#tool.colour.color", "colour_r", "colour_g", "colour_b", "colour_a" )
CPanel:ComboBoxMulti( "#tool.colour.mode", list.Get( "RenderModes" ) )
CPanel:ComboBoxMulti( "#tool.colour.fx", list.Get( "RenderFX" ) )
end
list.Set( "RenderModes", "#rendermode.normal", { colour_mode = 0 } )
list.Set( "RenderModes", "#rendermode.transcolor", { colour_mode = 1 } )
list.Set( "RenderModes", "#rendermode.transtexture", { colour_mode = 2 } )
list.Set( "RenderModes", "#rendermode.glow", { colour_mode = 3 } )
list.Set( "RenderModes", "#rendermode.transalpha", { colour_mode = 4 } )
list.Set( "RenderModes", "#rendermode.transadd", { colour_mode = 5 } )
list.Set( "RenderModes", "#rendermode.transalphaadd", { colour_mode = 8 } )
list.Set( "RenderModes", "#rendermode.worldglow", { colour_mode = 9 } )
list.Set( "RenderFX", "#renderfx.none", { colour_fx = 0 } )
list.Set( "RenderFX", "#renderfx.pulseslow", { colour_fx = 1 } )
list.Set( "RenderFX", "#renderfx.pulsefast", { colour_fx = 2 } )
list.Set( "RenderFX", "#renderfx.pulseslowwide", { colour_fx = 3 } )
list.Set( "RenderFX", "#renderfx.pulsefastwide", { colour_fx = 4 } )
list.Set( "RenderFX", "#renderfx.fadeslow", { colour_fx = 5 } )
list.Set( "RenderFX", "#renderfx.fadefast", { colour_fx = 6 } )
list.Set( "RenderFX", "#renderfx.solidslow", { colour_fx = 7 } )
list.Set( "RenderFX", "#renderfx.solidfast", { colour_fx = 8 } )
list.Set( "RenderFX", "#renderfx.strobeslow", { colour_fx = 9 } )
list.Set( "RenderFX", "#renderfx.strobefast", { colour_fx = 10 } )
list.Set( "RenderFX", "#renderfx.strobefaster", { colour_fx = 11 } )
list.Set( "RenderFX", "#renderfx.flickerslow", { colour_fx = 12 } )
list.Set( "RenderFX", "#renderfx.flickerfast", { colour_fx = 13 } )
list.Set( "RenderFX", "#renderfx.distort", { colour_fx = 15 } )
list.Set( "RenderFX", "#renderfx.hologram", { colour_fx = 16 } )
list.Set( "RenderFX", "#renderfx.pulsefastwider", { colour_fx = 24 } )

View File

@@ -0,0 +1,53 @@
TOOL.AddToMenu = false
TOOL.ClientConVar[ "type" ] = "0"
TOOL.ClientConVar[ "name" ] = "0"
TOOL.ClientConVar[ "override" ] = ""
TOOL.Information = { { name = "left" } }
function TOOL:LeftClick( trace, attach )
local type = self:GetClientNumber( "type", 0 )
local name = self:GetClientInfo( "name" )
if ( CLIENT ) then return true end
if ( type == 0 ) then
Spawn_SENT( self:GetOwner(), name, trace )
elseif ( type == 1 ) then
Spawn_Vehicle( self:GetOwner(), name, trace )
elseif ( type == 2 ) then
-- Load a weapon just like left clicking would
local weapon = ""
local gmod_npcweapon = self:GetOwner():GetInfo( "gmod_npcweapon" )
if ( gmod_npcweapon != "" ) then
weapon = gmod_npcweapon
else
local NPCinfo = list.GetEntry( "NPC", name )
weapon = table.Random( NPCinfo and NPCinfo.Weapons or {} ) or ""
end
local override = self:GetOwner():GetInfo( "creator_override" )
if ( override != "" ) then weapon = override end
Spawn_NPC( self:GetOwner(), name, weapon, trace )
elseif ( type == 3 ) then
Spawn_Weapon( self:GetOwner(), name, trace )
elseif ( type == 4 ) then
CCSpawn( self:GetOwner(), nil, { name } ) -- Props
end
return true
end

View File

@@ -0,0 +1,248 @@
include( "duplicator/transport.lua" )
include( "duplicator/arming.lua" )
if ( CLIENT ) then
include( "duplicator/icon.lua" )
else
AddCSLuaFile( "duplicator/arming.lua" )
AddCSLuaFile( "duplicator/transport.lua" )
AddCSLuaFile( "duplicator/icon.lua" )
util.AddNetworkString( "CopiedDupe" )
end
TOOL.Category = "Construction"
TOOL.Name = "#tool.duplicator.name"
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
cleanup.Register( "duplicates" )
--
-- PASTE
--
function TOOL:LeftClick( trace )
if ( CLIENT ) then return true end
--
-- Get the copied dupe. We store it on the player so it will still exist if they die and respawn.
--
local dupe = self:GetOwner().CurrentDupe
if ( !dupe ) then return false end
--
-- We want to spawn it flush on thr ground. So get the point that we hit
-- and take away the mins.z of the bounding box of the dupe.
--
local SpawnCenter = trace.HitPos
SpawnCenter.z = SpawnCenter.z - dupe.Mins.z
--
-- Spawn it rotated with the player - but not pitch.
--
local SpawnAngle = self:GetOwner():EyeAngles()
SpawnAngle.pitch = 0
SpawnAngle.roll = 0
--
-- Spawn them all at our chosen positions
--
duplicator.SetLocalPos( SpawnCenter )
duplicator.SetLocalAng( SpawnAngle )
DisablePropCreateEffect = true
local Ents = duplicator.Paste( self:GetOwner(), dupe.Entities, dupe.Constraints )
DisablePropCreateEffect = nil
duplicator.SetLocalPos( vector_origin )
duplicator.SetLocalAng( angle_zero )
--
-- Create one undo for the whole creation
--
undo.Create( "Duplicator" )
for k, ent in pairs( Ents ) do
undo.AddEntity( ent )
end
for k, ent in pairs( Ents ) do
self:GetOwner():AddCleanup( "duplicates", ent )
end
undo.SetPlayer( self:GetOwner() )
undo.SetCustomUndoText( "Undone #undo.duplication" )
undo.Finish( "#undo.duplication (" .. tostring( table.Count( Ents ) ) .. ")" )
return true
end
--
-- Copy
--
function TOOL:RightClick( trace )
if ( !IsValid( trace.Entity ) ) then return false end
if ( CLIENT ) then return true end
--
-- Set the position to our local position (so we can paste relative to our `hold`)
--
duplicator.SetLocalPos( trace.HitPos )
duplicator.SetLocalAng( Angle( 0, self:GetOwner():EyeAngles().yaw, 0 ) )
local Dupe = duplicator.Copy( trace.Entity )
duplicator.SetLocalPos( vector_origin )
duplicator.SetLocalAng( angle_zero )
if ( !Dupe ) then return false end
--
-- Tell the clientside that they're holding something new
--
net.Start( "CopiedDupe" )
net.WriteUInt( 1, 1 )
net.WriteVector( Dupe.Mins )
net.WriteVector( Dupe.Maxs )
net.WriteString( "Unsaved dupe" )
net.WriteUInt( table.Count( Dupe.Entities ), 24 )
net.WriteUInt( 0, 16 )
net.Send( self:GetOwner() )
--
-- Store the dupe on the player
--
self:GetOwner().CurrentDupeArmed = false
self:GetOwner().CurrentDupe = Dupe
return true
end
if ( CLIENT ) then
--
-- Builds the context menu
--
function TOOL.BuildCPanel( CPanel, tool )
CPanel:Clear()
CPanel:Help( "#tool.duplicator.desc" )
CPanel:Button( "#tool.duplicator.showsaves", "dupe_show" )
if ( !tool && IsValid( LocalPlayer() ) ) then tool = LocalPlayer():GetTool( "duplicator" ) end
if ( !tool || !tool.CurrentDupeName ) then return end
local info = "Name: " .. tool.CurrentDupeName
info = info .. "\nEntities: " .. tool.CurrentDupeEntCount
CPanel:Help( info )
if ( tool.CurrentDupeWSIDs && #tool.CurrentDupeWSIDs > 0 ) then
CPanel:Help( "Required workshop content:" )
for _, wsid in pairs( tool.CurrentDupeWSIDs ) do
local subbed = ""
if ( steamworks.IsSubscribed( wsid ) ) then subbed = " (Subscribed)" end
local b = CPanel:Button( wsid .. subbed )
b.DoClick = function( s, ... ) steamworks.ViewFile( wsid ) end
steamworks.FileInfo( wsid, function( result )
if ( !IsValid( b ) ) then return end
b:SetText( result.title .. subbed )
end )
end
end
if ( tool.CurrentDupeCanSave ) then
local b = CPanel:Button( "#dupes.savedupe", "dupe_save" )
hook.Add( "DupeSaveUnavailable", b, function() b:Remove() end )
end
end
function TOOL:RefreshCPanel()
local CPanel = controlpanel.Get( "duplicator" )
if ( !CPanel ) then return end
self.BuildCPanel( CPanel, self )
end
--
-- Received by the client to alert us that we have something copied
-- This allows us to enable the save button in the spawn menu
--
net.Receive( "CopiedDupe", function( len, client )
local canSave = net.ReadUInt( 1 )
if ( canSave == 1 ) then
hook.Run( "DupeSaveAvailable" )
else
hook.Run( "DupeSaveUnavailable" )
end
local ply = LocalPlayer()
if ( !IsValid( ply ) || !ply.GetTool ) then return end
local tool = ply:GetTool( "duplicator" )
if ( !tool ) then return end
tool.CurrentDupeCanSave = canSave == 1
tool.CurrentDupeMins = net.ReadVector()
tool.CurrentDupeMaxs = net.ReadVector()
tool.CurrentDupeName = net.ReadString()
tool.CurrentDupeEntCount = net.ReadUInt( 24 )
local workshopCount = net.ReadUInt( 16 )
local addons = {}
for i = 1, workshopCount do
table.insert( addons, net.ReadString() )
end
tool.CurrentDupeWSIDs = addons
tool:RefreshCPanel()
end )
-- This is not perfect, but let the player see roughly the outline of what they are about to paste
function TOOL:DrawHUD()
local ply = LocalPlayer()
if ( !IsValid( ply ) || !self.CurrentDupeMins || !self.CurrentDupeMaxs ) then return end
local tr = self:GetWeapon():DoToolTrace()
if ( !tr ) then return end
local pos = tr.HitPos
pos.z = pos.z - self.CurrentDupeMins.z
local ang = ply:GetAngles()
if ( IsValid( ply:GetVehicle() ) ) then
ang = ang + ply:LocalEyeAngles()
ang.y = ang.y - 90 -- Hacky
end
ang.p = 0
ang.r = 0
cam.Start3D()
render.DrawWireframeBox( pos, ang, self.CurrentDupeMins, self.CurrentDupeMaxs )
cam.End3D()
end
end

View File

@@ -0,0 +1,131 @@
local DUPE_SEND_SIZE = 60000
if ( CLIENT ) then
--
-- Called by the client to save a dupe they're holding on the server
-- into a file on their computer.
--
local LastDupeArm = 0
concommand.Add( "dupe_arm", function( ply, cmd, arg )
if ( !arg[ 1 ] ) then return end
if ( LastDupeArm > CurTime() and !game.SinglePlayer() ) then ply:ChatPrint( "Please wait a second before trying to load another duplication!" ) return end
LastDupeArm = CurTime() + 1
-- Server doesn't allow us to do this, don't even try to send them data
local res, msg = hook.Run( "CanArmDupe", ply )
if ( res == false ) then ply:ChatPrint( msg or "Refusing to load dupe, server has blocked usage of the Duplicator tool!" ) return end
-- Load the dupe (engine takes care of making sure it's a dupe)
local dupe = engine.OpenDupe( arg[ 1 ] )
if ( !dupe ) then ply:ChatPrint( "Error loading dupe.. (" .. tostring( arg[ 1 ] ) .. ")" ) return end
local uncompressed = util.Decompress( dupe.data, 5242880 )
if ( !uncompressed ) then ply:ChatPrint( "That dupe seems to be corrupted!" ) return end
--
-- And send it to the server
--
local length = dupe.data:len()
local parts = math.ceil( length / DUPE_SEND_SIZE )
local start = 0
for i = 1, parts do
local endbyte = math.min( start + DUPE_SEND_SIZE, length )
local size = endbyte - start
net.Start( "ArmDupe" )
net.WriteUInt( i, 8 )
net.WriteUInt( parts, 8 )
net.WriteUInt( size, 32 )
net.WriteData( dupe.data:sub( start + 1, endbyte + 1 ), size )
net.SendToServer()
start = endbyte
end
end, nil, "Arm a dupe", { FCVAR_DONTRECORD } )
end
if ( SERVER ) then
--
-- Add the name of the net message to the string table (or it won't be able to send!)
--
util.AddNetworkString( "ArmDupe" )
net.Receive( "ArmDupe", function( size, client )
if ( !IsValid( client ) or size < 48 ) then return end
local res, msg = hook.Run( "CanArmDupe", client )
if ( res == false ) then client:ChatPrint( msg or "Server has blocked usage of the Duplicator tool!" ) return end
local part = net.ReadUInt( 8 )
local total = net.ReadUInt( 8 )
local length = net.ReadUInt( 32 )
if ( length > DUPE_SEND_SIZE ) then return end
local datachunk = net.ReadData( length )
client.CurrentDupeBuffer = client.CurrentDupeBuffer or {}
client.CurrentDupeBuffer[ part ] = datachunk
if ( part != total ) then return end
local data = table.concat( client.CurrentDupeBuffer )
client.CurrentDupeBuffer = nil
if ( ( client.LastDupeArm or 0 ) > CurTime() and !game.SinglePlayer() ) then ServerLog( tostring( client ) .. " tried to arm a dupe too quickly!\n" ) return end
client.LastDupeArm = CurTime() + 1
ServerLog( tostring( client ) .. " is arming a dupe, size: " .. data:len() .. "\n" )
local uncompressed = util.Decompress( data, 5242880 )
if ( !uncompressed ) then
client:ChatPrint( "Server failed to decompress the duplication!" )
MsgN( "Couldn't decompress dupe from " .. client:Nick() .. "!" )
return
end
local Dupe = util.JSONToTable( uncompressed )
if ( !istable( Dupe ) ) then return end
if ( !istable( Dupe.Constraints ) ) then return end
if ( !istable( Dupe.Entities ) ) then return end
if ( !isvector( Dupe.Mins ) ) then return end
if ( !isvector( Dupe.Maxs ) ) then return end
client.CurrentDupeArmed = true
client.CurrentDupe = Dupe
client:ConCommand( "gmod_tool duplicator" )
--
-- Tell the client we got a dupe on server, ready to paste
--
local workshopCount = 0
if ( Dupe.RequiredAddons ) then workshopCount = #Dupe.RequiredAddons end
net.Start( "CopiedDupe" )
net.WriteUInt( 0, 1 ) -- Can save
net.WriteVector( Dupe.Mins )
net.WriteVector( Dupe.Maxs )
net.WriteString( "Loaded dupe" )
net.WriteUInt( table.Count( Dupe.Entities ), 24 )
net.WriteUInt( workshopCount, 16 )
if ( Dupe.RequiredAddons ) then
for _, wsid in ipairs( Dupe.RequiredAddons ) do
net.WriteString( wsid )
end
end
net.Send( client )
end )
end

View File

@@ -0,0 +1,270 @@
hook.Add( "PostRender", "RenderDupeIcon", function()
--
-- g_ClientSaveDupe is set in transport.lua when receiving a dupe from the server
--
if ( !g_ClientSaveDupe ) then return end
--
-- Remove the global straight away
--
local Dupe = g_ClientSaveDupe
g_ClientSaveDupe = nil
local FOV = 17
--
-- This is gonna take some cunning to look awesome!
--
local Size = Dupe.Maxs - Dupe.Mins
local Radius = Size:Length() * 0.5
local CamDist = Radius / math.sin( math.rad( FOV ) / 2 ) -- Works out how far the camera has to be away based on radius + fov!
local Center = LerpVector( 0.5, Dupe.Mins, Dupe.Maxs )
local CamPos = Center + Vector( -1, 0, 0.5 ):GetNormalized() * CamDist
local EyeAng = ( Center - CamPos ):GetNormal():Angle()
--
-- The base view
--
local view = {
type = "3D",
origin = CamPos,
angles = EyeAng,
x = 0,
y = 0,
w = 512,
h = 512,
aspect = 1,
fov = FOV
}
--
-- Create a bunch of entities we're gonna use to render.
--
local entities = {}
local i = 0
for k, ent in pairs( Dupe.Entities ) do
if ( ent.Class == "prop_ragdoll" ) then
entities[ k ] = ClientsideRagdoll( ent.Model or "error.mdl", RENDERGROUP_OTHER )
if ( istable( ent.PhysicsObjects ) ) then
for boneid, v in pairs( ent.PhysicsObjects ) do
local obj = entities[ k ]:GetPhysicsObjectNum( boneid )
if ( IsValid( obj ) ) then
obj:SetPos( v.Pos )
obj:SetAngles( v.Angle )
end
end
entities[ k ]:InvalidateBoneCache()
end
else
entities[ k ] = ClientsideModel( ent.Model or "error.mdl", RENDERGROUP_OTHER )
end
i = i + 1
end
--
-- DRAW THE BLUE BACKGROUND
--
render.SetMaterial( Material( "gui/dupe_bg.png" ) )
render.DrawScreenQuadEx( 0, 0, 512, 512 )
render.UpdateRefractTexture()
--
-- BLACK OUTLINE
-- AWESOME BRUTE FORCE METHOD
--
render.SuppressEngineLighting( true )
-- Rendering icon the way we do is kinda bad and will crash the game with too many entities in the dupe
-- Try to mitigate that to some degree by not rendering the outline when we are above 800 entities
-- 1000 was tested without problems, but we want to give it some space as 1000 was tested in "perfect conditions" with nothing else happening on the map
if ( i < 800 ) then
local BorderSize = CamDist * 0.004
local Up = EyeAng:Up() * BorderSize
local Right = EyeAng:Right() * BorderSize
render.SetColorModulation( 1, 1, 1 )
render.SetBlend( 1 )
render.MaterialOverride( Material( "models/debug/debugwhite" ) )
-- Render each entity in a circle
for k, v in pairs( Dupe.Entities ) do
-- Set the skin and bodygroups
entities[ k ]:SetSkin( v.Skin or 0 )
for bg_k, bg_v in pairs( v.BodyG or {} ) do entities[ k ]:SetBodygroup( bg_k, bg_v ) end
for j = 0, math.tau, 0.2 do
view.origin = CamPos + Up * math.sin( j ) + Right * math.cos( j )
cam.Start( view )
render.Model( {
model = v.Model,
pos = v.Pos,
angle = v.Angle
}, entities[ k ] )
cam.End()
end
end
-- Because we just messed up the depth
render.ClearDepth()
render.SetColorModulation( 0, 0, 0 )
render.SetBlend( 1 )
-- Try to keep the border size consistent with zoom size
BorderSize = CamDist * 0.002
Up = EyeAng:Up() * BorderSize
Right = EyeAng:Right() * BorderSize
-- Render each entity in a circle
for k, v in pairs( Dupe.Entities ) do
for j = 0, math.tau, 0.2 do
view.origin = CamPos + Up * math.sin( j ) + Right * math.cos( j )
cam.Start( view )
render.Model( {
model = v.Model,
pos = v.Pos,
angle = v.Angle
}, entities[ k ] )
cam.End()
end
end
end
--
-- ACUAL RENDER!
--
-- We just fucked the depth up - so clean it
render.ClearDepth()
-- Set up the lighting. This is over-bright on purpose - to make the ents pop
render.SetModelLighting( 0, 0, 0, 0 )
render.SetModelLighting( 1, 2, 2, 2 )
render.SetModelLighting( 2, 3, 2, 0 )
render.SetModelLighting( 3, 0.5, 2.0, 2.5 )
render.SetModelLighting( 4, 3, 3, 3 ) -- top
render.SetModelLighting( 5, 0, 0, 0 )
render.MaterialOverride( nil )
view.origin = CamPos
cam.Start( view )
-- Render each model
for k, v in pairs( Dupe.Entities ) do
render.SetColorModulation( 1, 1, 1 )
render.SetBlend( 1 )
-- EntityMods override this
if ( v._DuplicatedColor ) then
render.SetColorModulation( v._DuplicatedColor.r / 255, v._DuplicatedColor.g / 255, v._DuplicatedColor.b / 255 )
--render.SetBlend( v._DuplicatedColor.a / 255 )
end
if ( v._DuplicatedMaterial ) then render.MaterialOverride( Material( v._DuplicatedMaterial ) ) end
if ( istable( v.EntityMods ) ) then
if ( istable( v.EntityMods.colour ) ) then
render.SetColorModulation( v.EntityMods.colour.Color.r / 255, v.EntityMods.colour.Color.g / 255, v.EntityMods.colour.Color.b / 255 )
--render.SetBlend( v.EntityMods.colour.Color.a / 255 )
end
if ( istable( v.EntityMods.material ) ) then
render.MaterialOverride( Material( v.EntityMods.material.MaterialOverride ) )
end
end
render.Model( {
model = v.Model,
pos = v.Pos,
angle = v.Angle
}, entities[ k ] )
render.MaterialOverride( nil )
end
cam.End()
-- Enable lighting again (or it will affect outside of this loop!)
render.SuppressEngineLighting( false )
render.SetColorModulation( 1, 1, 1 )
render.SetBlend( 1 )
--
-- Finished with the entities - remove them all
--
for k, v in pairs( entities ) do
v:Remove()
end
--
-- This captures a square of the render target, copies it to a jpeg file
-- and returns it to us as a (binary) string.
--
local jpegdata = render.Capture( {
format = "jpeg",
x = 0,
y = 0,
w = 512,
h = 512,
quality = 95
} )
--
-- Try to figure out if any of the models/materials/etc came from some addon
--
duplicator.FigureOutRequiredAddons( Dupe )
--
-- Encode and compress the dupe
--
local DupeJSON = util.TableToJSON( Dupe )
if ( !isstring( DupeJSON ) ) then
MsgN( "There was an error converting the dupe to a json string" )
end
DupeJSON = util.Compress( DupeJSON )
--
-- And save it! (filename is automatic md5 in dupes/)
--
if ( engine.WriteDupe( DupeJSON, jpegdata ) ) then
-- Disable the save button!!
hook.Run( "DupeSaveUnavailable" )
hook.Run( "DupeSaved" )
MsgN( "Saved!" )
spawnmenu.SwitchCreationTab( "#spawnmenu.category.dupes" )
end
end )

View File

@@ -0,0 +1,99 @@
if ( SERVER ) then
--
-- Add the name of the net message to the string table (or it won't be able to send!)
--
util.AddNetworkString( "ReceiveDupe" )
--
-- Called by the client to save a dupe they're holding on the server
-- into a file on their computer.
--
concommand.Add( "dupe_save", function( ply, cmd, arg )
if ( !IsValid( ply ) ) then return end
-- No dupe to save
if ( !ply.CurrentDupe ) then return end
-- Current dupe was armed from a file. Don't allow immediate resave.
if ( ply.CurrentDupeArmed ) then return end
if ( ply.m_NextDupeSave && ply.m_NextDupeSave > CurTime() && !game.SinglePlayer() ) then
ServerLog( tostring( ply ) .. " tried to save a dupe too quickly!\n" )
return
end
ply.m_NextDupeSave = CurTime() + 1
-- Convert dupe to JSON
local json = util.TableToJSON( ply.CurrentDupe )
-- Compress it
local compressed = util.Compress( json )
local length = compressed:len()
local send_size = 60000
local parts = math.ceil( length / send_size )
ServerLog( tostring( ply ) .. " requested a Dupe. Size: " .. json:len() .. " ( " .. length .. " compressed, " .. parts .. " parts )\n" )
-- And send it(!)
local start = 0
for i = 1, parts do
local endbyte = math.min( start + send_size, length )
local size = endbyte - start
-- print( "S [ " .. i .. " / " .. parts .. " ] Size: " .. size .. " Start: " .. start .. " End: " .. endbyte )
net.Start( "ReceiveDupe" )
net.WriteUInt( i, 8 )
net.WriteUInt( parts, 8 )
net.WriteUInt( size, 32 )
net.WriteData( compressed:sub( start + 1, endbyte + 1 ), size )
net.Send( ply )
start = endbyte
end
end, nil, "Save the current dupe!", { FCVAR_DONTRECORD } )
end
if ( CLIENT ) then
local buffer = ""
net.Receive( "ReceiveDupe", function( len, client )
local part = net.ReadUInt( 8 )
local total = net.ReadUInt( 8 )
local length = net.ReadUInt( 32 )
local data = net.ReadData( length )
buffer = buffer .. data
-- MsgN( "R [ " .. part .. " / " .. total .. " ] Size: " .. data:len() )
if ( part != total ) then return end
MsgN( "Received dupe. Size: " .. buffer:len() )
local uncompressed = util.Decompress( buffer )
buffer = ""
if ( !uncompressed ) then
MsgN( "Received dupe - but couldn't decompress!?" )
return
end
--
-- Set this global so we can pick it up when we're rendering a frame
-- See icon.lua for this process
--
g_ClientSaveDupe = util.JSONToTable( uncompressed )
end )
end

View File

@@ -0,0 +1,185 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.dynamite.name"
TOOL.ClientConVar[ "group" ] = 52
TOOL.ClientConVar[ "damage" ] = 200
TOOL.ClientConVar[ "delay" ] = 0
TOOL.ClientConVar[ "model" ] = "models/dav0r/tnt/tnt.mdl"
TOOL.ClientConVar[ "remove" ] = 0
TOOL.Information = { { name = "left" } }
cleanup.Register( "dynamite" )
local function IsValidDynamiteModel( model )
for mdl, _ in pairs( list.Get( "DynamiteModels" ) ) do
if ( mdl:lower() == model:lower() ) then return true end
end
return false
end
function TOOL:LeftClick( trace )
if ( !trace.HitPos || IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
local ply = self:GetOwner()
-- Get client's CVars
local group = self:GetClientNumber( "group" )
local delay = self:GetClientNumber( "delay" )
local damage = self:GetClientNumber( "damage" )
local model = self:GetClientInfo( "model" )
local remove = self:GetClientNumber( "remove" ) == 1
-- If we shot a dynamite, change it's settings
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_dynamite" && trace.Entity:GetPlayer() == ply ) then
trace.Entity:SetDamage( damage )
trace.Entity:SetShouldRemove( remove )
trace.Entity:SetDelay( delay )
numpad.Remove( trace.Entity.NumDown )
trace.Entity.key = group
trace.Entity.NumDown = numpad.OnDown( ply, group, "DynamiteBlow", trace.Entity )
return true
end
if ( !util.IsValidModel( model ) || !util.IsValidProp( model ) || !IsValidDynamiteModel( model ) ) then return false end
if ( !self:GetWeapon():CheckLimit( "dynamite" ) ) then return false end
local dynamite = MakeDynamite( ply, trace.HitPos, angle_zero, group, damage, model, remove, delay )
if ( !IsValid( dynamite ) ) then return false end
local CurPos = dynamite:GetPos()
local Offset = CurPos - dynamite:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
dynamite:SetPos( trace.HitPos + Offset )
undo.Create( "gmod_dynamite" )
undo.AddEntity( dynamite )
undo.SetPlayer( ply )
undo.Finish()
return true
end
if ( SERVER ) then
function MakeDynamite( ply, pos, ang, key, damage, model, remove, delay, Data )
if ( IsValid( ply ) && !ply:CheckLimit( "dynamite" ) ) then return NULL end
if ( !IsValidDynamiteModel( model ) ) then return NULL end
local dynamite = ents.Create( "gmod_dynamite" )
if ( !IsValid( dynamite ) ) then return NULL end
duplicator.DoGeneric( dynamite, Data )
dynamite:SetPos( pos ) -- Backwards compatible for addons directly calling this function
dynamite:SetAngles( ang )
dynamite:SetModel( model )
dynamite:SetShouldRemove( remove )
dynamite:SetDamage( damage )
dynamite:SetDelay( delay )
dynamite:Spawn()
DoPropSpawnedEffect( dynamite )
duplicator.DoGenericPhysics( dynamite, ply, Data )
if ( IsValid( ply ) ) then
dynamite:SetPlayer( ply )
end
table.Merge( dynamite:GetTable(), {
key = key,
pl = ply,
Damage = damage,
model = model,
remove = remove,
delay = delay
} )
dynamite.NumDown = numpad.OnDown( ply, key, "DynamiteBlow", dynamite )
if ( IsValid( ply ) ) then
ply:AddCount( "dynamite", dynamite )
ply:AddCleanup( "dynamite", dynamite )
end
return dynamite
end
duplicator.RegisterEntityClass( "gmod_dynamite", MakeDynamite, "Pos", "Ang", "key", "Damage", "model", "remove", "delay", "Data" )
numpad.Register( "DynamiteBlow", function( ply, dynamite )
if ( !IsValid( dynamite ) ) then return end
dynamite:Explode( nil, ply )
end )
end
function TOOL:UpdateGhostDynamite( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit || IsValid( trace.Entity ) && ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_dynamite" ) ) then
ent:SetNoDraw( true )
return
end
ent:SetAngles( angle_zero )
local CurPos = ent:GetPos()
local Offset = CurPos - ent:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
ent:SetPos( trace.HitPos + Offset )
ent:SetNoDraw( false )
end
function TOOL:Think()
local mdl = self:GetClientInfo( "model" )
if ( !IsValidDynamiteModel( mdl ) ) then self:ReleaseGhostEntity() return end
if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != mdl:lower() ) then
self:MakeGhostEntity( mdl, vector_origin, angle_zero )
end
self:UpdateGhostDynamite( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.dynamite.help" )
CPanel:ToolPresets( "dynamite", ConVarsDefault )
CPanel:KeyBinder( "#tool.dynamite.explode", "dynamite_group" )
CPanel:NumSlider( "#tool.dynamite.damage", "dynamite_damage", 0, 500 )
CPanel:ControlHelp( "#tool.dynamite.damage.help" )
CPanel:NumSlider( "#tool.dynamite.delay", "dynamite_delay", 0, 10 )
CPanel:ControlHelp( "#tool.dynamite.delay.help" )
CPanel:CheckBox( "#tool.dynamite.remove", "dynamite_remove" )
CPanel:PropSelect( "#tool.dynamite.model", "dynamite_model", list.Get( "DynamiteModels" ), 0 )
end
list.Set( "DynamiteModels", "models/dav0r/tnt/tnt.mdl", {} )
list.Set( "DynamiteModels", "models/dav0r/tnt/tnttimed.mdl", {} )
list.Set( "DynamiteModels", "models/dynamite/dynamite.mdl", {} )

View File

@@ -0,0 +1,54 @@
--
-- This works - but I'm not certain that it's the way to go about it.
-- better instead to use the right click properties?
--
TOOL.AddToMenu = false
TOOL.Category = "Construction"
TOOL.Name = "#tool.editentity.name"
function TOOL:LeftClick( trace )
if ( !trace.Hit ) then return false end
self:GetWeapon():SetTargetEntity1( trace.Entity )
return true
end
function TOOL:RightClick( trace )
return self:LeftClick( trace )
end
function TOOL:Think()
local CurrentEditing = self:GetWeapon():GetTargetEntity1()
if ( CLIENT && self.LastEditing != CurrentEditing ) then
self.LastEditing = CurrentEditing
local CPanel = controlpanel.Get( "editentity" )
if ( !CPanel ) then return end
CPanel:Clear()
self.BuildCPanel( CPanel, CurrentEditing )
end
end
function TOOL.BuildCPanel( CPanel, ent )
local control = vgui.Create( "DEntityProperties" )
control:SetEntity( ent )
control:SetSize( 10, 500 )
CPanel:AddPanel( control )
end

View File

@@ -0,0 +1,132 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.elastic.name"
TOOL.ClientConVar[ "constant" ] = "500"
TOOL.ClientConVar[ "damping" ] = "3"
TOOL.ClientConVar[ "rdamping" ] = "0.01"
TOOL.ClientConVar[ "material" ] = "cable/cable"
TOOL.ClientConVar[ "width" ] = "2"
TOOL.ClientConVar[ "stretch_only" ] = "1"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local width = self:GetClientNumber( "width" )
local material = self:GetClientInfo( "material" )
local damping = self:GetClientNumber( "damping" )
local rdamping = self:GetClientNumber( "rdamping" )
local constant = self:GetClientNumber( "constant" )
local stretchonly = self:GetClientNumber( "stretch_only" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
-- Create the constraint
local constr, rope = constraint.Elastic( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, constant, damping, rdamping, material, width, stretchonly, Color( colorR, colorG, colorB ) )
-- Create an undo if the constraint was created
if ( IsValid( constr ) ) then
undo.Create( "Elastic" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.elastic.name" )
undo.Finish( "#tool.elastic.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Elastic" )
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.elastic.help" )
CPanel:ToolPresets( "elastic", ConVarsDefault )
CPanel:NumSlider( "#tool.elastic.constant", "elastic_constant", 0, 4000 )
CPanel:ControlHelp( "#tool.elastic.constant.help" )
CPanel:NumSlider( "#tool.elastic.damping", "elastic_damping", 0, 50 )
CPanel:ControlHelp( "#tool.elastic.damping.help" )
CPanel:NumSlider( "#tool.elastic.rdamping", "elastic_rdamping", 0, 1 )
CPanel:ControlHelp( "#tool.elastic.rdamping.help" )
CPanel:CheckBox( "#tool.elastic.stretchonly", "elastic_stretch_only" )
CPanel:ControlHelp( "#tool.elastic.stretchonly.help" )
CPanel:NumSlider( "#tool.elastic.width", "elastic_width", 0, 20 )
CPanel:RopeSelect( "elastic_material" )
CPanel:ColorPicker( "#tool.elastic.color", "elastic_color_r", "elastic_color_g", "elastic_color_b" )
end

View File

@@ -0,0 +1,206 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.emitter.name"
TOOL.ClientConVar[ "key" ] = "51"
TOOL.ClientConVar[ "delay" ] = "1"
TOOL.ClientConVar[ "toggle" ] = "1"
TOOL.ClientConVar[ "starton" ] = "0"
TOOL.ClientConVar[ "effect" ] = "sparks"
TOOL.ClientConVar[ "scale" ] = "1"
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
cleanup.Register( "emitters" )
function TOOL:LeftClick( trace, worldweld )
if ( trace.Entity && trace.Entity:IsPlayer() ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
if ( CLIENT ) then return true end
local ply = self:GetOwner()
local key = self:GetClientNumber( "key" )
local effect = self:GetClientInfo( "effect" )
local toggle = self:GetClientNumber( "toggle" ) == 1
local starton = self:GetClientNumber( "starton" ) == 1
local scale = math.Clamp( self:GetClientNumber( "scale" ), 0.1, 6 )
local delay = math.Clamp( self:GetClientNumber( "delay" ), 0.05, 20 )
-- We shot an existing emitter - just change its values
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_emitter" && trace.Entity.pl == ply ) then
trace.Entity:SetEffect( effect )
trace.Entity:SetDelay( delay )
trace.Entity:SetToggle( toggle )
trace.Entity:SetScale( scale )
numpad.Remove( trace.Entity.NumDown )
numpad.Remove( trace.Entity.NumUp )
trace.Entity.NumDown = numpad.OnDown( ply, key, "Emitter_On", trace.Entity )
trace.Entity.NumUp = numpad.OnUp( ply, key, "Emitter_Off", trace.Entity )
trace.Entity.key = key
return true
end
if ( !self:GetWeapon():CheckLimit( "emitters" ) ) then return false end
local pos = trace.HitPos
local shouldWeld = ( trace.Entity != NULL && ( !trace.Entity:IsWorld() or worldweld ) )
if ( !shouldWeld ) then
pos = pos + trace.HitNormal
end
local ang = trace.HitNormal:Angle()
ang:RotateAroundAxis( trace.HitNormal, 0 )
local emitter = MakeEmitter( ply, key, delay, toggle, effect, starton, nil, scale, { Pos = pos, Angle = ang } )
if ( !IsValid( emitter ) ) then return false end
undo.Create( "gmod_emitter" )
undo.AddEntity( emitter )
-- Don't weld to world
if ( shouldWeld ) then
local weld = constraint.Weld( emitter, trace.Entity, 0, trace.PhysicsBone, 0, true, true )
if ( IsValid( weld ) ) then
ply:AddCleanup( "emitters", weld )
undo.AddEntity( weld )
end
if ( IsValid( emitter:GetPhysicsObject() ) ) then emitter:GetPhysicsObject():EnableCollisions( false ) end
emitter.nocollide = true
end
undo.SetPlayer( ply )
undo.Finish()
return true
end
function TOOL:RightClick( trace )
return self:LeftClick( trace, true )
end
if ( SERVER ) then
function MakeEmitter( ply, key, delay, toggle, effect, starton, nocollide, scale, Data )
if ( IsValid( ply ) && !ply:CheckLimit( "emitters" ) ) then return NULL end
local emitter = ents.Create( "gmod_emitter" )
if ( !IsValid( emitter ) ) then return NULL end
duplicator.DoGeneric( emitter, Data )
emitter:SetEffect( effect )
emitter:SetPlayer( ply )
emitter:SetDelay( delay )
emitter:SetToggle( toggle )
emitter:SetOn( starton )
emitter:SetScale( scale or 1 )
emitter:Spawn()
DoPropSpawnedEffect( emitter )
duplicator.DoGenericPhysics( emitter, ply, Data )
emitter.NumDown = numpad.OnDown( ply, key, "Emitter_On", emitter )
emitter.NumUp = numpad.OnUp( ply, key, "Emitter_Off", emitter )
if ( nocollide && IsValid( emitter:GetPhysicsObject() ) ) then
emitter:GetPhysicsObject():EnableCollisions( false )
end
local ttable = {
key = key,
delay = delay,
toggle = toggle,
effect = effect,
pl = ply,
nocollide = nocollide,
starton = starton,
scale = scale
}
table.Merge( emitter:GetTable(), ttable )
if ( IsValid( ply ) ) then
ply:AddCount( "emitters", emitter )
ply:AddCleanup( "emitters", emitter )
end
return emitter
end
duplicator.RegisterEntityClass( "gmod_emitter", MakeEmitter, "key", "delay", "toggle", "effect", "starton", "nocollide", "scale", "Data" )
end
function TOOL:UpdateGhostEmitter( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit or IsValid( trace.Entity ) && ( trace.Entity:GetClass() == "gmod_emitter" or trace.Entity:IsPlayer() ) ) then
ent:SetNoDraw( true )
return
end
ent:SetPos( trace.HitPos )
ent:SetAngles( trace.HitNormal:Angle() )
ent:SetNoDraw( false )
end
function TOOL:Think()
if ( !IsValid( self.GhostEntity ) or self.GhostEntity:GetModel() != "models/props_lab/tpplug.mdl" ) then
self:MakeGhostEntity( "models/props_lab/tpplug.mdl", vector_origin, angle_zero )
end
self:UpdateGhostEmitter( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.emitter.desc" )
CPanel:ToolPresets( "emitter", ConVarsDefault )
CPanel:KeyBinder( "#tool.emitter.key", "emitter_key" )
CPanel:NumSlider( "#tool.emitter.delay", "emitter_delay", 0.01, 2 )
CPanel:NumSlider( "#tool.emitter.scale", "emitter_scale", 0, 6 )
CPanel:ControlHelp( "#tool.emitter.scale.help" )
CPanel:CheckBox( "#tool.emitter.toggle", "emitter_toggle" )
CPanel:CheckBox( "#tool.emitter.starton", "emitter_starton" )
local matselect = CPanel:MatSelect( "emitter_effect", nil, true, 0.25, 0.25 )
for k, v in pairs( list.Get( "EffectType" ) ) do
matselect:AddMaterialEx( v.print, v.material or "gui/effects/default.png", k, { emitter_effect = k } )
end
CPanel:AddItem( matselect )
end

View File

@@ -0,0 +1,39 @@
-- Remove this to add it to the menu
TOOL.AddToMenu = false
-- Define these!
TOOL.Category = "My Category" -- Name of the category
TOOL.Name = "#tool.example.name" -- Name to display. # means it will be translated ( see below )
if ( true ) then return end -- Don't actually run anything below, remove this to make everything below functional
if ( CLIENT ) then -- We can only use language.Add on client
language.Add( "tool.example.name", "My example tool" ) -- Add translation
end
-- An example clientside convar
TOOL.ClientConVar[ "CLIENTSIDE" ] = "default"
-- An example serverside convar
TOOL.ServerConVar[ "SERVERSIDE" ] = "default"
-- This function/hook is called when the player presses their left click
function TOOL:LeftClick( trace )
Msg( "PRIMARY FIRE\n" )
end
-- This function/hook is called when the player presses their right click
function TOOL:RightClick( trace )
Msg( "ALT FIRE\n" )
end
-- This function/hook is called when the player presses their reload key
function TOOL:Reload( trace )
-- The SWEP doesn't reload so this does nothing :(
Msg( "RELOAD\n" )
end
-- This function/hook is called every frame on client and every tick on the server
function TOOL:Think()
end

View File

@@ -0,0 +1,335 @@
TOOL.Category = "Poser"
TOOL.Name = "#tool.eyeposer.name"
TOOL.Information = {
{ name = "left" },
{ name = "left_use" },
{ name = "right" },
{ name = "reload" },
}
TOOL.ClientConVar[ "x" ] = "0"
TOOL.ClientConVar[ "y" ] = "0"
TOOL.ClientConVar[ "strabismus" ] = "0"
local function SetEyeTarget( ply, ent, data )
if ( data.EyeTarget ) then ent:SetEyeTarget( data.EyeTarget ) end
if ( SERVER ) then
if ( data.EyeTarget == vector_origin ) then
duplicator.ClearEntityModifier( ent, "eyetarget" )
else
duplicator.StoreEntityModifier( ent, "eyetarget", data )
end
end
end
if ( SERVER ) then
duplicator.RegisterEntityModifier( "eyetarget", SetEyeTarget )
end
local function ConvertRelativeToEyesAttachment( ent, pos )
if ( ent:IsNPC() ) then return pos end
-- Convert relative to eye attachment
local eyeattachment = ent:LookupAttachment( "eyes" )
if ( eyeattachment == 0 ) then return end
local attachment = ent:GetAttachment( eyeattachment )
if ( !attachment ) then return end
return WorldToLocal( pos, angle_zero, attachment.Pos, attachment.Ang )
end
function TOOL:CalculateEyeTarget()
local x = math.Remap( self:GetClientNumber( "x" ), 0, 1, -1, 1 )
local y = math.Remap( self:GetClientNumber( "y" ), 0, 1, -1, 1 )
local fwd = Angle( y * 45, x * 45, 0 ):Forward()
local s = math.Clamp( self:GetClientNumber( "strabismus" ), -1, 1 )
local distance = 1000
if ( s < 0 ) then
s = math.Remap( s, -1, 0, 0, 1 )
distance = distance * math.pow( 10000, s - 1 )
elseif ( s > 0 ) then
distance = distance * -math.pow( 10000, -s )
end
-- Gotta do this for NPCs...
local ent = self:GetSelectedEntity()
if ( IsValid( ent ) and ent:IsNPC() ) then
local eyeattachment = ent:LookupAttachment( "eyes" )
if ( eyeattachment == 0 ) then return fwd * distance end
local attachment = ent:GetAttachment( eyeattachment )
if ( !attachment ) then return fwd * distance end
return LocalToWorld( fwd * distance, angle_zero, attachment.Pos, attachment.Ang )
end
return fwd * distance
end
function TOOL:GetSelectedEntity()
return self:GetWeapon():GetNWEntity( "eyeposer_ent" )
end
function TOOL:SetSelectedEntity( ent )
if ( !IsValid( ent ) ) then self:SetOperation( 0 ) end
if ( IsValid( ent ) and ent:GetClass() == "prop_effect" ) then ent = ent.AttachedEntity end
return self:GetWeapon():SetNWEntity( "eyeposer_ent", ent )
end
-- Selects entity and aims their eyes
function TOOL:LeftClick( trace )
if ( self:GetOwner():KeyDown( IN_USE ) ) then
return self:MakeLookAtMe( trace )
end
if ( !IsValid( self:GetSelectedEntity() ) or self:GetOperation() != 1 ) then
self:SetSelectedEntity( trace.Entity )
if ( !IsValid( self:GetSelectedEntity() ) ) then return false end
local eyeAtt = self:GetSelectedEntity():LookupAttachment( "eyes" )
if ( eyeAtt == 0 ) then
self:SetSelectedEntity( NULL )
return false
end
self:SetOperation( 1 ) -- For UI
return true
end
local selectedEnt = self:GetSelectedEntity()
self:SetSelectedEntity( NULL )
self:SetOperation( 0 )
if ( !IsValid( selectedEnt ) ) then return false end
local LocalPos = ConvertRelativeToEyesAttachment( selectedEnt, trace.HitPos )
if ( !LocalPos ) then return false end
SetEyeTarget( self:GetOwner(), selectedEnt, { EyeTarget = LocalPos } )
return true
end
-- Select the eyes for posing through UI
function TOOL:RightClick( trace )
local hadEntity = IsValid( self:GetSelectedEntity() )
self:SetSelectedEntity( trace.Entity )
if ( !IsValid( self:GetSelectedEntity() ) ) then return hadEntity end
local eyeAtt = self:GetSelectedEntity():LookupAttachment( "eyes" )
if ( eyeAtt == 0 ) then
self:SetSelectedEntity( NULL )
return false
end
-- TODO: Reset? Save and load these raw values from the entity modifier?
--RunConsoleCommand( "eyeposer_x", 0.5 )
--RunConsoleCommand( "eyeposer_y", 0.5 )
--RunConsoleCommand( "eyeposer_strabismus", 0 )
self:SetOperation( 2 ) -- For UI
return true
end
-- Makes the eyes look at the player
function TOOL:MakeLookAtMe( trace )
self:SetSelectedEntity( NULL )
self:SetOperation( 0 )
local ent = trace.Entity
if ( IsValid( ent ) and ent:GetClass() == "prop_effect" ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end
if ( CLIENT ) then return true end
local pos = self:GetOwner():EyePos()
local LocalPos = ConvertRelativeToEyesAttachment( ent, pos )
if ( !LocalPos ) then return false end
SetEyeTarget( self:GetOwner(), ent, { EyeTarget = LocalPos } )
return true
end
-- Reset eye position
function TOOL:Reload( trace )
self:SetSelectedEntity( NULL )
self:SetOperation( 0 )
local ent = trace.Entity
if ( IsValid( ent ) and ent:GetClass() == "prop_effect" ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end
if ( CLIENT ) then return true end
SetEyeTarget( self:GetOwner(), ent, { EyeTarget = vector_origin } )
return true
end
local validEntityLast = false
function TOOL:Think()
local ent = self:GetSelectedEntity()
-- If we're on the client just make sure the context menu is up to date
if ( CLIENT ) then
if ( IsValid( ent ) == validEntityLast ) then return end
validEntityLast = IsValid( ent )
self:RebuildControlPanel( validEntityLast )
return
end
if ( !IsValid( ent ) ) then self:SetOperation( 0 ) return end
if ( self:GetOperation() != 2 ) then return end
-- On the server we continually set the eye position
SetEyeTarget( self:GetOwner(), ent, { EyeTarget = self:CalculateEyeTarget() } )
end
-- The rest of the code is clientside only, it is not used on server
if ( SERVER ) then return end
local SelectionRing = surface.GetTextureID( "gui/faceposer_indicator" )
-- Draw a box indicating the face we have selected
function TOOL:DrawHUD()
local selected = self:GetSelectedEntity()
if ( !IsValid( selected ) ) then return end
local eyeattachment = selected:LookupAttachment( "eyes" )
if ( eyeattachment == 0 ) then return end
local attachment = selected:GetAttachment( eyeattachment )
local scrpos = attachment.Pos:ToScreen()
if ( !scrpos.visible ) then return end
if ( self:GetOperation() == 1 ) then
-- Get Target
local trace = self:GetOwner():GetEyeTrace()
-- Clientside preview
local LocalPos = ConvertRelativeToEyesAttachment( selected, trace.HitPos )
if ( LocalPos ) then
selected:SetEyeTarget( LocalPos )
end
-- Try to get each eye position.. this is a real guess and won't work on non-humans
local Leye = ( attachment.Pos + attachment.Ang:Right() * 1.5 ):ToScreen()
local Reye = ( attachment.Pos - attachment.Ang:Right() * 1.5 ):ToScreen()
-- TODO: make the line look less like ass
local scrhit = trace.HitPos:ToScreen()
local x = scrhit.x
local y = scrhit.y
surface.SetDrawColor( 0, 0, 0, 100 )
surface.DrawLine( Leye.x - 1, Leye.y + 1, x - 1, y + 1 )
surface.DrawLine( Leye.x - 1, Leye.y - 1, x - 1, y - 1 )
surface.DrawLine( Leye.x + 1, Leye.y + 1, x + 1, y + 1 )
surface.DrawLine( Leye.x + 1, Leye.y - 1, x + 1, y - 1 )
surface.DrawLine( Reye.x - 1, Reye.y + 1, x - 1, y + 1 )
surface.DrawLine( Reye.x - 1, Reye.y - 1, x - 1, y - 1 )
surface.DrawLine( Reye.x + 1, Reye.y + 1, x + 1, y + 1 )
surface.DrawLine( Reye.x + 1, Reye.y - 1, x + 1, y - 1 )
surface.SetDrawColor( 0, 255, 0, 255 )
surface.DrawLine( Leye.x, Leye.y, x, y )
surface.DrawLine( Leye.x, Leye.y - 1, x, y - 1 )
surface.DrawLine( Reye.x, Reye.y, x, y )
surface.DrawLine( Reye.x, Reye.y - 1, x, y - 1 )
end
if ( self:GetOperation() == 2 ) then
-- Clientside preview
--selected:SetEyeTarget( self:CalculateEyeTarget() )
-- Work out the side distance to give a rough headsize box..
local player_eyes = LocalPlayer():EyeAngles()
local side = ( attachment.Pos + player_eyes:Right() * 20 ):ToScreen()
local size = math.abs( side.x - scrpos.x )
-- Draw the selection ring
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( SelectionRing )
surface.DrawTexturedRect( scrpos.x - size, scrpos.y - size, size * 2, size * 2 )
end
end
function TOOL.BuildCPanel( CPanel, hasEntity )
CPanel:Help( "#tool.eyeposer.desc" )
if ( hasEntity ) then
-- Panel for Slider ( limiting edge )
local SliderBackground = vgui.Create( "DPanel", CPanel )
SliderBackground:Dock( TOP )
SliderBackground:SetTall( 225 )
CPanel:AddItem( SliderBackground )
-- 2 axis slider for the eye position
local EyeSlider = vgui.Create( "DSlider", SliderBackground )
EyeSlider:Dock( FILL )
EyeSlider:SetLockY()
EyeSlider:SetSlideX( 0.5 )
EyeSlider:SetSlideY( 0.5 )
EyeSlider:SetTrapInside( true )
EyeSlider:SetConVarX( "eyeposer_x" )
EyeSlider:SetConVarY( "eyeposer_y" )
-- Draw the 'button' different from the slider
EyeSlider.Knob.Paint = function( panel, w, h ) derma.SkinHook( "Paint", "Button", panel, w, h ) end
function EyeSlider:Paint( w, h )
local knobX, knobY = self.Knob:GetPos()
local knobW, knobH = self.Knob:GetSize()
surface.SetDrawColor( 0, 0, 0, 250 )
surface.DrawLine( knobX + knobW / 2, knobY + knobH / 2, w / 2, h / 2 )
surface.DrawRect( w / 2 - 2, h / 2 - 2, 5, 5 )
end
CPanel:NumSlider( "#tool.eyeposer.strabismus", "eyeposer_strabismus", -1, 1 )
end
CPanel:NumSlider( "#tool.eyeposer.size_eyes", "r_eyesize", -0.5, 2 )
CPanel:ControlHelp( "#tool.eyeposer.size_eyes.help" )
end

View File

@@ -0,0 +1,481 @@
TOOL.Category = "Poser"
TOOL.Name = "#tool.faceposer.name"
local MAXSTUDIOFLEXCTRL = 96
TOOL.FaceTimer = 0
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
local function IsUselessFaceFlex( strName )
if ( strName == "gesture_rightleft" ) then return true end
if ( strName == "gesture_updown" ) then return true end
if ( strName == "head_forwardback" ) then return true end
if ( strName == "chest_rightleft" ) then return true end
if ( strName == "body_rightleft" ) then return true end
if ( strName == "eyes_rightleft" ) then return true end
if ( strName == "eyes_updown" ) then return true end
if ( strName == "head_tilt" ) then return true end
if ( strName == "head_updown" ) then return true end
if ( strName == "head_rightleft" ) then return true end
return false
end
local function GenerateDefaultFlexValue( ent, flexID )
local min, max = ent:GetFlexBounds( flexID )
if ( !max || max - min == 0 ) then return 0 end
return ( 0 - min ) / ( max - min )
end
function TOOL:FacePoserEntity()
return self:GetWeapon():GetNWEntity( 1 )
end
function TOOL:SetFacePoserEntity( ent )
if ( IsValid( ent ) && ent:GetClass() == "prop_effect" ) then ent = ent.AttachedEntity end
return self:GetWeapon():SetNWEntity( 1, ent )
end
local LastFPEntity = NULL
local LastFPEntityValid = false
function TOOL:Think()
-- If we're on the client just make sure the context menu is up to date
if ( CLIENT ) then
if ( self:FacePoserEntity() == LastFPEntity && IsValid( LastFPEntity ) == LastFPEntityValid ) then return end
LastFPEntity = self:FacePoserEntity()
LastFPEntityValid = IsValid( LastFPEntity )
self:RebuildControlPanel( self:FacePoserEntity() )
return
end
-- On the server we continually set the flex weights
if ( self.FaceTimer > CurTime() ) then return end
local ent = self:FacePoserEntity()
if ( !IsValid( ent ) ) then return end
local FlexNum = ent:GetFlexNum()
if ( FlexNum <= 0 ) then return end
for i = 0, FlexNum do
local num = self:GetClientNumber( "flex" .. i )
ent:SetFlexWeight( i, num )
end
local num = self:GetClientNumber( "scale" )
ent:SetFlexScale( num )
end
--[[---------------------------------------------------------
Alt fire sucks the facepose from the model's face
-----------------------------------------------------------]]
function TOOL:RightClick( trace )
local ent = trace.Entity
if ( IsValid( ent ) && ent:GetClass() == "prop_effect" ) then ent = ent.AttachedEntity end
if ( SERVER ) then
self:SetFacePoserEntity( ent )
end
if ( !IsValid( ent ) ) then return true end
local FlexNum = ent:GetFlexNum()
if ( FlexNum == 0 ) then return false end
if ( SERVER ) then
-- This stops it applying the current sliders to the newly selected face..
-- it should probably be linked to the ping somehow.. but 1 second seems pretty safe
self.FaceTimer = CurTime() + 1
-- In multiplayer the rest is only done on the client to save bandwidth.
-- We can't do that in single player because these functions don't get called on the client
if ( !game.SinglePlayer() ) then return true end
end
for i = 0, FlexNum - 1 do
local Weight = 0
if ( !ent:HasFlexManipulatior() ) then
Weight = GenerateDefaultFlexValue( ent, i )
elseif ( i <= FlexNum ) then
Weight = ent:GetFlexWeight( i )
end
self:GetOwner():ConCommand( "faceposer_flex" .. i .. " " .. Weight )
end
self:GetOwner():ConCommand( "faceposer_scale " .. ent:GetFlexScale() )
return true
end
--[[---------------------------------------------------------
Just select as the current object
Current settings will get applied
-----------------------------------------------------------]]
function TOOL:LeftClick( trace )
local ent = trace.Entity
if ( IsValid( ent ) && ent:GetClass() == "prop_effect" ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end
if ( ent:GetFlexNum() == 0 ) then return false end
self.FaceTimer = 0
self:SetFacePoserEntity( ent )
return true
end
if ( SERVER ) then
local function CC_Face_Randomize( ply, command, arguments )
for i = 0, MAXSTUDIOFLEXCTRL do
local num = math.Rand( 0, 1 )
ply:ConCommand( "faceposer_flex" .. i .. " " .. string.format( "%.3f", num ) )
end
end
concommand.Add( "faceposer_randomize", CC_Face_Randomize )
end
-- The rest of the code is clientside only, it is not used on server
if ( SERVER ) then return end
for i = 0, MAXSTUDIOFLEXCTRL do
TOOL.ClientConVar[ "flex" .. i ] = "0"
end
TOOL.ClientConVar[ "scale" ] = "1.0"
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel, faceEntity )
CPanel:Help( "#tool.faceposer.desc" )
if ( !IsValid( faceEntity ) || faceEntity:GetFlexNum() == 0 ) then return end
CPanel:ToolPresets( "face", ConVarsDefault )
local QuickFace = vgui.Create( "MatSelect", CPanel )
QuickFace:SetItemWidth( 64 )
QuickFace:SetItemHeight( 32 )
QuickFace.List:SetSpacing( 1 )
QuickFace.List:SetPadding( 0 )
QuickFace:SetAutoHeight( true )
local Clear = {}
for i = 0, MAXSTUDIOFLEXCTRL do
Clear[ "faceposer_flex" .. i ] = GenerateDefaultFlexValue( faceEntity, i )
end
QuickFace:AddMaterialEx( "#faceposer.clear", "vgui/face/clear", nil, Clear )
-- Todo: These really need to be the name of the flex.
QuickFace:AddMaterialEx( "#faceposer.openeyes", "vgui/face/open_eyes", nil, {
faceposer_flex0 = "1",
faceposer_flex1 = "1",
faceposer_flex2 = "0",
faceposer_flex3 = "0",
faceposer_flex4 = "0",
faceposer_flex5 = "0",
faceposer_flex6 = "0",
faceposer_flex7 = "0",
faceposer_flex8 = "0",
faceposer_flex9 = "0"
} )
QuickFace:AddMaterialEx( "#faceposer.closeeyes", "vgui/face/close_eyes", nil, {
faceposer_flex0 = "0",
faceposer_flex1 = "0",
faceposer_flex2 = "1",
faceposer_flex3 = "1",
faceposer_flex4 = "1",
faceposer_flex5 = "1",
faceposer_flex6 = "1",
faceposer_flex7 = "1",
faceposer_flex8 = "1",
faceposer_flex9 = "1"
} )
QuickFace:AddMaterialEx( "#faceposer.angryeyebrows", "vgui/face/angry_eyebrows", nil, {
faceposer_flex10 = "0",
faceposer_flex11 = "0",
faceposer_flex12 = "1",
faceposer_flex13 = "1",
faceposer_flex14 = "0.5",
faceposer_flex15 = "0.5"
} )
QuickFace:AddMaterialEx( "#faceposer.normaleyebrows", "vgui/face/normal_eyebrows", nil, {
faceposer_flex10 = "0",
faceposer_flex11 = "0",
faceposer_flex12 = "0",
faceposer_flex13 = "0",
faceposer_flex14 = "0",
faceposer_flex15 = "0"
} )
QuickFace:AddMaterialEx( "#faceposer.sorryeyebrows", "vgui/face/sorry_eyebrows", nil, {
faceposer_flex10 = "1",
faceposer_flex11 = "1",
faceposer_flex12 = "0",
faceposer_flex13 = "0",
faceposer_flex14 = "0",
faceposer_flex15 = "0"
} )
QuickFace:AddMaterialEx( "#faceposer.grin", "vgui/face/grin", nil, {
faceposer_flex20 = "1",
faceposer_flex21 = "1",
faceposer_flex22 = "1",
faceposer_flex23 = "1",
faceposer_flex24 = "0",
faceposer_flex25 = "0",
faceposer_flex26 = "0",
faceposer_flex27 = "1",
faceposer_flex28 = "1",
faceposer_flex29 = "0",
faceposer_flex30 = "0",
faceposer_flex31 = "0",
faceposer_flex32 = "0",
faceposer_flex33 = "1",
faceposer_flex34 = "1",
faceposer_flex35 = "0",
faceposer_flex36 = "0",
faceposer_flex37 = "0",
faceposer_flex38 = "0",
faceposer_flex39 = "1",
faceposer_flex40 = "0",
faceposer_flex41 = "0",
faceposer_flex42 = "1",
faceposer_flex43 = "1"
} )
QuickFace:AddMaterialEx( "#faceposer.sad", "vgui/face/sad", nil, {
faceposer_flex20 = "0",
faceposer_flex21 = "0",
faceposer_flex22 = "0",
faceposer_flex23 = "0",
faceposer_flex24 = "1",
faceposer_flex25 = "1",
faceposer_flex26 = "0.0",
faceposer_flex27 = "0",
faceposer_flex28 = "0",
faceposer_flex29 = "0",
faceposer_flex30 = "0",
faceposer_flex31 = "0",
faceposer_flex32 = "0",
faceposer_flex33 = "0",
faceposer_flex34 = "0",
faceposer_flex35 = "0",
faceposer_flex36 = "0",
faceposer_flex37 = "0",
faceposer_flex38 = "0.5",
faceposer_flex39 = "0",
faceposer_flex40 = "0",
faceposer_flex41 = "0",
faceposer_flex42 = "0",
faceposer_flex43 = "0"
} )
QuickFace:AddMaterialEx( "#faceposer.smile", "vgui/face/smile", nil, {
faceposer_flex20 = "1",
faceposer_flex21 = "1",
faceposer_flex22 = "1",
faceposer_flex23 = "1",
faceposer_flex24 = "0",
faceposer_flex25 = "0",
faceposer_flex26 = "0",
faceposer_flex27 = "0.6",
faceposer_flex28 = "0.4",
faceposer_flex29 = "0",
faceposer_flex30 = "0",
faceposer_flex31 = "0",
faceposer_flex32 = "0",
faceposer_flex33 = "1",
faceposer_flex34 = "1",
faceposer_flex35 = "0",
faceposer_flex36 = "0",
faceposer_flex37 = "0",
faceposer_flex38 = "0",
faceposer_flex39 = "0",
faceposer_flex40 = "1",
faceposer_flex41 = "1",
faceposer_flex42 = "0",
faceposer_flex43 = "0",
faceposer_flex44 = "0",
} )
CPanel:AddItem( QuickFace )
CPanel:NumSlider( "#tool.faceposer.scale", "faceposer_scale", -5, 5 ):SetHeight( 16 )
CPanel:ControlHelp( "#tool.faceposer.scale.help" )
CPanel:Button( "#tool.faceposer.randomize", "faceposer_randomize" )
local filter = CPanel:TextEntry( "#spawnmenu.quick_filter_tool" )
filter:SetUpdateOnType( true )
-- Group flex controllers by their type..
local flexGroups = {}
for i = 0, faceEntity:GetFlexNum() - 1 do
local name = faceEntity:GetFlexName( i )
if ( !IsUselessFaceFlex( name ) ) then
local group = faceEntity:GetFlexType( i )
if ( group == name ) then group = language.GetPhrase( "#spawnmenu.category.other" ) end
local min, max = faceEntity:GetFlexBounds( i )
flexGroups[ group ] = flexGroups[ group ] or { sortId = table.Count( flexGroups ), items = {} }
table.insert( flexGroups[ group ].items, { name = name, id = i, min = min, max = max, default = GenerateDefaultFlexValue( faceEntity, i ) } )
end
end
local flexControllers = {}
local moreThanOneGroup = table.Count( flexGroups ) > 1
for group, groupData in SortedPairsByMemberValue( flexGroups, "sortId" ) do
local items = groupData.items
local groupForm = vgui.Create( "DForm", CPanel )
groupForm:SetLabel( string.NiceName( group ) )
-- Give the DForm a nice outline
groupForm.GetBackgroundColor = function() return color_white end
function groupForm:Paint( w, h )
derma.SkinHook( "Paint", "CategoryList", self, w, h )
derma.SkinHook( "Paint", "CollapsibleCategory", self, w, h )
end
CPanel:AddItem( groupForm )
for id, item in SortedPairsByMemberValue( items, "id" ) do
local ctrl = groupForm:NumSlider( string.NiceName( item.name ), "faceposer_flex" .. item.id, item.min, item.max )
ctrl:SetDefaultValue( item.default )
ctrl:SetHeight( 11 ) -- This makes the controls all bunched up like how we want
ctrl:DockPadding( 0, -6, 0, -4 ) -- Try to make the lower part of the text visible
ctrl.originalName = item.name
table.insert( flexControllers, ctrl )
if ( item.id >= MAXSTUDIOFLEXCTRL ) then
ctrl:SetEnabled( false )
ctrl:SetTooltip( "#tool.faceposer.too_many_flexes" )
end
end
-- Per category random/clear
if ( moreThanOneGroup ) then
local btnContainer = vgui.Create( "Panel", groupForm )
btnContainer:SetHeight( 22 )
local btnRnd = vgui.Create( "DButton", btnContainer )
btnRnd:SetText( "#tool.faceposer.randomize" )
btnRnd:Dock( FILL )
btnRnd.DoClick = function()
for id, item in pairs( items ) do
local num = math.Rand( item.min, item.max )
LocalPlayer():ConCommand( "faceposer_flex" .. item.id .. " " .. string.format( "%.2f", num ) )
end
end
local btnClear = vgui.Create( "DButton", btnContainer )
btnClear:SetText( "#faceposer.clear" )
btnClear:DockMargin( 8, 0, 0, 0 )
btnClear:Dock( RIGHT )
btnClear.DoClick = function()
for id, item in pairs( items ) do
LocalPlayer():ConCommand( "faceposer_flex" .. item.id .. " " .. string.format( "%.2f", item.default ) )
end
end
groupForm:AddItem( btnContainer )
end
-- HACK: Add some padding to the bottom of the list, because Dock won't
local padding = vgui.Create( "Panel", groupForm )
padding:SetHeight( 0 )
groupForm:AddItem( padding )
end
-- Actual searching
filter.OnValueChange = function( pnl, txt )
for id, flxpnl in ipairs( flexControllers ) do
if ( !flxpnl:GetText():lower():find( txt:lower(), nil, true ) && !flxpnl.originalName:lower():find( txt:lower(), nil, true ) ) then
flxpnl:SetVisible( false )
else
flxpnl:SetVisible( true )
end
flxpnl:InvalidateParent()
end
CPanel:InvalidateChildren()
end
end
local FacePoser = surface.GetTextureID( "gui/faceposer_indicator" )
-- Draw a box indicating the face we have selected
function TOOL:DrawHUD()
if ( GetConVarNumber( "gmod_drawtooleffects" ) == 0 ) then return end
local selected = self:FacePoserEntity()
if ( !IsValid( selected ) || selected:IsWorld() || selected:GetFlexNum() == 0 ) then return end
local pos = selected:GetPos()
local eyeattachment = selected:LookupAttachment( "eyes" )
if ( eyeattachment != 0 ) then
local attachment = selected:GetAttachment( eyeattachment )
pos = attachment.Pos
else
-- The model has no "eyes" attachment, try to find a bone with "head" in its name
for i = 0, selected:GetBoneCount() - 1 do
if ( selected:GetBoneName( i ) && selected:GetBoneName( i ):lower():find( "head" ) ) then
pos = selected:GetBonePosition( i )
end
end
end
local scrpos = pos:ToScreen()
if ( !scrpos.visible ) then return end
-- Work out the side distance to give a rough headsize box..
local player_eyes = LocalPlayer():EyeAngles()
local side = ( pos + player_eyes:Right() * 20 ):ToScreen()
local size = math.abs( side.x - scrpos.x )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( FacePoser )
surface.DrawTexturedRect( scrpos.x - size, scrpos.y - size, size * 2, size * 2 )
end

View File

@@ -0,0 +1,628 @@
TOOL.Category = "Poser"
TOOL.Name = "#tool.finger.name"
TOOL.RequiresTraceHit = true
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
local VarsOnHand = 15
-- Returns true if it has TF2 hands
local function HasTF2Hands( pEntity )
return pEntity:LookupBone( "bip_hand_L" ) != nil
end
-- Returns true if it has Portal 2 hands
local function HasP2Hands( pEntity )
return pEntity:LookupBone( "wrist_A_L" ) != nil || pEntity:LookupBone( "index_1_L" ) != nil
end
local TranslateTable_TF2 = {}
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger0" ] = "bip_thumb_0_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger01" ] = "bip_thumb_1_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger02" ] = "bip_thumb_2_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger1" ] = "bip_index_0_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger11" ] = "bip_index_1_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger12" ] = "bip_index_2_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger2" ] = "bip_middle_0_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger21" ] = "bip_middle_1_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger22" ] = "bip_middle_2_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger3" ] = "bip_ring_0_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger31" ] = "bip_ring_1_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger32" ] = "bip_ring_2_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger4" ] = "bip_pinky_0_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger41" ] = "bip_pinky_1_L"
TranslateTable_TF2[ "ValveBiped.Bip01_L_Finger42" ] = "bip_pinky_2_L"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger0" ] = "bip_thumb_0_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger01" ] = "bip_thumb_1_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger02" ] = "bip_thumb_2_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger1" ] = "bip_index_0_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger11" ] = "bip_index_1_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger12" ] = "bip_index_2_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger2" ] = "bip_middle_0_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger21" ] = "bip_middle_1_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger22" ] = "bip_middle_2_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger3" ] = "bip_ring_0_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger31" ] = "bip_ring_1_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger32" ] = "bip_ring_2_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger4" ] = "bip_pinky_0_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger41" ] = "bip_pinky_1_R"
TranslateTable_TF2[ "ValveBiped.Bip01_R_Finger42" ] = "bip_pinky_2_R"
local TranslateTable_Zeno = {}
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger0" ] = "Bip01_L_Finger0"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger01" ] = "Bip01_L_Finger01"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger02" ] = "Bip01_L_Finger02"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger1" ] = "Bip01_L_Finger1"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger11" ] = "Bip01_L_Finger11"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger12" ] = "Bip01_L_Finger12"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger2" ] = "Bip01_L_Finger2"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger21" ] = "Bip01_L_Finger21"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger22" ] = "Bip01_L_Finger22"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger3" ] = "Bip01_L_Finger3"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger31" ] = "Bip01_L_Finger31"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger32" ] = "Bip01_L_Finger32"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger4" ] = "Bip01_L_Finger4"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger41" ] = "Bip01_L_Finger41"
TranslateTable_Zeno[ "ValveBiped.Bip01_L_Finger42" ] = "Bip01_L_Finger42"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger0" ] = "Bip01_R_Finger0"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger01" ] = "Bip01_R_Finger01"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger02" ] = "Bip01_R_Finger02"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger1" ] = "Bip01_R_Finger1"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger11" ] = "Bip01_R_Finger11"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger12" ] = "Bip01_R_Finger12"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger2" ] = "Bip01_R_Finger2"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger21" ] = "Bip01_R_Finger21"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger22" ] = "Bip01_R_Finger22"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger3" ] = "Bip01_R_Finger3"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger31" ] = "Bip01_R_Finger31"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger32" ] = "Bip01_R_Finger32"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger4" ] = "Bip01_R_Finger4"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger41" ] = "Bip01_R_Finger41"
TranslateTable_Zeno[ "ValveBiped.Bip01_R_Finger42" ] = "Bip01_R_Finger42"
local TranslateTable_INS = {}
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger0" ] = "L Finger0"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger01" ] = "L Finger01"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger02" ] = "L Finger02"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger1" ] = "L Finger1"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger11" ] = "L Finger11"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger12" ] = "L Finger12"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger2" ] = "L Finger2"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger21" ] = "L Finger21"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger22" ] = "L Finger22"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger3" ] = "L Finger3"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger31" ] = "L Finger31"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger32" ] = "L Finger32"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger4" ] = "L Finger4"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger41" ] = "L Finger41"
TranslateTable_INS[ "ValveBiped.Bip01_L_Finger42" ] = "L Finger42"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger0" ] = "R Finger0"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger01" ] = "R Finger01"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger02" ] = "R Finger02"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger1" ] = "R Finger1"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger11" ] = "R Finger11"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger12" ] = "R Finger12"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger2" ] = "R Finger2"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger21" ] = "R Finger21"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger22" ] = "R Finger22"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger3" ] = "R Finger3"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger31" ] = "R Finger31"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger32" ] = "R Finger32"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger4" ] = "R Finger4"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger41" ] = "R Finger41"
TranslateTable_INS[ "ValveBiped.Bip01_R_Finger42" ] = "R Finger42"
local TranslateTable_Chell = {}
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger0" ] = "thumb_base_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger01" ] = "thumb_mid_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger02" ] = "thumb_end_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger1" ] = "index_base_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger11" ] = "index_mid_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger12" ] = "index_end_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger2" ] = "mid_base_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger21" ] = "mid_mid_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger22" ] = "mid_end_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger3" ] = "ring_base_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger31" ] = "ring_mid_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger32" ] = "ring_end_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger4" ] = "pinky_base_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger41" ] = "pinky_mid_L"
TranslateTable_Chell[ "ValveBiped.Bip01_L_Finger42" ] = "pinky_end_L"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger0" ] = "thumb_base_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger01" ] = "thumb_mid_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger02" ] = "thumb_end_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger1" ] = "index_base_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger11" ] = "index_mid_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger12" ] = "index_end_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger2" ] = "mid_base_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger21" ] = "mid_mid_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger22" ] = "mid_end_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger3" ] = "ring_base_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger31" ] = "ring_mid_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger32" ] = "ring_end_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger4" ] = "pinky_base_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger41" ] = "pinky_mid_R"
TranslateTable_Chell[ "ValveBiped.Bip01_R_Finger42" ] = "pinky_end_R"
local TranslateTable_EggBot = {}
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger0" ] = "thumb2_0_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger01" ] = "thumb2_1_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger02" ] = "thumb2_2_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger1" ] = "index2_0_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger11" ] = "index2_1_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger12" ] = "index2_2_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger2" ] = "mid2_0_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger21" ] = "mid2_1_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_L_Finger22" ] = "mid2_2_A_L"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger0" ] = "thumb3_0_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger01" ] = "thumb3_1_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger02" ] = "thumb3_2_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger1" ] = "index3_0_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger11" ] = "index3_1_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger12" ] = "index3_2_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger2" ] = "mid3_0_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger21" ] = "mid3_1_A_R"
TranslateTable_EggBot[ "ValveBiped.Bip01_R_Finger22" ] = "mid3_2_A_R"
local TranslateTable_Poral2 = {}
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger0" ] = "thumb_0_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger01" ] = "thumb_1_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger02" ] = "thumb_2_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger1" ] = "index_0_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger11" ] = "index_1_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger12" ] = "index_2_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger2" ] = "mid_0_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger21" ] = "mid_1_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger22" ] = "mid_2_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger3" ] = "ring_0_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger31" ] = "ring_1_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_L_Finger32" ] = "ring_2_L"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger0" ] = "thumb_0_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger01" ] = "thumb_1_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger02" ] = "thumb_2_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger1" ] = "index_0_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger11" ] = "index_1_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger12" ] = "index_2_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger2" ] = "mid_0_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger21" ] = "mid_1_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger22" ] = "mid_2_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger3" ] = "ring_0_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger31" ] = "ring_1_R"
TranslateTable_Poral2[ "ValveBiped.Bip01_R_Finger32" ] = "ring_2_R"
local TranslateTable_DOG = {}
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger0" ] = "Dog_Model.Thumb1_L"
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger01" ] = "Dog_Model.Thumb2_L"
--TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger02" ] = "Dog_Model.Thumb3_L"
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger1" ] = "Dog_Model.Index1_L"
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger11" ] = "Dog_Model.Index2_L"
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger12" ] = "Dog_Model.Index3_L"
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger4" ] = "Dog_Model.Pinky1_L"
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger41" ] = "Dog_Model.Pinky2_L"
TranslateTable_DOG[ "ValveBiped.Bip01_L_Finger42" ] = "Dog_Model.Pinky3_L"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger0" ] = "Dog_Model.Thumb1_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger01" ] = "Dog_Model.Thumb2_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger02" ] = "Dog_Model.Thumb3_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger1" ] = "Dog_Model.Index1_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger11" ] = "Dog_Model.Index2_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger12" ] = "Dog_Model.Index3_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger4" ] = "Dog_Model.Pinky1_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger41" ] = "Dog_Model.Pinky2_R"
TranslateTable_DOG[ "ValveBiped.Bip01_R_Finger42" ] = "Dog_Model.Pinky3_R"
local TranslateTable_VORT = {}
TranslateTable_VORT[ "ValveBiped.Bip01_L_Finger1" ] = "ValveBiped.index1_L"
TranslateTable_VORT[ "ValveBiped.Bip01_L_Finger11" ] = "ValveBiped.index2_L"
TranslateTable_VORT[ "ValveBiped.Bip01_L_Finger12" ] = "ValveBiped.index3_L"
TranslateTable_VORT[ "ValveBiped.Bip01_L_Finger4" ] = "ValveBiped.pinky1_L"
TranslateTable_VORT[ "ValveBiped.Bip01_L_Finger41" ] = "ValveBiped.pinky2_L"
TranslateTable_VORT[ "ValveBiped.Bip01_L_Finger42" ] = "ValveBiped.pinky3_L"
TranslateTable_VORT[ "ValveBiped.Bip01_R_Finger1" ] = "ValveBiped.index1_R"
TranslateTable_VORT[ "ValveBiped.Bip01_R_Finger11" ] = "ValveBiped.index2_R"
TranslateTable_VORT[ "ValveBiped.Bip01_R_Finger12" ] = "ValveBiped.index3_R"
TranslateTable_VORT[ "ValveBiped.Bip01_R_Finger4" ] = "ValveBiped.pinky1_R"
TranslateTable_VORT[ "ValveBiped.Bip01_R_Finger41" ] = "ValveBiped.pinky2_R"
TranslateTable_VORT[ "ValveBiped.Bip01_R_Finger42" ] = "ValveBiped.pinky3_R"
function TOOL:HandEntity()
return self:GetWeapon():GetNWEntity( "HandEntity" )
end
function TOOL:HandNum()
return self:GetWeapon():GetNWInt( "HandNum" )
end
function TOOL:SetHand( ent, iHand )
self:GetWeapon():SetNWEntity( "HandEntity", ent )
self:GetWeapon():SetNWInt( "HandNum", iHand )
end
-- Translate the fingernum, part and hand into an real bone number
local function GetFingerBone( self, fingernum, part, hand )
---- START HL2 BONE LOOKUP ----------------------------------
local Name = "ValveBiped.Bip01_L_Finger" .. fingernum
if ( hand == 1 ) then Name = "ValveBiped.Bip01_R_Finger" .. fingernum end
if ( part != 0 ) then Name = Name .. part end
local boneid = self:LookupBone( Name )
if ( boneid ) then return boneid end
---- END HL2 BONE LOOKUP ----------------------------------
---- START TF BONE LOOKUP ----------------------------------
local TranslatedName = TranslateTable_TF2[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END TF BONE LOOKUP ----------------------------------
---- START Zeno BONE LOOKUP ----------------------------------
TranslatedName = TranslateTable_Zeno[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END Zeno BONE LOOKUP ----------------------------------
---- START DOG BONE LOOKUP ----------------------------------
TranslatedName = TranslateTable_DOG[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END DOG BONE LOOKUP ----------------------------------
---- START VORT BONE LOOKUP ----------------------------------
TranslatedName = TranslateTable_VORT[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END VORT BONE LOOKUP ----------------------------------
---- START Chell BONE LOOKUP ----------------------------------
TranslatedName = TranslateTable_Chell[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END Chell BONE LOOKUP ----------------------------------
---- START EggBot ( Portal 2 ) BONE LOOKUP ----------------------------------
TranslatedName = TranslateTable_EggBot[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END EggBot BONE LOOKUP ----------------------------------
---- START Portal 2 ( Ball Bot ) BONE LOOKUP ----------------------------------
TranslatedName = TranslateTable_Poral2[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END Portal 2 BONE LOOKUP ----------------------------------
---- START Ins BONE LOOKUP ----------------------------------
TranslatedName = TranslateTable_INS[ Name ]
if ( TranslatedName ) then
local bone = self:LookupBone( TranslatedName )
if ( bone ) then return bone end
end
---- END Insurgency BONE LOOKUP ----------------------------------
end
-- Cache the finger bone numbers for faster access
local function SetupFingers( self )
if ( self.FingerIndex ) then return end
self.FingerIndex = {}
local i = 1
for hand = 0, 1 do
for finger = 0, 4 do
for part = 0, 2 do
self.FingerIndex[ i ] = GetFingerBone( self, finger, part, hand )
i = i + 1
end
end
end
end
-- Apply the current tool values to entity's hand
function TOOL:ApplyValues( pEntity, iHand )
if ( CLIENT ) then return end
SetupFingers( pEntity )
local bTF2 = HasTF2Hands( pEntity )
local bP2 = HasP2Hands( pEntity )
for i = 0, VarsOnHand - 1 do
local Var = self:GetClientInfo( i )
local VecComp = string.Explode( " ", Var )
local Ang = nil
if ( bP2 ) then
if ( i < 3 ) then
Ang = Angle( tonumber( VecComp[1] ), tonumber( VecComp[2] ), 0 )
else
Ang = Angle( -tonumber( VecComp[2] ), tonumber( VecComp[1] ), 0 )
end
elseif ( bTF2 ) then
if ( i < 3 ) then
Ang = Angle( 0, tonumber( VecComp[2] ), tonumber( VecComp[1] ) )
else
Ang = Angle( 0, tonumber( VecComp[1] ), -tonumber( VecComp[2] ) )
end
else
if ( i < 3 ) then
Ang = Angle( tonumber( VecComp[2] ), tonumber( VecComp[1] ), 0 )
else
Ang = Angle( tonumber( VecComp[1] ), tonumber( VecComp[2] ), 0 )
end
end
local bone = pEntity.FingerIndex[ i + iHand * VarsOnHand + 1 ]
if ( bone ) then
pEntity:ManipulateBoneAngles( bone, Ang )
end
end
end
-- Hope we don't have any one armed models
function TOOL:GetHandPositions( pEntity )
local LeftHand = pEntity:LookupBone( "ValveBiped.Bip01_L_Hand" )
if ( !LeftHand ) then LeftHand = pEntity:LookupBone( "bip_hand_L" ) end
if ( !LeftHand ) then LeftHand = pEntity:LookupBone( "Bip01_L_Hand" ) end
if ( !LeftHand ) then LeftHand = pEntity:LookupBone( "Dog_Model.Hand_L" ) end -- DOG
if ( !LeftHand ) then LeftHand = pEntity:LookupBone( "ValveBiped.Hand1_L" ) end -- Vortigaunt
if ( !LeftHand ) then LeftHand = pEntity:LookupBone( "wrist_L" ) end -- Chell
if ( !LeftHand ) then LeftHand = pEntity:LookupBone( "L Hand" ) end -- Insurgency
if ( !LeftHand ) then LeftHand = pEntity:LookupBone( "wrist_A_L" ) end -- Portal 2 Egg bot
local RightHand = pEntity:LookupBone( "ValveBiped.Bip01_R_Hand" )
if ( !RightHand ) then RightHand = pEntity:LookupBone( "bip_hand_R" ) end
if ( !RightHand ) then RightHand = pEntity:LookupBone( "Bip01_R_Hand" ) end
if ( !RightHand ) then RightHand = pEntity:LookupBone( "Bip01_R_Hand" ) end
if ( !RightHand ) then RightHand = pEntity:LookupBone( "Dog_Model.Hand_R" ) end
if ( !RightHand ) then RightHand = pEntity:LookupBone( "ValveBiped.Hand1_R" ) end
if ( !RightHand ) then RightHand = pEntity:LookupBone( "wrist_R" ) end
if ( !RightHand ) then RightHand = pEntity:LookupBone( "R Hand" ) end
if ( !RightHand ) then RightHand = pEntity:LookupBone( "wrist_A_R" ) end
if ( !LeftHand || !RightHand ) then return false end
local LeftHandMatrix = pEntity:GetBoneMatrix( LeftHand )
local RightHandMatrix = pEntity:GetBoneMatrix( RightHand )
if ( !LeftHandMatrix || !RightHandMatrix ) then return false end
return LeftHandMatrix, RightHandMatrix
end
-- Applies current convar hand to picked hand
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
--if ( trace.Entity:GetClass() != "prop_ragdoll" && !trace.Entity:IsNPC() ) then return false end
local LeftHandMatrix, RightHandMatrix = self:GetHandPositions( trace.Entity )
if ( !LeftHandMatrix ) then return false end
if ( CLIENT ) then return true end
local LeftHand = ( LeftHandMatrix:GetTranslation() - trace.HitPos ):Length()
local RightHand = ( RightHandMatrix:GetTranslation() - trace.HitPos ):Length()
if ( LeftHand < RightHand ) then
self:ApplyValues( trace.Entity, 0 )
else
self:ApplyValues( trace.Entity, 1 )
end
return true
end
-- Selects picked hand and sucks off convars
function TOOL:RightClick( trace )
local ent = trace.Entity
if ( IsValid( ent ) && ent:GetClass() == "prop_effect" ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) || ent:IsPlayer() ) then self:SetHand( NULL, 0 ) return true end
--if ( ent:GetClass() != "prop_ragdoll" && ent:GetClass() != "prop_dynamic" && !ent:IsNPC() ) then return false end
if ( CLIENT ) then return false end
local LeftHandMatrix, RightHandMatrix = self:GetHandPositions( ent )
if ( !LeftHandMatrix ) then return false end
local LeftHand = ( LeftHandMatrix:GetTranslation() - trace.HitPos ):Length()
local RightHand = ( RightHandMatrix:GetTranslation() - trace.HitPos ):Length()
local Hand = 0
if ( LeftHand < RightHand ) then
self:SetHand( ent, 0 )
else
self:SetHand( ent, 1 )
Hand = 1
end
--
-- Make sure entity has fingers set up!
--
SetupFingers( ent )
local bTF2 = HasTF2Hands( ent )
--
-- Rwead the variables from the angles of the fingers, into our convars
--
for i = 0, VarsOnHand-1 do
local bone = ent.FingerIndex[ i + Hand * VarsOnHand + 1 ]
if ( bone ) then
local Ang = ent:GetManipulateBoneAngles( bone )
if ( bTF2 ) then
if ( i < 3 ) then
self:GetOwner():ConCommand( Format( "finger_%s %.1f %.1f", i, Ang.Roll, Ang.Yaw ) )
else
self:GetOwner():ConCommand( Format( "finger_%s %.1f %.1f", i, Ang.Yaw, -Ang.Roll ) )
end
else
if ( i < 3 ) then
self:GetOwner():ConCommand( Format( "finger_%s %.1f %.1f", i, Ang.Yaw, Ang.Pitch ) )
else
self:GetOwner():ConCommand( Format( "finger_%s %.1f %.1f", i, Ang.Pitch, Ang.Yaw ) )
end
end
end
end
-- We don't want to send the finger poses to the client straight away
-- because they will get the old poses that are currently in their convars
-- We need to wait until they convars get updated with the sucked pose
self.NextUpdate = CurTime() + 0.5
return true
end
local OldHand = nil
local OldEntity = nil
local OldEntityValid = false
--[[
Updates the selected entity with the values from the convars
Also, on the client it rebuilds the control panel if we have
selected a new entity or hand
]]
function TOOL:Think()
local selected = self:HandEntity()
local hand = self:HandNum()
if ( self.NextUpdate && self.NextUpdate > CurTime() ) then return end
if ( CLIENT && ( OldHand != hand || OldEntity != selected || IsValid( selected ) != OldEntityValid ) ) then
OldHand = hand
OldEntity = selected
OldEntityValid = IsValid( selected )
self:RebuildControlPanel( self:HandEntity(), self:HandNum() )
end
if ( !IsValid( selected ) ) then return end
if ( selected:IsWorld() ) then return end
self:ApplyValues( selected, hand )
end
if ( SERVER ) then return end
-- Notice the return above.
-- The rest of this file CLIENT ONLY.
for i = 0, VarsOnHand do
TOOL.ClientConVar[ "" .. i ] = "0 0"
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel, ent, hand )
CPanel:Help( "#tool.finger.desc" )
if ( !IsValid( ent ) ) then return end
CPanel:ToolPresets( "finger", ConVarsDefault )
SetupFingers( ent )
if ( !ent.FingerIndex ) then return end
-- Detect mitten hands
local NumVars = table.Count( ent.FingerIndex )
local fingerPoser = vgui.Create( "fingerposer", CPanel )
fingerPoser:ControlValues( { hand = hand, numvars = NumVars } )
CPanel:AddPanel( fingerPoser )
CPanel:CheckBox( "#tool.finger.restrict_axis", "finger_restrict" )
end
local FacePoser = surface.GetTextureID( "gui/faceposer_indicator" )
-- Draw a circle around the selected hand
function TOOL:DrawHUD()
if ( GetConVarNumber( "gmod_drawtooleffects" ) == 0 ) then return end
local selected = self:HandEntity()
local hand = self:HandNum()
if ( !IsValid( selected ) ) then return end
if ( selected:IsWorld() ) then return end
local lefthand, righthand = self:GetHandPositions( selected )
local BoneMatrix = lefthand
if ( hand == 1 ) then BoneMatrix = righthand end
if ( !BoneMatrix ) then return end
local vPos = BoneMatrix:GetTranslation()
local scrpos = vPos:ToScreen()
if ( !scrpos.visible ) then return end
-- Work out the side distance to give a rough headsize box..
local player_eyes = LocalPlayer():EyeAngles()
local side = ( vPos + player_eyes:Right() * 20 ):ToScreen()
local size = math.abs( side.x - scrpos.x )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( FacePoser )
surface.DrawTexturedRect( scrpos.x - size, scrpos.y - size, size * 2, size * 2 )
end

View File

@@ -0,0 +1,246 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.hoverball.name"
TOOL.ClientConVar[ "keyup" ] = "46"
TOOL.ClientConVar[ "keydn" ] = "43"
TOOL.ClientConVar[ "keyon" ] = "40"
TOOL.ClientConVar[ "speed" ] = "5"
TOOL.ClientConVar[ "resistance" ] = "5"
TOOL.ClientConVar[ "strength" ] = "10"
TOOL.ClientConVar[ "model" ] = "models/dav0r/hoverball.mdl"
TOOL.Information = { { name = "left" } }
cleanup.Register( "hoverballs" )
local function IsValidHoverballModel( model )
for mdl, _ in pairs( list.Get( "HoverballModels" ) ) do
if ( mdl:lower() == model:lower() ) then return true end
end
return false
end
function TOOL:LeftClick( trace )
if ( trace.Entity && trace.Entity:IsPlayer() ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
if ( CLIENT ) then return true end
local ply = self:GetOwner()
local model = self:GetClientInfo( "model" )
local key_d = self:GetClientNumber( "keydn" )
local key_u = self:GetClientNumber( "keyup" )
local key_o = self:GetClientNumber( "keyon" )
local speed = self:GetClientNumber( "speed" )
local strength = math.Clamp( self:GetClientNumber( "strength" ), 0.1, 20 )
local resistance = math.Clamp( self:GetClientNumber( "resistance" ), 0, 20 )
-- We shot an existing hoverball - just change its values
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_hoverball" && trace.Entity:GetPlayer() == ply ) then
trace.Entity:SetSpeed( speed )
trace.Entity:SetAirResistance( resistance )
trace.Entity:SetStrength( strength )
numpad.Remove( trace.Entity.NumDown )
numpad.Remove( trace.Entity.NumUp )
numpad.Remove( trace.Entity.NumBackDown )
numpad.Remove( trace.Entity.NumBackUp )
numpad.Remove( trace.Entity.NumToggle )
trace.Entity.NumDown = numpad.OnDown( ply, key_u, "Hoverball_Up", trace.Entity, true )
trace.Entity.NumUp = numpad.OnUp( ply, key_u, "Hoverball_Up", trace.Entity, false )
trace.Entity.NumBackDown = numpad.OnDown( ply, key_d, "Hoverball_Down", trace.Entity, true )
trace.Entity.NumBackUp = numpad.OnUp( ply, key_d, "Hoverball_Down", trace.Entity, false )
trace.Entity.NumToggle = numpad.OnDown( ply, key_o, "Hoverball_Toggle", trace.Entity )
trace.Entity.key_u = key_u
trace.Entity.key_d = key_d
trace.Entity.key_o = key_o
trace.Entity.speed = speed
trace.Entity.strength = strength
trace.Entity.resistance = resistance
return true
end
if ( !util.IsValidModel( model ) || !util.IsValidProp( model ) || !IsValidHoverballModel( model ) ) then return false end
if ( !self:GetWeapon():CheckLimit( "hoverballs" ) ) then return false end
local ball = MakeHoverBall( ply, trace.HitPos, key_d, key_u, speed, resistance, strength, model, nil, key_o )
if ( !IsValid( ball ) ) then return false end
local ang = trace.HitNormal:Angle()
ang.pitch = ang.pitch + 90
ball:SetAngles( ang )
local CurPos = ball:GetPos()
local NearestPoint = ball:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local Offset = CurPos - NearestPoint
ball:SetPos( trace.HitPos + Offset )
undo.Create( "gmod_hoverball" )
undo.AddEntity( ball )
-- Don't weld to world
if ( IsValid( trace.Entity ) ) then
local weld = constraint.Weld( ball, trace.Entity, 0, trace.PhysicsBone, 0, 0, true )
if ( IsValid( weld ) ) then
ply:AddCleanup( "hoverballs", weld )
undo.AddEntity( weld )
end
if ( IsValid( ball:GetPhysicsObject() ) ) then ball:GetPhysicsObject():EnableCollisions( false ) end
ball:SetCollisionGroup( COLLISION_GROUP_WORLD )
ball.nocollide = true
end
undo.SetPlayer( ply )
undo.Finish()
return true
end
if ( SERVER ) then
function MakeHoverBall( ply, pos, key_d, key_u, speed, resistance, strength, model, nocollide, key_o, Data )
if ( IsValid( ply ) && !ply:CheckLimit( "hoverballs" ) ) then return NULL end
if ( !IsValidHoverballModel( model ) ) then return NULL end
local ball = ents.Create( "gmod_hoverball" )
if ( !IsValid( ball ) ) then return NULL end
duplicator.DoGeneric( ball, Data )
ball:SetPos( pos ) -- Backwards compatible for addons directly calling this function
ball:SetModel( model )
ball:Spawn()
DoPropSpawnedEffect( ball )
duplicator.DoGenericPhysics( ball, ply, Data )
ball:SetSpeed( speed )
ball:SetAirResistance( resistance )
ball:SetStrength( strength )
if ( IsValid( ply ) ) then
ball:SetPlayer( ply )
end
ball.NumDown = numpad.OnDown( ply, key_u, "Hoverball_Up", ball, true )
ball.NumUp = numpad.OnUp( ply, key_u, "Hoverball_Up", ball, false )
ball.NumBackDown = numpad.OnDown( ply, key_d, "Hoverball_Down", ball, true )
ball.NumBackUp = numpad.OnUp( ply, key_d, "Hoverball_Down", ball, false )
if ( key_o ) then ball.NumToggle = numpad.OnDown( ply, key_o, "Hoverball_Toggle", ball ) end
if ( nocollide == true ) then
if ( IsValid( ball:GetPhysicsObject() ) ) then ball:GetPhysicsObject():EnableCollisions( false ) end
ball:SetCollisionGroup( COLLISION_GROUP_WORLD )
end
local ttable = {
key_d = key_d,
key_u = key_u,
key_o = key_o,
pl = ply,
nocollide = nocollide,
speed = speed,
strength = strength,
resistance = resistance,
model = model
}
table.Merge( ball:GetTable(), ttable )
if ( IsValid( ply ) ) then
ply:AddCount( "hoverballs", ball )
ply:AddCleanup( "hoverballs", ball )
end
return ball
end
duplicator.RegisterEntityClass( "gmod_hoverball", MakeHoverBall, "Pos", "key_d", "key_u", "speed", "resistance", "strength", "model", "nocollide", "key_o", "Data" )
end
function TOOL:UpdateGhostHoverball( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit || IsValid( trace.Entity ) && ( trace.Entity:GetClass() == "gmod_hoverball" || trace.Entity:IsPlayer() ) ) then
ent:SetNoDraw( true )
return
end
local ang = trace.HitNormal:Angle()
ang.pitch = ang.pitch + 90
ent:SetAngles( ang )
local CurPos = ent:GetPos()
local NearestPoint = ent:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local Offset = CurPos - NearestPoint
ent:SetPos( trace.HitPos + Offset )
ent:SetNoDraw( false )
end
function TOOL:Think()
local mdl = self:GetClientInfo( "model" )
if ( !IsValidHoverballModel( mdl ) ) then self:ReleaseGhostEntity() return end
if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != mdl:lower() ) then
self:MakeGhostEntity( mdl, vector_origin, angle_zero )
end
self:UpdateGhostHoverball( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.hoverball.help" )
CPanel:ToolPresets( "hoverball", ConVarsDefault )
CPanel:KeyBinder( "#tool.hoverball.up", "hoverball_keyup", "#tool.hoverball.down", "hoverball_keydn" )
CPanel:KeyBinder( "#tool.hoverball.key", "hoverball_keyon" )
CPanel:NumSlider( "#tool.hoverball.speed", "hoverball_speed", 0, 20 )
CPanel:ControlHelp( "#tool.hoverball.speed.help" )
CPanel:NumSlider( "#tool.hoverball.resistance", "hoverball_resistance", 0, 10 )
CPanel:ControlHelp( "#tool.hoverball.resistance.help" )
CPanel:NumSlider( "#tool.hoverball.strength", "hoverball_strength", 0.1, 10 )
CPanel:ControlHelp( "#tool.hoverball.strength.help" )
CPanel:PropSelect( "#tool.hoverball.model", "hoverball_model", list.Get( "HoverballModels" ), 0 )
end
list.Set( "HoverballModels", "models/dav0r/hoverball.mdl", {} )
list.Set( "HoverballModels", "models/maxofs2d/hover_basic.mdl", {} )
list.Set( "HoverballModels", "models/maxofs2d/hover_classic.mdl", {} )
list.Set( "HoverballModels", "models/maxofs2d/hover_plate.mdl", {} )
list.Set( "HoverballModels", "models/maxofs2d/hover_propeller.mdl", {} )
list.Set( "HoverballModels", "models/maxofs2d/hover_rings.mdl", {} )

View File

@@ -0,0 +1,255 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.hydraulic.name"
TOOL.ClientConVar[ "group" ] = "37"
TOOL.ClientConVar[ "width" ] = "3"
TOOL.ClientConVar[ "addlength" ] = "100"
TOOL.ClientConVar[ "fixed" ] = "1"
TOOL.ClientConVar[ "speed" ] = "64"
TOOL.ClientConVar[ "toggle" ] = "1"
TOOL.ClientConVar[ "material" ] = "cable/rope"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1, op = 1 },
{ name = "right", stage = 0 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
self:SetOperation( 1 )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
if ( ( !IsValid( self:GetEnt( 1 ) ) && !IsValid( self:GetEnt( 2 ) ) ) || iNum > 1 ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local width = self:GetClientNumber( "width", 3 )
local bind = self:GetClientNumber( "group", 1 )
local addLength = self:GetClientNumber( "addlength", 0 )
local fixed = self:GetClientNumber( "fixed", 1 )
local speed = self:GetClientNumber( "speed", 64 )
local material = self:GetClientInfo( "material" )
local toggle = self:GetClientNumber( "toggle" ) != 0
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local lengthMin = ( WPos1 - WPos2 ):Length()
local lengthMax = lengthMin + addLength
local constr, rope, controller, slider = constraint.Hydraulic( ply, Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, lengthMin, lengthMax, width, bind, fixed, speed, material, toggle, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
undo.Create( "Hydraulic" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
if ( IsValid( slider ) ) then undo.AddEntity( slider ) end
if ( IsValid( controller ) ) then undo.AddEntity( controller ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.hydraulic.name" )
undo.Finish( "#tool.hydraulic.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
if ( IsValid( slider ) ) then ply:AddCleanup( "ropeconstraints", slider ) end
if ( IsValid( controller ) ) then ply:AddCleanup( "ropeconstraints", controller ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:RightClick( trace )
if ( self:GetOperation() == 1 ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
local ply = self:GetOwner()
local tr_new = {}
tr_new.start = trace.HitPos
tr_new.endpos = trace.HitPos + ( trace.HitNormal * 16384 )
tr_new.filter = { ply }
if ( IsValid( trace.Entity ) ) then
table.insert( tr_new.filter, trace.Entity )
end
local tr = util.TraceLine( tr_new )
if ( !tr.Hit ) then
self:ClearObjects()
return
end
-- Don't try to constrain world to world
if ( trace.HitWorld && tr.HitWorld ) then
self:ClearObjects()
return
end
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then
self:ClearObjects()
return
end
if ( IsValid( tr.Entity ) && tr.Entity:IsPlayer() ) then
self:ClearObjects()
return
end
-- Check to see if the player can create a hydraulic constraint with the entity in the trace
if ( !hook.Run( "CanTool", ply, tr, "hydraulic", self, 2 ) ) then
self:ClearObjects()
return
end
local Phys2 = tr.Entity:GetPhysicsObjectNum( tr.PhysicsBone )
self:SetObject( 2, tr.Entity, tr.HitPos, Phys2, tr.PhysicsBone, tr.HitNormal )
if ( CLIENT ) then
self:ClearObjects()
return true
end
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local width = self:GetClientNumber( "width", 3 )
local bind = self:GetClientNumber( "group", 1 )
local AddLength = self:GetClientNumber( "addlength", 0 )
local fixed = self:GetClientNumber( "fixed", 1 )
local speed = self:GetClientNumber( "speed", 64 )
local material = self:GetClientInfo( "material" )
local toggle = self:GetClientNumber( "toggle" ) != 0
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local Length1 = ( WPos1 - WPos2 ):Length()
local Length2 = Length1 + AddLength
local constr, rope, controller, slider = constraint.Hydraulic( ply, Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, speed, material, toggle, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
undo.Create( "Hydraulic" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
if ( IsValid( slider ) ) then undo.AddEntity( slider ) end
if ( IsValid( controller ) ) then undo.AddEntity( controller ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.hydraulic.name" )
undo.Finish( "#tool.hydraulic.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
if ( IsValid( slider ) ) then ply:AddCleanup( "ropeconstraints", slider ) end
if ( IsValid( controller ) ) then ply:AddCleanup( "ropeconstraints", controller ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Hydraulic" )
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.hydraulic.help" )
CPanel:ToolPresets( "hydraulic", ConVarsDefault )
CPanel:KeyBinder( "#tool.hydraulic.controls", "hydraulic_group" )
CPanel:NumSlider( "#tool.hydraulic.addlength", "hydraulic_addlength", -1000, 1000 )
CPanel:ControlHelp( "#tool.hydraulic.addlength.help" )
CPanel:NumSlider( "#tool.hydraulic.speed", "hydraulic_speed", 0, 50 )
CPanel:ControlHelp( "#tool.hydraulic.speed.help" )
CPanel:CheckBox( "#tool.hydraulic.fixed", "hydraulic_fixed" )
CPanel:ControlHelp( "#tool.hydraulic.fixed.help" )
CPanel:CheckBox( "#tool.toggle", "hydraulic_toggle" )
CPanel:ControlHelp( "#tool.toggle.help" )
CPanel:NumSlider( "#tool.hydraulic.width", "hydraulic_width", 0, 5 )
CPanel:RopeSelect( "hydraulic_material" )
CPanel:ColorPicker( "#tool.hydraulic.color", "hydraulic_color_r", "hydraulic_color_g", "hydraulic_color_b" )
end

View File

@@ -0,0 +1,147 @@
TOOL.Category = "Poser"
TOOL.Name = "#tool.inflator.name"
TOOL.LeftClickAutomatic = true
TOOL.RightClickAutomatic = true
TOOL.RequiresTraceHit = true
TOOL.Information = {
{ name = "left" },
{ name = "right" },
{ name = "reload" }
}
local ScaleYZ = {
"ValveBiped.Bip01_L_UpperArm",
"ValveBiped.Bip01_L_Forearm",
"ValveBiped.Bip01_L_Thigh",
"ValveBiped.Bip01_L_Calf",
"ValveBiped.Bip01_R_UpperArm",
"ValveBiped.Bip01_R_Forearm",
"ValveBiped.Bip01_R_Thigh",
"ValveBiped.Bip01_R_Calf",
"ValveBiped.Bip01_Spine2",
"ValveBiped.Bip01_Spine1",
"ValveBiped.Bip01_Spine",
"ValveBiped.Bip01_Spinebut",
-- Vortigaunt
"ValveBiped.spine4",
"ValveBiped.spine3",
"ValveBiped.spine2",
"ValveBiped.spine1",
"ValveBiped.hlp_ulna_R",
"ValveBiped.hlp_ulna_L",
"ValveBiped.arm1_L",
"ValveBiped.arm1_R",
"ValveBiped.arm2_L",
"ValveBiped.arm2_R",
"ValveBiped.leg_bone1_L",
"ValveBiped.leg_bone1_R",
"ValveBiped.leg_bone2_L",
"ValveBiped.leg_bone2_R",
"ValveBiped.leg_bone3_L",
"ValveBiped.leg_bone3_R",
-- Team Fortress 2
"bip_knee_L",
"bip_knee_R",
"bip_hip_R",
"bip_hip_L",
}
local ScaleXZ = {
"ValveBiped.Bip01_pelvis",
-- Team Fortress 2
"bip_upperArm_L",
"bip_upperArm_R",
"bip_lowerArm_L",
"bip_lowerArm_R",
"bip_forearm_L",
"bip_forearm_R",
}
local function GetNiceBoneScale( name, scale )
if ( table.HasValue( ScaleYZ, name ) or string.find( name:lower(), "leg" ) or string.find( name:lower(), "arm" ) ) then
return Vector( 0, scale, scale )
end
if ( table.HasValue( ScaleXZ, name ) ) then
return Vector( scale, 0, scale )
end
return Vector( scale, scale, scale )
end
--Scale the specified bone by Scale
local function ScaleBone( ent, bone, scale )
if ( !bone or CLIENT ) then return false end
local physBone = ent:TranslateBoneToPhysBone( bone )
for i = 0, ent:GetBoneCount() do
if ( ent:TranslateBoneToPhysBone( i ) != physBone ) then continue end
-- Some bones are scaled only in certain directions (like legs don't scale on length)
local v = GetNiceBoneScale( ent:GetBoneName( i ), scale ) * 0.1
local TargetScale = ent:GetManipulateBoneScale( i ) + v * 0.1
if ( TargetScale.x < 0 ) then TargetScale.x = 0 end
if ( TargetScale.y < 0 ) then TargetScale.y = 0 end
if ( TargetScale.z < 0 ) then TargetScale.z = 0 end
ent:ManipulateBoneScale( i, TargetScale )
end
end
--Scale UP
function TOOL:LeftClick( trace, scale )
if ( !IsValid( trace.Entity ) ) then return false end
if ( !trace.Entity:IsNPC() and trace.Entity:GetClass() != "prop_ragdoll" /*&& !trace.Entity:IsPlayer()*/ ) then return false end
local bone = trace.Entity:TranslatePhysBoneToBone( trace.PhysicsBone )
ScaleBone( trace.Entity, bone, scale or 1 )
self:GetWeapon():SetNextPrimaryFire( CurTime() + 0.01 )
local effectdata = EffectData()
effectdata:SetOrigin( trace.HitPos )
util.Effect( "inflator_magic", effectdata )
return false
end
-- Scale DOWN
function TOOL:RightClick( trace )
return self:LeftClick( trace, -1 )
end
-- Reset scaling
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) ) then return false end
if ( !trace.Entity:IsNPC() and trace.Entity:GetClass() != "prop_ragdoll" /*&& !trace.Entity:IsPlayer()*/ ) then return false end
if ( CLIENT ) then return true end
for i = 0, trace.Entity:GetBoneCount() do
trace.Entity:ManipulateBoneScale( i, Vector( 1, 1, 1 ) )
end
return true
end
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.inflator.desc" )
end

View File

@@ -0,0 +1,287 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.lamp.name"
TOOL.ClientConVar[ "r" ] = "255"
TOOL.ClientConVar[ "g" ] = "255"
TOOL.ClientConVar[ "b" ] = "255"
TOOL.ClientConVar[ "key" ] = "37"
TOOL.ClientConVar[ "fov" ] = "90"
TOOL.ClientConVar[ "distance" ] = "1024"
TOOL.ClientConVar[ "brightness" ] = "4"
TOOL.ClientConVar[ "texture" ] = "effects/flashlight001"
TOOL.ClientConVar[ "model" ] = "models/lamps/torch.mdl"
TOOL.ClientConVar[ "toggle" ] = "1"
TOOL.Information = {
{ name = "left" },
{ name = "right" },
}
cleanup.Register( "lamps" )
local function IsValidLampModel( model )
for mdl, _ in pairs( list.Get( "LampModels" ) ) do
if ( mdl:lower() == model:lower() ) then return true end
end
return false
end
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) and trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
local ply = self:GetOwner()
local pos = trace.HitPos
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 )
local key = self:GetClientNumber( "key" )
local mdl = self:GetClientInfo( "model" )
local fov = self:GetClientNumber( "fov" )
local distance = self:GetClientNumber( "distance" )
local bright = self:GetClientNumber( "brightness" )
local toggle = self:GetClientNumber( "toggle" ) != 1
local tex = self:GetClientInfo( "texture" )
local mat = Material( tex )
local texture = mat:GetString( "$basetexture" )
if ( IsValid( trace.Entity ) and trace.Entity:GetClass() == "gmod_lamp" and trace.Entity:GetPlayer() == ply ) then
trace.Entity:SetColor( Color( r, g, b, 255 ) )
trace.Entity:SetFlashlightTexture( texture )
trace.Entity:SetLightFOV( fov )
trace.Entity:SetDistance( distance )
trace.Entity:SetBrightness( bright )
trace.Entity:SetToggle( !toggle )
trace.Entity:UpdateLight()
numpad.Remove( trace.Entity.NumDown )
numpad.Remove( trace.Entity.NumUp )
trace.Entity.NumDown = numpad.OnDown( ply, key, "LampToggle", trace.Entity, 1 )
trace.Entity.NumUp = numpad.OnUp( ply, key, "LampToggle", trace.Entity, 0 )
-- For duplicator
trace.Entity.Texture = texture
trace.Entity.fov = fov
trace.Entity.distance = distance
trace.Entity.r = r
trace.Entity.g = g
trace.Entity.b = b
trace.Entity.brightness = bright
trace.Entity.KeyDown = key
return true
end
if ( !util.IsValidModel( mdl ) or !util.IsValidProp( mdl ) or !IsValidLampModel( mdl ) ) then return false end
if ( !self:GetWeapon():CheckLimit( "lamps" ) ) then return false end
local lamp = MakeLamp( ply, r, g, b, key, toggle, texture, mdl, fov, distance, bright, !toggle, { Pos = pos, Angle = angle_zero } )
if ( !IsValid( lamp ) ) then return false end
local CurPos = lamp:GetPos()
local NearestPoint = lamp:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local LampOffset = CurPos - NearestPoint
lamp:SetPos( trace.HitPos + LampOffset )
undo.Create( "gmod_lamp" )
undo.AddEntity( lamp )
undo.SetPlayer( self:GetOwner() )
undo.Finish()
return true
end
function TOOL:RightClick( trace )
if ( !IsValid( trace.Entity ) or trace.Entity:GetClass() != "gmod_lamp" ) then return false end
if ( CLIENT ) then return true end
local ent = trace.Entity
local ply = self:GetOwner()
ply:ConCommand( "lamp_fov " .. ent:GetLightFOV() )
ply:ConCommand( "lamp_distance " .. ent:GetDistance() )
ply:ConCommand( "lamp_brightness " .. ent:GetBrightness() )
ply:ConCommand( "lamp_texture " .. ent:GetFlashlightTexture() )
if ( ent:GetToggle() ) then
ply:ConCommand( "lamp_toggle 1" )
else
ply:ConCommand( "lamp_toggle 0" )
end
local clr = ent:GetColor()
ply:ConCommand( "lamp_r " .. clr.r )
ply:ConCommand( "lamp_g " .. clr.g )
ply:ConCommand( "lamp_b " .. clr.b )
return true
end
if ( SERVER ) then
function MakeLamp( ply, r, g, b, keyDown, toggle, texture, model, fov, distance, brightness, on, Data )
if ( IsValid( ply ) and !ply:CheckLimit( "lamps" ) ) then return NULL end
if ( !IsValidLampModel( model ) ) then return NULL end
local lamp = ents.Create( "gmod_lamp" )
if ( !IsValid( lamp ) ) then return NULL end
duplicator.DoGeneric( lamp, Data )
lamp:SetModel( model ) -- Backwards compatible for addons directly calling this function
lamp:SetFlashlightTexture( texture )
lamp:SetLightFOV( fov )
lamp:SetColor( Color( r, g, b, 255 ) )
lamp:SetDistance( distance )
lamp:SetBrightness( brightness )
lamp:Switch( on )
lamp:SetToggle( !toggle )
lamp:Spawn()
DoPropSpawnedEffect( lamp )
duplicator.DoGenericPhysics( lamp, ply, Data )
lamp:SetPlayer( ply )
if ( IsValid( ply ) ) then
ply:AddCount( "lamps", lamp )
ply:AddCleanup( "lamps", lamp )
end
lamp.Texture = texture
lamp.KeyDown = keyDown
lamp.fov = fov
lamp.distance = distance
lamp.r = r
lamp.g = g
lamp.b = b
lamp.brightness = brightness
lamp.NumDown = numpad.OnDown( ply, keyDown, "LampToggle", lamp, 1 )
lamp.NumUp = numpad.OnUp( ply, keyDown, "LampToggle", lamp, 0 )
return lamp
end
duplicator.RegisterEntityClass( "gmod_lamp", MakeLamp, "r", "g", "b", "KeyDown", "Toggle", "Texture", "Model", "fov", "distance", "brightness", "on", "Data" )
numpad.Register( "LampToggle", function( ply, ent, onoff )
if ( !IsValid( ent ) ) then return false end
if ( !ent:GetToggle() ) then ent:Switch( onoff == 1 ) return end
if ( numpad.FromButton() ) then
ent:Switch( onoff == 1 )
return
end
if ( onoff == 0 ) then return end
return ent:Toggle()
end )
end
function TOOL:UpdateGhostLamp( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit or IsValid( trace.Entity ) and ( trace.Entity:IsPlayer() or trace.Entity:GetClass() == "gmod_lamp" ) ) then
ent:SetNoDraw( true )
return
end
local CurPos = ent:GetPos()
local NearestPoint = ent:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local LampOffset = CurPos - NearestPoint
ent:SetPos( trace.HitPos + LampOffset )
ent:SetNoDraw( false )
end
function TOOL:Think()
local mdl = self:GetClientInfo( "model" )
if ( !IsValidLampModel( mdl ) ) then self:ReleaseGhostEntity() return end
if ( !IsValid( self.GhostEntity ) or self.GhostEntity:GetModel() != mdl:lower() ) then
self:MakeGhostEntity( mdl, vector_origin, angle_zero )
end
self:UpdateGhostLamp( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.lamp.desc" )
CPanel:ToolPresets( "lamp", ConVarsDefault )
CPanel:KeyBinder( "#tool.lamp.key", "lamp_key" )
CPanel:NumSlider( "#tool.lamp.fov", "lamp_fov", 10, 170 )
CPanel:NumSlider( "#tool.lamp.distance", "lamp_distance", 64, 2048 )
CPanel:NumSlider( "#tool.lamp.brightness", "lamp_brightness", 0, 8 )
CPanel:CheckBox( "#tool.lamp.toggle", "lamp_toggle" )
CPanel:ColorPicker( "#tool.lamp.color", "lamp_r", "lamp_g", "lamp_b" )
local MatSelect = CPanel:MatSelect( "lamp_texture", nil, false, 0.33, 0.33 )
MatSelect.Height = 4
for k, v in pairs( list.Get( "LampTextures" ) ) do
MatSelect:AddMaterial( v.Name or k, k )
end
CPanel:PropSelect( "#tool.lamp.model", "lamp_model", list.Get( "LampModels" ), 0 )
end
list.Set( "LampTextures", "effects/flashlight001", { Name = "#lamptexture.default" } )
list.Set( "LampTextures", "effects/flashlight/slit", { Name = "#lamptexture.slit" } )
list.Set( "LampTextures", "effects/flashlight/circles", { Name = "#lamptexture.circles" } )
list.Set( "LampTextures", "effects/flashlight/window", { Name = "#lamptexture.window" } )
list.Set( "LampTextures", "effects/flashlight/logo", { Name = "#lamptexture.logo" } )
list.Set( "LampTextures", "effects/flashlight/gradient", { Name = "#lamptexture.gradient" } )
list.Set( "LampTextures", "effects/flashlight/bars", { Name = "#lamptexture.bars" } )
list.Set( "LampTextures", "effects/flashlight/tech", { Name = "#lamptexture.techdemo" } )
list.Set( "LampTextures", "effects/flashlight/soft", { Name = "#lamptexture.soft" } )
list.Set( "LampTextures", "effects/flashlight/hard", { Name = "#lamptexture.hard" } )
list.Set( "LampTextures", "effects/flashlight/caustics", { Name = "#lamptexture.caustics" } )
list.Set( "LampTextures", "effects/flashlight/square", { Name = "#lamptexture.square" } )
list.Set( "LampTextures", "effects/flashlight/camera", { Name = "#lamptexture.camera" } )
list.Set( "LampTextures", "effects/flashlight/view", { Name = "#lamptexture.view" } )
list.Set( "LampModels", "models/lamps/torch.mdl", {} )
list.Set( "LampModels", "models/maxofs2d/lamp_flashlight.mdl", { Offset = Vector( 8.5, 0, 0 ) } )
list.Set( "LampModels", "models/maxofs2d/lamp_projector.mdl", { Offset = Vector( 8.5, 0, 0 ) } )
list.Set( "LampModels", "models/props_wasteland/light_spotlight01_lamp.mdl", { Offset = Vector( 9, 0, 4 ), Skin = 1, Scale = 3 } )
list.Set( "LampModels", "models/props_wasteland/light_spotlight02_lamp.mdl", { Offset = Vector( 5.5, 0, 0 ), Skin = 1 } )
list.Set( "LampModels", "models/props_c17/light_decklight01_off.mdl", { Offset = Vector( 3, 0, 0 ), Skin = 1, Scale = 3 } )
list.Set( "LampModels", "models/props_wasteland/prison_lamp001c.mdl", { Offset = Vector( 0, 0, -5 ), Angle = Angle( 90, 0, 0 ) } )
-- This works, but the ghost entity is invisible due to $alphatest...
--list.Set( "LampModels", "models/props_c17/lamp_standard_off01.mdl", { Offset = Vector( 5.20, 0.25, 8 ), Angle = Angle( 90, 0, 0 ), NearZ = 6 } )

View File

@@ -0,0 +1,37 @@
TOOL.AddToMenu = false
--
-- This tool is the most important aspect of Garry's Mod
--
TOOL.LeftClickAutomatic = true
function TOOL:LeftClick( trace )
if ( CLIENT ) then return end
util.PrecacheSound( "ambient/wind/wind_hit2.wav" )
self:GetOwner():EmitSound( "ambient/wind/wind_hit2.wav" )
if ( IsValid( trace.Entity ) and IsValid( trace.Entity:GetPhysicsObject() ) ) then
local phys = trace.Entity:GetPhysicsObject() -- The physics object
local direction = trace.StartPos - trace.HitPos -- The direction of the force
local force = 32 -- The ideal amount of force
local distance = direction:Length() -- The distance the phys object is from the gun
local maxdistance = 512 -- The max distance the gun should reach
-- Lessen the force from a distance
local ratio = math.Clamp( 1 - ( distance / maxdistance ), 0, 1 )
-- Set up the 'real' force and the offset of the force
local vForce = -direction * ( force * ratio )
local vOffset = trace.HitPos
-- Apply it!
phys:ApplyForceOffset( vForce, vOffset )
end
end

View File

@@ -0,0 +1,232 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.light.name"
TOOL.ClientConVar[ "ropelength" ] = "64"
TOOL.ClientConVar[ "ropematerial" ] = "cable/rope"
TOOL.ClientConVar[ "r" ] = "255"
TOOL.ClientConVar[ "g" ] = "255"
TOOL.ClientConVar[ "b" ] = "255"
TOOL.ClientConVar[ "brightness" ] = "2"
TOOL.ClientConVar[ "size" ] = "256"
TOOL.ClientConVar[ "key" ] = "37"
TOOL.ClientConVar[ "toggle" ] = "1"
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
cleanup.Register( "lights" )
function TOOL:LeftClick( trace, attach )
if ( IsValid( 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 * 8, 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 )
local brght = math.Clamp( self:GetClientNumber( "brightness" ), -10, 20 )
local size = self:GetClientNumber( "size" )
local toggle = self:GetClientNumber( "toggle" ) != 1
local key = self:GetClientNumber( "key" )
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_light" && trace.Entity:GetPlayer() == ply ) then
trace.Entity:SetColor( Color( r, g, b, 255 ) )
trace.Entity.r = r
trace.Entity.g = g
trace.Entity.b = b
trace.Entity.Brightness = brght
trace.Entity.Size = size
trace.Entity:SetBrightness( brght )
trace.Entity:SetLightSize( size )
trace.Entity:SetToggle( !toggle )
trace.Entity.KeyDown = key
numpad.Remove( trace.Entity.NumDown )
numpad.Remove( trace.Entity.NumUp )
trace.Entity.NumDown = numpad.OnDown( ply, key, "LightToggle", trace.Entity, 1 )
trace.Entity.NumUp = numpad.OnUp( ply, key, "LightToggle", trace.Entity, 0 )
return true
end
if ( !self:GetWeapon():CheckLimit( "lights" ) ) then return false end
local light = MakeLight( ply, r, g, b, brght, size, toggle, !toggle, key, { Pos = pos, Angle = ang } )
if ( !IsValid( light ) ) then return false end
undo.Create( "gmod_light" )
undo.AddEntity( light )
if ( attach ) then
local length = math.Clamp( self:GetClientNumber( "ropelength" ), 4, 1024 )
local material = self:GetClientInfo( "ropematerial" )
local LPos1 = Vector( 0, 0, 6.5 )
local LPos2 = trace.Entity:WorldToLocal( trace.HitPos )
if ( IsValid( trace.Entity ) ) then
local phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
if ( IsValid( phys ) ) then
LPos2 = phys:WorldToLocal( trace.HitPos )
end
end
local constr, rope = constraint.Rope( light, trace.Entity, 0, trace.PhysicsBone, LPos1, LPos2, 0, length, 0, 1, material )
if ( IsValid( constr ) ) then
undo.AddEntity( constr )
ply:AddCleanup( "lights", constr )
end
if ( IsValid( rope ) ) then
undo.AddEntity( rope )
ply:AddCleanup( "lights", rope )
end
end
undo.SetPlayer( ply )
undo.Finish()
return true
end
function TOOL:RightClick( trace )
return self:LeftClick( trace, false )
end
if ( SERVER ) then
function MakeLight( ply, r, g, b, brght, size, toggle, on, keyDown, Data )
if ( IsValid( ply ) && !ply:CheckLimit( "lights" ) ) then return NULL end
local light = ents.Create( "gmod_light" )
if ( !IsValid( light ) ) then return NULL end
duplicator.DoGeneric( light, Data )
light:SetColor( Color( r, g, b, 255 ) )
light:SetBrightness( brght )
light:SetLightSize( size )
light:SetToggle( !toggle )
light:SetOn( on )
light:Spawn()
DoPropSpawnedEffect( light )
duplicator.DoGenericPhysics( light, ply, Data )
light:SetPlayer( ply )
light.lightr = r
light.lightg = g
light.lightb = b
light.Brightness = brght
light.Size = size
light.KeyDown = keyDown
light.on = on
light.NumDown = numpad.OnDown( ply, keyDown, "LightToggle", light, 1 )
light.NumUp = numpad.OnUp( ply, keyDown, "LightToggle", light, 0 )
if ( IsValid( ply ) ) then
ply:AddCount( "lights", light )
ply:AddCleanup( "lights", light )
end
return light
end
duplicator.RegisterEntityClass( "gmod_light", MakeLight, "lightr", "lightg", "lightb", "Brightness", "Size", "Toggle", "on", "KeyDown", "Data" )
local function Toggle( ply, ent, onoff )
if ( !IsValid( ent ) ) then return false end
if ( !ent:GetToggle() ) then ent:SetOn( onoff == 1 ) return end
if ( numpad.FromButton() ) then
ent:SetOn( onoff == 1 )
return
end
if ( onoff == 0 ) then return end
return ent:Toggle()
end
numpad.Register( "LightToggle", Toggle )
end
function TOOL:UpdateGhostLight( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit || IsValid( trace.Entity ) && ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_light" ) ) then
ent:SetNoDraw( true )
return
end
ent:SetPos( trace.HitPos + trace.HitNormal * 8 )
ent:SetAngles( trace.HitNormal:Angle() - Angle( 90, 0, 0 ) )
ent:SetNoDraw( false )
end
function TOOL:Think()
if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != "models/maxofs2d/light_tubular.mdl" ) then
self:MakeGhostEntity( "models/maxofs2d/light_tubular.mdl", vector_origin, angle_zero )
end
self:UpdateGhostLight( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.light.desc" )
CPanel:ToolPresets( "light", ConVarsDefault )
CPanel:KeyBinder( "#tool.light.key", "light_key" )
CPanel:NumSlider( "#tool.light.ropelength", "light_ropelength", 0, 256 )
CPanel:NumSlider( "#tool.light.brightness", "light_brightness", -6, 6, 0 )
CPanel:NumSlider( "#tool.light.size", "light_size", 0, 1024 )
CPanel:CheckBox( "#tool.light.toggle", "light_toggle" )
CPanel:ColorPicker( "#tool.light.color", "light_r", "light_g", "light_b" )
end

View File

@@ -0,0 +1,156 @@
TOOL.Category = "Render"
TOOL.Name = "#tool.material.name"
TOOL.ClientConVar[ "override" ] = "debug/env_cubemap_model"
TOOL.Information = {
{ name = "left" },
{ name = "right" },
{ name = "reload" }
}
--
-- Duplicator function
--
local function SetMaterial( Player, Entity, Data )
if ( SERVER ) then
--
-- Make sure this is in the 'allowed' list in multiplayer - to stop people using exploits
--
if ( !game.SinglePlayer() && !list.Contains( "OverrideMaterials", Data.MaterialOverride ) && Data.MaterialOverride != "" ) then return end
Entity:SetMaterial( Data.MaterialOverride )
duplicator.StoreEntityModifier( Entity, "material", Data )
end
return true
end
if ( SERVER ) then
duplicator.RegisterEntityModifier( "material", SetMaterial )
end
-- Left click applies the current material
function TOOL:LeftClick( trace )
local ent = trace.Entity
if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end -- The entity is valid and isn't worldspawn
if ( CLIENT ) then return true end
local mat = self:GetClientInfo( "override" )
SetMaterial( self:GetOwner(), ent, { MaterialOverride = mat } )
return true
end
-- Right click copies the material
function TOOL:RightClick( trace )
local ent = trace.Entity
if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end -- The entity is valid and isn't worldspawn
if ( CLIENT ) then return true end
self:GetOwner():ConCommand( "material_override " .. ent:GetMaterial() )
return true
end
-- Reload reverts the material
function TOOL:Reload( trace )
local ent = trace.Entity
if ( IsValid( ent.AttachedEntity ) ) then ent = ent.AttachedEntity end
if ( !IsValid( ent ) ) then return false end -- The entity is valid and isn't worldspawn
if ( CLIENT ) then return true end
SetMaterial( self:GetOwner(), ent, { MaterialOverride = "" } )
return true
end
list.Add( "OverrideMaterials", "models/wireframe" )
list.Add( "OverrideMaterials", "debug/env_cubemap_model" )
list.Add( "OverrideMaterials", "models/shadertest/shader3" )
list.Add( "OverrideMaterials", "models/shadertest/shader4" )
list.Add( "OverrideMaterials", "models/shadertest/shader5" )
list.Add( "OverrideMaterials", "models/shiny" )
list.Add( "OverrideMaterials", "models/debug/debugwhite" )
list.Add( "OverrideMaterials", "Models/effects/comball_sphere" )
list.Add( "OverrideMaterials", "Models/effects/comball_tape" )
list.Add( "OverrideMaterials", "Models/effects/splodearc_sheet" )
list.Add( "OverrideMaterials", "Models/effects/vol_light001" )
list.Add( "OverrideMaterials", "models/props_combine/stasisshield_sheet" )
list.Add( "OverrideMaterials", "models/props_combine/portalball001_sheet" )
list.Add( "OverrideMaterials", "models/props_combine/com_shield001a" )
list.Add( "OverrideMaterials", "models/props_c17/frostedglass_01a" )
list.Add( "OverrideMaterials", "models/props_lab/Tank_Glass001" )
list.Add( "OverrideMaterials", "models/props_combine/tprings_globe" )
list.Add( "OverrideMaterials", "models/rendertarget" )
list.Add( "OverrideMaterials", "models/screenspace" )
list.Add( "OverrideMaterials", "brick/brick_model" )
list.Add( "OverrideMaterials", "models/props_pipes/GutterMetal01a" )
list.Add( "OverrideMaterials", "models/props_pipes/Pipesystem01a_skin3" )
list.Add( "OverrideMaterials", "models/props_wasteland/wood_fence01a" )
list.Add( "OverrideMaterials", "models/props_foliage/tree_deciduous_01a_trunk" )
list.Add( "OverrideMaterials", "models/props_c17/FurnitureFabric003a" )
list.Add( "OverrideMaterials", "models/props_c17/FurnitureMetal001a" )
list.Add( "OverrideMaterials", "models/props_c17/paper01" )
list.Add( "OverrideMaterials", "models/flesh" )
-- phx
list.Add( "OverrideMaterials", "phoenix_storms/metalset_1-2" )
list.Add( "OverrideMaterials", "phoenix_storms/metalfloor_2-3" )
list.Add( "OverrideMaterials", "phoenix_storms/plastic" )
list.Add( "OverrideMaterials", "phoenix_storms/wood" )
list.Add( "OverrideMaterials", "phoenix_storms/bluemetal" )
list.Add( "OverrideMaterials", "phoenix_storms/cube" )
list.Add( "OverrideMaterials", "phoenix_storms/dome" )
list.Add( "OverrideMaterials", "phoenix_storms/gear" )
list.Add( "OverrideMaterials", "phoenix_storms/stripes" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_green" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_red" )
list.Add( "OverrideMaterials", "phoenix_storms/wire/pcb_blue" )
list.Add( "OverrideMaterials", "hunter/myplastic" )
list.Add( "OverrideMaterials", "models/XQM/LightLinesRed_tool" )
if ( IsMounted( "tf" ) ) then
list.Add( "OverrideMaterials", "models/player/shared/gold_player" )
list.Add( "OverrideMaterials", "models/player/shared/ice_player" )
end
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.material.help" )
local filter = CPanel:TextEntry( "#spawnmenu.quick_filter_tool" )
filter:SetUpdateOnType( true )
-- Remove duplicate materials. table.HasValue is used to preserve material order
local materials = {}
for id, str in ipairs( list.Get( "OverrideMaterials" ) ) do
if ( !table.HasValue( materials, str ) ) then
table.insert( materials, str )
end
end
local matlist = CPanel:MatSelect( "material_override", materials, true, 0.25, 0.25 )
filter.OnValueChange = function( s, txt )
for id, pnl in ipairs( matlist.Controls ) do
if ( !pnl.Value:lower():find( txt:lower(), nil, true ) ) then
pnl:SetVisible( false )
else
pnl:SetVisible( true )
end
end
matlist:InvalidateChildren()
CPanel:InvalidateChildren()
end
end

View File

@@ -0,0 +1,168 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.motor.name"
TOOL.ClientConVar[ "torque" ] = "500"
TOOL.ClientConVar[ "friction" ] = "1"
TOOL.ClientConVar[ "nocollide" ] = "1"
TOOL.ClientConVar[ "forcetime" ] = "0"
TOOL.ClientConVar[ "fwd" ] = "45"
TOOL.ClientConVar[ "bwd" ] = "42"
TOOL.ClientConVar[ "toggle" ] = "0"
TOOL.ClientConVar[ "forcelimit" ] = "0"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1 },
{ name = "reload"}
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
-- Don't allow us to choose the world as the first object
if ( iNum == 0 && !IsValid( trace.Entity ) ) then return end
-- Don't allow us to choose the same object
if ( iNum == 1 && trace.Entity == self:GetEnt( 1 ) ) then return end
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
self:ReleaseGhostEntity()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "constraints" ) ) then
self:ClearObjects()
self:ReleaseGhostEntity()
return false
end
-- Get client's CVars
local torque = self:GetClientNumber( "torque" )
local friction = self:GetClientNumber( "friction" )
local nocollide = self:GetClientNumber( "nocollide" )
local time = self:GetClientNumber( "forcetime" )
local forekey = self:GetClientNumber( "fwd" )
local backkey = self:GetClientNumber( "bwd" )
local toggle = self:GetClientNumber( "toggle" ) != 0
local limit = self:GetClientNumber( "forcelimit" )
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local Norm1, Norm2 = self:GetNormal( 1 ), self:GetNormal( 2 )
local Phys1 = self:GetPhys( 1 )
local WPos2 = self:GetPos( 2 )
-- Note: To keep stuff ragdoll friendly try to treat things as physics objects rather than entities
local Ang1, Ang2 = Norm1:Angle(), ( -Norm2 ):Angle()
local TargetAngle = Phys1:AlignAngles( Ang1, Ang2 )
Phys1:SetAngles( TargetAngle )
-- Move the object so that the hitpos on our object is at the second hitpos
local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) ) + ( Norm2 * 0.2 )
-- Set the position
Phys1:SetPos( TargetPos )
-- Wake up the physics object so that the entity updates
Phys1:Wake()
-- Set the hinge Axis perpendicular to the trace hit surface
LPos1 = Phys1:WorldToLocal( WPos2 + Norm2 * 64 )
local constr, axis = constraint.Motor( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, friction, torque, time, nocollide, toggle, ply, limit, forekey, backkey, 1 )
if ( IsValid( constr ) ) then
undo.Create( "Motor" )
undo.AddEntity( constr )
if ( IsValid( axis ) ) then undo.AddEntity( axis ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.motor.name" )
undo.Finish( "#tool.motor.name" )
ply:AddCount( "constraints", constr )
ply:AddCleanup( "constraints", constr )
if ( IsValid( axis ) ) then ply:AddCleanup( "constraints", axis ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
self:ReleaseGhostEntity()
else
self:StartGhostEntity( trace.Entity )
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Motor" )
end
function TOOL:Think()
if ( self:NumObjects() != 1 ) then return end
self:UpdateGhostEntity()
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.motor.help" )
CPanel:ToolPresets( "motor", ConVarsDefault )
CPanel:KeyBinder( "#tool.motor.numpad1", "motor_fwd", "#tool.motor.numpad2", "motor_bwd" )
CPanel:NumSlider( "#tool.motor.torque", "motor_torque", 0, 10000 )
CPanel:NumSlider( "#tool.forcelimit", "motor_forcelimit", 0, 50000 )
CPanel:ControlHelp( "#tool.forcelimit.help" )
CPanel:NumSlider( "#tool.hingefriction", "motor_friction", 0, 100 )
CPanel:ControlHelp( "#tool.hingefriction.help" )
CPanel:NumSlider( "#tool.motor.forcetime", "motor_forcetime", 0, 120 )
CPanel:ControlHelp( "#tool.motor.forcetime.help" )
CPanel:CheckBox( "#tool.nocollide", "motor_nocollide" )
CPanel:ControlHelp( "#tool.nocollide.help" )
CPanel:CheckBox( "#tool.toggle", "motor_toggle" )
CPanel:ControlHelp( "#tool.toggle.help" )
end

View File

@@ -0,0 +1,267 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.muscle.name"
TOOL.ClientConVar[ "group" ] = "37"
TOOL.ClientConVar[ "width" ] = "2"
TOOL.ClientConVar[ "addlength" ] = "100"
TOOL.ClientConVar[ "fixed" ] = "1"
TOOL.ClientConVar[ "period" ] = "1"
TOOL.ClientConVar[ "material" ] = "cable/rope"
TOOL.ClientConVar[ "starton" ] = "0"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1, op = 1 },
{ name = "right", stage = 0 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
self:SetOperation( 1 )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
if ( ( !IsValid( self:GetEnt( 1 ) ) && !IsValid( self:GetEnt( 2 ) ) ) || iNum > 1 ) then
self:ClearObjects()
return true
end
-- Get client's CVars
local width = self:GetClientNumber( "width", 3 )
local bind = self:GetClientNumber( "group", 1 )
local AddLength = self:GetClientNumber( "addlength", 0 )
local fixed = self:GetClientNumber( "fixed", 1 )
local period = self:GetClientNumber( "period", 1 )
local starton = self:GetClientNumber( "starton" ) == 1
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- If AddLength is 0 then what's the point.
if ( AddLength == 0 ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
if ( period <= 0 ) then period = 0.1 end
AddLength = math.Clamp( AddLength, -1000, 1000 )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local Length1 = ( WPos1 - WPos2 ):Length()
local Length2 = Length1 + AddLength
local amp = Length2 - Length1
local constr, rope, controller, slider = constraint.Muscle( ply, Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, period, amp, starton, material, Color( colorR, colorG, colorB, 255 ) )
if ( IsValid( constr ) ) then
undo.Create( "Muscle" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
if ( IsValid( slider ) ) then undo.AddEntity( slider ) end
if ( IsValid( controller ) ) then undo.AddEntity( controller ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.muscle.name" )
undo.Finish( "#tool.muscle.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
if ( IsValid( slider ) ) then ply:AddCleanup( "ropeconstraints", slider ) end
if ( IsValid( controller ) ) then ply:AddCleanup( "ropeconstraints", controller ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:RightClick( trace )
if ( self:GetOperation() == 1 ) then return false end
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
local ply = self:GetOwner()
local tr_new = {}
tr_new.start = trace.HitPos
tr_new.endpos = trace.HitPos + ( trace.HitNormal * 16384 )
tr_new.filter = { ply }
if ( IsValid( trace.Entity ) ) then
table.insert( tr_new.filter, trace.Entity )
end
local tr = util.TraceLine( tr_new )
if ( !tr.Hit ) then
self:ClearObjects()
return false
end
-- Don't try to constrain world to world
if ( trace.HitWorld && tr.HitWorld ) then
self:ClearObjects()
return false
end
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then
self:ClearObjects()
return false
end
if ( IsValid( tr.Entity ) && tr.Entity:IsPlayer() ) then
self:ClearObjects()
return false
end
-- Check to see if the player can create a muscle constraint with the entity in the trace
if ( !hook.Run( "CanTool", ply, tr, "muscle", self, 2 ) ) then
self:ClearObjects()
return false
end
local Phys2 = tr.Entity:GetPhysicsObjectNum( tr.PhysicsBone )
self:SetObject( 2, tr.Entity, tr.HitPos, Phys2, tr.PhysicsBone, tr.HitNormal )
if ( CLIENT ) then
self:ClearObjects()
return true
end
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local width = self:GetClientNumber( "width", 3 )
local bind = self:GetClientNumber( "group", 1 )
local AddLength = self:GetClientNumber( "addlength", 0 )
local fixed = self:GetClientNumber( "fixed", 1 )
local period = self:GetClientNumber( "period", 64 )
local starton = self:GetClientNumber( "starton" ) > 0
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local Length1 = ( WPos1 - WPos2 ):Length()
local Length2 = Length1 + AddLength
local amp = Length2 - Length1
local constr, rope, controller, slider = constraint.Muscle( ply, Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, period, amp, starton, material, Color( colorR, colorG, colorB, 255 ) )
if ( IsValid( constr ) ) then
undo.Create( "Muscle" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
if ( IsValid( slider ) ) then undo.AddEntity( slider ) end
if ( IsValid( controller ) ) then undo.AddEntity( controller ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.muscle.name" )
undo.Finish( "#tool.muscle.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
if ( IsValid( slider ) ) then ply:AddCleanup( "ropeconstraints", slider ) end
if ( IsValid( controller ) ) then ply:AddCleanup( "ropeconstraints", controller ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Muscle" )
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.muscle.help" )
CPanel:ToolPresets( "muscle", ConVarsDefault )
CPanel:KeyBinder( "#tool.muscle.numpad", "muscle_group" )
CPanel:NumSlider( "#tool.muscle.length", "muscle_addlength", -1000, 1000 )
CPanel:ControlHelp( "#tool.muscle.length.help" )
CPanel:NumSlider( "#tool.muscle.period", "muscle_period", 0, 10 )
CPanel:ControlHelp( "#tool.muscle.period.help" )
CPanel:CheckBox( "#tool.muscle.fixed", "muscle_fixed" )
CPanel:ControlHelp( "#tool.muscle.fixed.help" )
CPanel:CheckBox( "#tool.muscle.starton", "muscle_starton" )
CPanel:ControlHelp( "#tool.muscle.starton.help" )
CPanel:NumSlider( "#tool.muscle.width", "muscle_width", 0, 5 )
CPanel:RopeSelect( "muscle_material" )
CPanel:ColorPicker( "#tool.muscle.color", "muscle_color_r", "muscle_color_g", "muscle_color_b" )
end

View File

@@ -0,0 +1,109 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.nocollide.name"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1 },
{ name = "right" },
{ name = "reload" }
}
cleanup.Register( "nocollide" )
function TOOL:LeftClick( trace )
if ( !IsValid( trace.Entity ) ) then return end
if ( trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( CLIENT ) then
if ( iNum > 0 ) then self:ClearObjects() end
return true
end
if ( iNum > 0 ) then
local ply = self:GetOwner()
if ( !ply:CheckLimit( "constraints" ) ) then
self:ClearObjects()
return false
end
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local constr = constraint.NoCollide( Ent1, Ent2, Bone1, Bone2, true )
if ( IsValid( constr ) ) then
undo.Create( "NoCollide" )
undo.AddEntity( constr )
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.nocollide.name" )
undo.Finish( "#tool.nocollide.name" )
ply:AddCount( "constraints", constr )
ply:AddCleanup( "nocollide", constr )
end
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:RightClick( trace )
if ( !IsValid( trace.Entity ) ) then return end
if ( trace.Entity:IsPlayer() ) then return end
if ( CLIENT ) then return true end
if ( trace.Entity:GetCollisionGroup() == COLLISION_GROUP_WORLD ) then
trace.Entity:SetCollisionGroup( COLLISION_GROUP_NONE )
else
trace.Entity:SetCollisionGroup( COLLISION_GROUP_WORLD )
end
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "NoCollide" )
end
function TOOL:Holster()
self:ClearObjects()
end
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.nocollide.desc" )
end

View File

@@ -0,0 +1,168 @@
TOOL.Category = "Render"
TOOL.Name = "#tool.paint.name"
TOOL.LeftClickAutomatic = true
TOOL.RightClickAutomatic = true
TOOL.RequiresTraceHit = true
TOOL.ClientConVar[ "decal" ] = "Blood"
TOOL.Information = {
{ name = "left" },
{ name = "right" },
{ name = "reload" }
}
local function PlaceDecal( ply, ent, data )
if ( !IsValid( ent ) && !ent:IsWorld() ) then return end
if ( CLIENT ) then return end
local bone
if ( data.bone && data.bone < ent:GetPhysicsObjectCount() ) then bone = ent:GetPhysicsObjectNum( data.bone ) end
if ( !IsValid( bone ) ) then bone = ent:GetPhysicsObject() end
if ( !IsValid( bone ) ) then bone = ent end
util.Decal( data.decal, bone:LocalToWorld( data.Pos1 ), bone:LocalToWorld( data.Pos2 ), ply )
local i = ent.DecalCount or 0
i = i + 1
duplicator.StoreEntityModifier( ent, "decal" .. i, data )
ent.DecalCount = i
end
--
-- Register decal duplicator
--
if ( SERVER ) then
for i = 1, 32 do
duplicator.RegisterEntityModifier( "decal" .. i, function( ply, ent, data )
timer.Simple( i * 0.05, function() PlaceDecal( ply, ent, data ) end )
end )
end
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) ) then return false end
trace.Entity:RemoveAllDecals()
if ( SERVER ) then
for i = 1, 32 do
duplicator.ClearEntityModifier( trace.Entity, "decal" .. i )
end
trace.Entity.DecalCount = nil
end
return true
end
function TOOL:LeftClick( trace )
return self:RightClick( trace, true )
end
function TOOL:RightClick( trace, bNoDelay )
self:GetWeapon():EmitSound( "SprayCan.Paint" )
local decal = self:GetClientInfo( "decal" )
local Pos1 = trace.HitPos + trace.HitNormal
local Pos2 = trace.HitPos - trace.HitNormal
local Bone
if ( trace.PhysicsBone && trace.PhysicsBone < trace.Entity:GetPhysicsObjectCount() ) then Bone = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone ) end
if ( !IsValid( Bone ) ) then Bone = trace.Entity:GetPhysicsObject() end
if ( !IsValid( Bone ) ) then Bone = trace.Entity end
Pos1 = Bone:WorldToLocal( Pos1 )
Pos2 = Bone:WorldToLocal( Pos2 )
PlaceDecal( self:GetOwner(), trace.Entity, { Pos1 = Pos1, Pos2 = Pos2, bone = trace.PhysicsBone, decal = decal } )
if ( bNoDelay ) then
self:GetWeapon():SetNextPrimaryFire( CurTime() + 0.05 )
self:GetWeapon():SetNextSecondaryFire( CurTime() + 0.05 )
else
self:GetWeapon():SetNextPrimaryFire( CurTime() + 0.2 )
self:GetWeapon():SetNextSecondaryFire( CurTime() + 0.2 )
end
return false
end
game.AddDecal( "Eye", "decals/eye" )
game.AddDecal( "Dark", "decals/dark" )
game.AddDecal( "Smile", "decals/smile" )
game.AddDecal( "Light", "decals/light" )
game.AddDecal( "Cross", "decals/cross" )
game.AddDecal( "Nought", "decals/nought" )
game.AddDecal( "Noughtsncrosses", "decals/noughtsncrosses" )
list.Add( "PaintMaterials", "Eye" )
list.Add( "PaintMaterials", "Smile" )
list.Add( "PaintMaterials", "Light" )
list.Add( "PaintMaterials", "Dark" )
list.Add( "PaintMaterials", "Blood" )
list.Add( "PaintMaterials", "YellowBlood" )
list.Add( "PaintMaterials", "Impact.Metal" )
list.Add( "PaintMaterials", "Scorch" )
list.Add( "PaintMaterials", "BeerSplash" )
list.Add( "PaintMaterials", "ExplosiveGunshot" )
list.Add( "PaintMaterials", "BirdPoop" )
list.Add( "PaintMaterials", "PaintSplatPink" )
list.Add( "PaintMaterials", "PaintSplatGreen" )
list.Add( "PaintMaterials", "PaintSplatBlue" )
list.Add( "PaintMaterials", "ManhackCut" )
list.Add( "PaintMaterials", "FadingScorch" )
list.Add( "PaintMaterials", "Antlion.Splat" )
list.Add( "PaintMaterials", "Splash.Large" )
list.Add( "PaintMaterials", "BulletProof" )
list.Add( "PaintMaterials", "GlassBreak" )
list.Add( "PaintMaterials", "Impact.Sand" )
list.Add( "PaintMaterials", "Impact.BloodyFlesh" )
list.Add( "PaintMaterials", "Impact.Antlion" )
list.Add( "PaintMaterials", "Impact.Glass" )
list.Add( "PaintMaterials", "Impact.Wood" )
list.Add( "PaintMaterials", "Impact.Concrete" )
list.Add( "PaintMaterials", "Noughtsncrosses" )
list.Add( "PaintMaterials", "Nought" )
list.Add( "PaintMaterials", "Cross" )
function TOOL.BuildCPanel( CPanel )
-- Remove duplicates.
local Options = {}
for id, str in ipairs( list.Get( "PaintMaterials" ) ) do
if ( !table.HasValue( Options, str ) ) then
table.insert( Options, str )
end
end
table.sort( Options )
local listbox = vgui.Create( "DListView" )
listbox:SetMultiSelect( false )
listbox:AddColumn( "#tool.paint.texture" )
listbox:SetTall( 17 + table.Count( Options ) * 17 )
listbox:SortByColumn( 1, false )
function listbox:OnRowSelected( LineID, Line )
for k, v in pairs( Line.data ) do
RunConsoleCommand( k, v )
end
end
for k, decal in ipairs( Options ) do
local line = listbox:AddLine( decal )
line.data = { paint_decal = decal, gmod_tool = "paint" }
if ( GetConVarString( "paint_decal" ) == tostring( decal ) ) then line:SetSelected( true ) end
end
CPanel:AddItem( listbox )
end

View File

@@ -0,0 +1,63 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.physprop.name"
TOOL.ClientConVar[ "gravity_toggle" ] = "1"
TOOL.ClientConVar[ "material" ] = "metal_bouncy"
TOOL.Information = { { name = "left" } }
function TOOL:LeftClick( trace )
if ( !IsValid( trace.Entity ) ) then return false end
if ( trace.Entity:IsPlayer() || trace.Entity:IsWorld() ) then return false end
-- Make sure there's a physics object to manipulate
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
-- Client can bail out here and assume we're going ahead
if ( CLIENT ) then return true end
-- Get the entity/bone from the trace
local ent = trace.Entity
local Bone = trace.PhysicsBone
-- Get client's CVars
local gravity = self:GetClientNumber( "gravity_toggle" ) == 1
local material = self:GetClientInfo( "material" )
-- Set the properties
construct.SetPhysProp( self:GetOwner(), ent, Bone, nil, { GravityToggle = gravity, Material = material } )
DoPropSpawnedEffect( ent )
return true
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:ToolPresets( "physprop", ConVarsDefault )
CPanel:ComboBoxMulti( "#tool.physprop.material", list.Get( "PhysicsMaterials" ) )
CPanel:CheckBox( "#tool.physprop.gravity", "physprop_gravity_toggle" )
end
list.Set( "PhysicsMaterials", "#physprop.metalbouncy", { physprop_material = "metal_bouncy" } )
list.Set( "PhysicsMaterials", "#physprop.metal", { physprop_material = "metal" } )
list.Set( "PhysicsMaterials", "#physprop.dirt", { physprop_material = "dirt" } )
list.Set( "PhysicsMaterials", "#physprop.slime", { physprop_material = "slipperyslime" } )
list.Set( "PhysicsMaterials", "#physprop.wood", { physprop_material = "wood" } )
list.Set( "PhysicsMaterials", "#physprop.glass", { physprop_material = "glass" } )
list.Set( "PhysicsMaterials", "#physprop.concrete", { physprop_material = "concrete_block" } )
list.Set( "PhysicsMaterials", "#physprop.ice", { physprop_material = "ice" } )
list.Set( "PhysicsMaterials", "#physprop.rubber", { physprop_material = "rubber" } )
list.Set( "PhysicsMaterials", "#physprop.paper", { physprop_material = "paper" } )
list.Set( "PhysicsMaterials", "#physprop.flesh", { physprop_material = "zombieflesh" } )
list.Set( "PhysicsMaterials", "#physprop.superice", { physprop_material = "gmod_ice" } )
list.Set( "PhysicsMaterials", "#physprop.superbouncy", { physprop_material = "gmod_bouncy" } )

View File

@@ -0,0 +1,126 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.pulley.name"
TOOL.ClientConVar[ "width" ] = "3"
TOOL.ClientConVar[ "forcelimit" ] = "0"
TOOL.ClientConVar[ "rigid" ] = "0"
TOOL.ClientConVar[ "material" ] = "cable/cable"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1 },
{ name = "left_2", stage = 2 },
{ name = "left_3", stage = 3 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
if ( !IsValid( trace.Entity ) && ( iNum == nil || iNum == 0 || iNum > 2 ) ) then return false end
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( iNum > 2 ) then
if ( CLIENT ) then return true end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
local width = self:GetClientNumber( "width" )
local forcelimit = self:GetClientNumber( "forcelimit" )
local rigid = self:GetClientNumber( "rigid" ) == 1
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1 = self:GetEnt( 1 )
local Ent4 = self:GetEnt( 4 )
local Bone1 = self:GetBone( 1 )
local Bone4 = self:GetBone( 4 )
local LPos1 = self:GetLocalPos( 1 )
local LPos4 = self:GetLocalPos( 4 )
local WPos2 = self:GetPos( 2 )
local WPos3 = self:GetPos( 3 )
local constr, rope1, rope2, rope3 = constraint.Pulley( Ent1, Ent4, Bone1, Bone4, LPos1, LPos4, WPos2, WPos3, forcelimit, rigid, width, material, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
undo.Create( "Pulley" )
undo.AddEntity( constr )
if ( IsValid( rope1 ) ) then undo.AddEntity( rope1 ) end
if ( IsValid( rope2 ) ) then undo.AddEntity( rope2 ) end
if ( IsValid( rope3 ) ) then undo.AddEntity( rope3 ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.pulley.name" )
undo.Finish( "#tool.pulley.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope1 ) ) then ply:AddCleanup( "ropeconstraints", rope1 ) end
if ( IsValid( rope2 ) ) then ply:AddCleanup( "ropeconstraints", rope2 ) end
if ( IsValid( rope3 ) ) then ply:AddCleanup( "ropeconstraints", rope3 ) end
end
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Pulley" )
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.pulley.help" )
CPanel:ToolPresets( "pulley", ConVarsDefault )
CPanel:NumSlider( "#tool.forcelimit", "pulley_forcelimit", 0, 1000 )
CPanel:ControlHelp( "#tool.forcelimit.help" )
CPanel:CheckBox( "#tool.pulley.rigid", "pulley_rigid" )
CPanel:ControlHelp( "#tool.pulley.rigid.help" )
CPanel:NumSlider( "#tool.pulley.width", "pulley_width", 0, 10 )
CPanel:RopeSelect( "pulley_material" )
CPanel:ColorPicker( "#tool.pulley.color", "pulley_color_r", "pulley_color_g", "pulley_color_b" )
end

View File

@@ -0,0 +1,103 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.remover.name"
TOOL.Information = {
{ name = "left" },
{ name = "right" },
{ name = "reload" }
}
local function DoRemoveEntity( ent )
if ( !IsValid( ent ) || ent:IsPlayer() ) then return false end
-- Nothing for the client to do here
if ( CLIENT ) then return true end
-- Remove all constraints (this stops ropes from hanging around)
constraint.RemoveAll( ent )
-- Remove it properly in 1 second
timer.Simple( 1, function() if ( IsValid( ent ) ) then ent:Remove() end end )
-- Make it non solid
ent:SetNotSolid( true )
ent:SetMoveType( MOVETYPE_NONE )
ent:SetNoDraw( true )
-- Send Effect
local ed = EffectData()
ed:SetOrigin( ent:GetPos() )
ed:SetEntity( ent )
util.Effect( "entity_remove", ed, true, true )
return true
end
--
-- Remove a single entity
--
function TOOL:LeftClick( trace )
if ( DoRemoveEntity( trace.Entity ) ) then
if ( !CLIENT ) then
self:GetOwner():SendLua( "achievements.Remover()" )
end
return true
end
return false
end
--
-- Remove this entity and everything constrained
--
function TOOL:RightClick( trace )
local entity = trace.Entity
if ( !IsValid( entity ) || entity:IsPlayer() ) then return false end
-- Client can bail out now.
if ( CLIENT ) then return true end
local ConstrainedEntities = constraint.GetAllConstrainedEntities( entity )
local Count = 0
-- Loop through all the entities in the system
for _, ent in pairs( ConstrainedEntities ) do
if ( DoRemoveEntity( ent ) ) then
Count = Count + 1
end
end
self:GetOwner():SendLua( string.format( "for i=1,%i do achievements.Remover() end", Count ) )
return true
end
--
-- Reload removes all constraints on the targetted entity
--
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveAll( trace.Entity )
end
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.remover.desc" )
end

View File

@@ -0,0 +1,201 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.rope.name"
TOOL.ClientConVar[ "forcelimit" ] = "0"
TOOL.ClientConVar[ "addlength" ] = "0"
TOOL.ClientConVar[ "material" ] = "cable/rope"
TOOL.ClientConVar[ "width" ] = "2"
TOOL.ClientConVar[ "rigid" ] = "0"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1 },
{ name = "right", stage = 1 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local forcelimit = self:GetClientNumber( "forcelimit" )
local addlength = self:GetClientNumber( "addlength" )
local material = self:GetClientInfo( "material" )
local width = self:GetClientNumber( "width" )
local rigid = self:GetClientNumber( "rigid" ) == 1
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local length = ( WPos1 - WPos2 ):Length()
local constr, rope = constraint.Rope( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, length, addlength, forcelimit, width, material, rigid, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
-- Add the constraint to the players undo table
undo.Create( "Rope" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.rope.name" )
undo.Finish( "#tool.rope.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:RightClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local forcelimit = self:GetClientNumber( "forcelimit" )
local addlength = self:GetClientNumber( "addlength" )
local material = self:GetClientInfo( "material" )
local width = self:GetClientNumber( "width" )
local rigid = self:GetClientNumber( "rigid" ) == 1
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local length = ( WPos1 - WPos2 ):Length()
local constr, rope = constraint.Rope( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, length, addlength, forcelimit, width, material, rigid, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
-- Add the constraint to the players undo table
undo.Create( "Rope" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.rope.name" )
undo.Finish( "#tool.rope.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
end
-- Clear the objects and set the last object as object 1
self:ClearObjects()
iNum = self:NumObjects()
self:SetObject( iNum + 1, Ent2, trace.HitPos, Phys, Bone2, trace.HitNormal )
self:SetStage( iNum + 1 )
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Rope" )
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.rope.help" )
CPanel:ToolPresets( "rope", ConVarsDefault )
CPanel:NumSlider( "#tool.forcelimit", "rope_forcelimit", 0, 1000 )
CPanel:ControlHelp( "#tool.forcelimit.help" )
CPanel:NumSlider( "#tool.rope.addlength", "rope_addlength", -500, 500 )
CPanel:ControlHelp( "#tool.rope.addlength.help" )
CPanel:CheckBox( "#tool.rope.rigid", "rope_rigid" )
CPanel:ControlHelp( "#tool.rope.rigid.help" )
CPanel:NumSlider( "#tool.rope.width", "rope_width", 0, 10 )
CPanel:RopeSelect( "rope_material" )
CPanel:ColorPicker( "#tool.rope.color", "rope_color_r", "rope_color_g", "rope_color_b" )
end

View File

@@ -0,0 +1,201 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.slider.name"
TOOL.ClientConVar[ "width" ] = "1.5"
TOOL.ClientConVar[ "material" ] = "cable/cable"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1, op = 1 },
{ name = "right", stage = 0 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
self:SetOperation( 1 )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local width = self:GetClientNumber( "width", 1.5 )
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local constr, rope = constraint.Slider( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, material, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
undo.Create( "Slider" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.slider.name" )
undo.Finish( "#tool.slider.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:RightClick( trace )
if ( self:GetOperation() == 1 ) then return false end
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
local tr_new = {}
tr_new.start = trace.HitPos
tr_new.endpos = trace.HitPos + ( trace.HitNormal * 16384 )
tr_new.filter = { self:GetOwner() }
if ( IsValid( trace.Entity ) ) then
table.insert( tr_new.filter, trace.Entity )
end
local tr = util.TraceLine( tr_new )
if ( !tr.Hit ) then
self:ClearObjects()
return
end
-- Don't try to constrain world to world
if ( trace.HitWorld && tr.HitWorld ) then
self:ClearObjects()
return
end
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then
self:ClearObjects()
return
end
if ( IsValid( tr.Entity ) && tr.Entity:IsPlayer() ) then
self:ClearObjects()
return
end
-- Check to see if the player can create a slider constraint with the entity in the trace
if ( !hook.Run( "CanTool", self:GetOwner(), tr, "slider", self, 2 ) ) then
self:ClearObjects()
return
end
local Phys2 = tr.Entity:GetPhysicsObjectNum( tr.PhysicsBone )
self:SetObject( 2, tr.Entity, tr.HitPos, Phys2, tr.PhysicsBone, trace.HitNormal )
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
local width = self:GetClientNumber( "width", 1.5 )
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local constr, rope = constraint.Slider( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, material, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
undo.Create( "Slider" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.slider.name" )
undo.Finish( "#tool.slider.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Slider" )
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.slider.help" )
CPanel:ToolPresets( "slider", ConVarsDefault )
CPanel:NumSlider( "#tool.slider.width", "slider_width", 0, 10 )
CPanel:RopeSelect( "slider_material" )
CPanel:ColorPicker( "#tool.slider.color", "slider_color_r", "slider_color_g", "slider_color_b" )
end

View File

@@ -0,0 +1,295 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.thruster.name"
TOOL.ClientConVar[ "force" ] = "1500"
TOOL.ClientConVar[ "model" ] = "models/props_phx2/garbage_metalcan001a.mdl"
TOOL.ClientConVar[ "keygroup" ] = "45"
TOOL.ClientConVar[ "keygroup_back" ] = "42"
TOOL.ClientConVar[ "toggle" ] = "0"
TOOL.ClientConVar[ "collision" ] = "0"
TOOL.ClientConVar[ "effect" ] = "fire"
TOOL.ClientConVar[ "damageable" ] = "0"
TOOL.ClientConVar[ "soundname" ] = "PhysicsCannister.ThrusterLoop"
TOOL.Information = { { name = "left" } }
cleanup.Register( "thrusters" )
local function IsValidThrusterModel( model )
for mdl, _ in pairs( list.Get( "ThrusterModels" ) ) do
if ( mdl:lower() == model:lower() ) then return true end
end
return false
end
function TOOL:LeftClick( trace )
if ( trace.Entity && trace.Entity:IsPlayer() ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
if ( CLIENT ) then return true end
local ply = self:GetOwner()
local force = math.Clamp( self:GetClientNumber( "force" ), 0, 1E10 )
local model = self:GetClientInfo( "model" )
local key = self:GetClientNumber( "keygroup" )
local key_bk = self:GetClientNumber( "keygroup_back" )
local toggle = self:GetClientNumber( "toggle" )
local collision = self:GetClientNumber( "collision" ) == 0
local effect = self:GetClientInfo( "effect" )
local damageable = self:GetClientNumber( "damageable" )
local soundname = self:GetClientInfo( "soundname" )
-- If we shot a thruster change its force
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_thruster" && trace.Entity.pl == ply ) then
trace.Entity:SetForce( force )
trace.Entity:SetEffect( effect )
trace.Entity:SetToggle( toggle == 1 )
trace.Entity.ActivateOnDamage = damageable == 1
trace.Entity:SetSound( soundname )
numpad.Remove( trace.Entity.NumDown )
numpad.Remove( trace.Entity.NumUp )
numpad.Remove( trace.Entity.NumBackDown )
numpad.Remove( trace.Entity.NumBackUp )
trace.Entity.NumDown = numpad.OnDown( ply, key, "Thruster_On", trace.Entity, 1 )
trace.Entity.NumUp = numpad.OnUp( ply, key, "Thruster_Off", trace.Entity, 1 )
trace.Entity.NumBackDown = numpad.OnDown( ply, key_bk, "Thruster_On", trace.Entity, -1 )
trace.Entity.NumBackUp = numpad.OnUp( ply, key_bk, "Thruster_Off", trace.Entity, -1 )
trace.Entity.key = key
trace.Entity.key_bk = key_bk
trace.Entity.force = force
trace.Entity.toggle = toggle
trace.Entity.effect = effect
trace.Entity.damageable = damageable
return true
end
if ( !util.IsValidModel( model ) || !util.IsValidProp( model ) || !IsValidThrusterModel( model ) ) then return false end
if ( !self:GetWeapon():CheckLimit( "thrusters" ) ) then return false end
local Ang = trace.HitNormal:Angle()
Ang.pitch = Ang.pitch + 90
local thruster = MakeThruster( ply, model, Ang, trace.HitPos, key, key_bk, force, toggle, effect, damageable, soundname )
if ( !IsValid( thruster ) ) then return false end
local min = thruster:OBBMins()
thruster:SetPos( trace.HitPos - trace.HitNormal * min.z )
undo.Create( "gmod_thruster" )
undo.AddEntity( thruster )
-- Don't weld to world
if ( IsValid( trace.Entity ) ) then
local weld = constraint.Weld( thruster, trace.Entity, 0, trace.PhysicsBone, 0, collision, true )
if ( IsValid( weld ) ) then
ply:AddCleanup( "thrusters", weld )
undo.AddEntity( weld )
end
-- Don't disable collision if it's not attached to anything
if ( collision ) then
if ( IsValid( thruster:GetPhysicsObject() ) ) then thruster:GetPhysicsObject():EnableCollisions( false ) end
thruster:SetCollisionGroup( COLLISION_GROUP_WORLD )
thruster.nocollide = true
end
end
undo.SetPlayer( ply )
undo.Finish()
return true
end
if ( SERVER ) then
function MakeThruster( ply, model, ang, pos, key, key_bck, force, toggle, effect, damageable, soundname, nocollide, Data )
if ( IsValid( ply ) && !ply:CheckLimit( "thrusters" ) ) then return NULL end
if ( !IsValidThrusterModel( model ) ) then return NULL end
local thruster = ents.Create( "gmod_thruster" )
if ( !IsValid( thruster ) ) then return NULL end
duplicator.DoGeneric( thruster, Data )
thruster:SetModel( model ) -- Backwards compatible for addons directly calling this function
thruster:SetAngles( ang )
thruster:SetPos( pos )
thruster:Spawn()
DoPropSpawnedEffect( thruster )
duplicator.DoGenericPhysics( thruster, ply, Data )
force = math.Clamp( force, 0, 1E10 )
thruster:SetEffect( effect )
thruster:SetForce( force )
thruster:SetToggle( toggle == 1 )
thruster.ActivateOnDamage = ( damageable == 1 )
thruster:SetPlayer( ply )
thruster:SetSound( soundname )
thruster.NumDown = numpad.OnDown( ply, key, "Thruster_On", thruster, 1 )
thruster.NumUp = numpad.OnUp( ply, key, "Thruster_Off", thruster, 1 )
thruster.NumBackDown = numpad.OnDown( ply, key_bck, "Thruster_On", thruster, -1 )
thruster.NumBackUp = numpad.OnUp( ply, key_bck, "Thruster_Off", thruster, -1 )
if ( nocollide == true ) then
if ( IsValid( thruster:GetPhysicsObject() ) ) then thruster:GetPhysicsObject():EnableCollisions( false ) end
thruster:SetCollisionGroup( COLLISION_GROUP_WORLD )
end
table.Merge( thruster:GetTable(), {
key = key,
key_bck = key_bck,
force = force,
toggle = toggle,
pl = ply,
effect = effect,
nocollide = nocollide,
damageable = damageable,
soundname = soundname
} )
if ( IsValid( ply ) ) then
ply:AddCount( "thrusters", thruster )
ply:AddCleanup( "thrusters", thruster )
end
return thruster
end
duplicator.RegisterEntityClass( "gmod_thruster", MakeThruster, "Model", "Ang", "Pos", "key", "key_bck", "force", "toggle", "effect", "damageable", "soundname", "nocollide", "Data" )
end
function TOOL:UpdateGhostThruster( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit || IsValid( trace.Entity ) && ( trace.Entity:GetClass() == "gmod_thruster" || trace.Entity:IsPlayer() ) ) then
ent:SetNoDraw( true )
return
end
local ang = trace.HitNormal:Angle()
ang.pitch = ang.pitch + 90
local min = ent:OBBMins()
ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
ent:SetAngles( ang )
ent:SetNoDraw( false )
end
function TOOL:Think()
local mdl = self:GetClientInfo( "model" )
if ( !IsValidThrusterModel( mdl ) ) then self:ReleaseGhostEntity() return end
if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != mdl:lower() ) then
self:MakeGhostEntity( mdl, vector_origin, angle_zero )
end
self:UpdateGhostThruster( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.thruster.desc" )
CPanel:ToolPresets( "thruster", ConVarsDefault )
CPanel:KeyBinder( "#tool.thruster.forward", "thruster_keygroup", "#tool.thruster.back", "thruster_keygroup_back" )
CPanel:NumSlider( "#tool.thruster.force", "thruster_force", 1, 10000 )
local combo = CPanel:ComboBoxMulti( "#tool.thruster.effect" )
for k, v in pairs( list.Get( "ThrusterEffects" ) ) do
combo:AddOption( k, { thruster_effect = v.thruster_effect } )
end
CPanel:ComboBoxMulti( "#tool.thruster.sound", list.Get( "ThrusterSounds" ) )
CPanel:CheckBox( "#tool.thruster.toggle", "thruster_toggle" )
CPanel:CheckBox( "#tool.thruster.collision", "thruster_collision" )
CPanel:CheckBox( "#tool.thruster.damagable", "thruster_damageable" )
CPanel:PropSelect( "#tool.thruster.model", "thruster_model", list.Get( "ThrusterModels" ), 0 )
end
list.Set( "ThrusterSounds", "#thrustersounds.none", { thruster_soundname = "" } )
list.Set( "ThrusterSounds", "#thrustersounds.steam", { thruster_soundname = "PhysicsCannister.ThrusterLoop" } )
list.Set( "ThrusterSounds", "#thrustersounds.zap", { thruster_soundname = "WeaponDissolve.Charge" } )
list.Set( "ThrusterSounds", "#thrustersounds.beam", { thruster_soundname = "WeaponDissolve.Beam" } )
list.Set( "ThrusterSounds", "#thrustersounds.elevator", { thruster_soundname = "eli_lab.elevator_move" } )
list.Set( "ThrusterSounds", "#thrustersounds.energy", { thruster_soundname = "combine.sheild_loop" } )
list.Set( "ThrusterSounds", "#thrustersounds.ring", { thruster_soundname = "k_lab.ringsrotating" } )
list.Set( "ThrusterSounds", "#thrustersounds.resonance", { thruster_soundname = "k_lab.teleport_rings_high" } )
list.Set( "ThrusterSounds", "#thrustersounds.dropship", { thruster_soundname = "k_lab2.DropshipRotorLoop" } )
list.Set( "ThrusterSounds", "#thrustersounds.machine", { thruster_soundname = "Town.d1_town_01_spin_loop" } )
list.Set( "ThrusterModels", "models/dav0r/thruster.mdl", {} )
list.Set( "ThrusterModels", "models/MaxOfS2D/thruster_projector.mdl", {} )
list.Set( "ThrusterModels", "models/MaxOfS2D/thruster_propeller.mdl", {} )
list.Set( "ThrusterModels", "models/thrusters/jetpack.mdl", {} )
list.Set( "ThrusterModels", "models/props_junk/plasticbucket001a.mdl", {} )
list.Set( "ThrusterModels", "models/props_junk/PropaneCanister001a.mdl", {} )
list.Set( "ThrusterModels", "models/props_junk/propane_tank001a.mdl", {} )
list.Set( "ThrusterModels", "models/props_junk/PopCan01a.mdl", {} )
list.Set( "ThrusterModels", "models/props_junk/MetalBucket01a.mdl", {} )
list.Set( "ThrusterModels", "models/props_lab/jar01a.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/lampShade001a.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/canister_propane01a.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/canister01a.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/canister02a.mdl", {} )
list.Set( "ThrusterModels", "models/props_trainstation/trainstation_ornament002.mdl", {} )
list.Set( "ThrusterModels", "models/props_junk/TrafficCone001a.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/clock01.mdl", {} )
list.Set( "ThrusterModels", "models/props_junk/terracotta01.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/TrapPropeller_Engine.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/FurnitureSink001a.mdl", {} )
list.Set( "ThrusterModels", "models/props_trainstation/trainstation_ornament001.mdl", {} )
list.Set( "ThrusterModels", "models/props_trainstation/trashcan_indoor001b.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/pottery02a.mdl", {} )
list.Set( "ThrusterModels", "models/props_c17/pottery03a.mdl", {} )
--PHX
list.Set( "ThrusterModels", "models/props_phx2/garbage_metalcan001a.mdl", {} )
--Tile Model Pack Thrusters
list.Set( "ThrusterModels", "models/hunter/plates/plate.mdl", {} )
list.Set( "ThrusterModels", "models/hunter/blocks/cube025x025x025.mdl", {} )
--XQM Model Pack Thrusters
list.Set( "ThrusterModels", "models/XQM/AfterBurner1.mdl", {} )
list.Set( "ThrusterModels", "models/XQM/AfterBurner1Medium.mdl", {} )
list.Set( "ThrusterModels", "models/XQM/AfterBurner1Big.mdl", {} )
list.Set( "ThrusterModels", "models/XQM/AfterBurner1Huge.mdl", {} )
list.Set( "ThrusterModels", "models/XQM/AfterBurner1Large.mdl", {} )

View File

@@ -0,0 +1,161 @@
TOOL.Category = "Render"
TOOL.Name = "#tool.trails.name"
TOOL.ClientConVar[ "r" ] = 255
TOOL.ClientConVar[ "g" ] = 255
TOOL.ClientConVar[ "b" ] = 255
TOOL.ClientConVar[ "a" ] = 255
TOOL.ClientConVar[ "length" ] = 5
TOOL.ClientConVar[ "startsize" ] = 32
TOOL.ClientConVar[ "endsize" ] = 0
TOOL.ClientConVar[ "material" ] = "trails/lol"
TOOL.Information = {
{ name = "left" },
{ name = "right" }
}
cleanup.Register( "trails" )
local function SetTrails( ply, ent, data )
if ( IsValid( ent.SToolTrail ) ) then
ent.SToolTrail:Remove()
ent.SToolTrail = nil
end
if ( !data ) then
duplicator.ClearEntityModifier( ent, "trail" )
return
end
-- Just don't even bother with invisible trails
if ( data.StartSize <= 0 && data.EndSize <= 0 ) then return end
-- This is here to fix crash exploits
if ( !game.SinglePlayer() ) then
-- Lock down the trail material - only allow what the server allows
if ( !list.Contains( "trail_materials", data.Material ) ) then return end
-- Clamp sizes in multiplayer
data.Length = math.Clamp( data.Length, 0.1, 10 )
data.EndSize = math.Clamp( data.EndSize, 0, 128 )
data.StartSize = math.Clamp( data.StartSize, 0, 128 )
end
data.StartSize = math.max( 0.0001, data.StartSize )
local trail_entity = util.SpriteTrail( ent, 0, data.Color, false, data.StartSize, data.EndSize, data.Length, 1 / ( ( data.StartSize + data.EndSize ) * 0.5 ), data.Material .. ".vmt" )
ent.SToolTrail = trail_entity
if ( IsValid( ply ) ) then
ply:AddCleanup( "trails", trail_entity )
end
duplicator.StoreEntityModifier( ent, "trail", data )
return trail_entity
end
if ( SERVER ) then
duplicator.RegisterEntityModifier( "trail", SetTrails )
end
function TOOL:LeftClick( trace )
if ( !IsValid( trace.Entity ) ) then return false end
if ( trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
local r = math.Clamp( self:GetClientNumber( "r", 255 ), 0, 255 )
local g = math.Clamp( self:GetClientNumber( "g", 255 ), 0, 255 )
local b = math.Clamp( self:GetClientNumber( "b", 255 ), 0, 255 )
local a = math.Clamp( self:GetClientNumber( "a", 255 ), 0, 255 )
local length = self:GetClientNumber( "length", 5 )
local endsize = self:GetClientNumber( "endsize", 0 )
local startsize = self:GetClientNumber( "startsize", 32 )
local mat = self:GetClientInfo( "material" )
local trail = SetTrails( self:GetOwner(), trace.Entity, {
Color = Color( r, g, b, a ),
Length = length,
StartSize = startsize,
EndSize = endsize,
Material = mat
} )
if ( IsValid( trail ) ) then
undo.Create( "Trail" )
undo.AddEntity( trail )
undo.SetPlayer( self:GetOwner() )
undo.SetCustomUndoText( "Undone #tool.trails.name" )
undo.Finish( "#tool.trails.name" )
end
return true
end
function TOOL:RightClick( trace )
if ( !IsValid( trace.Entity ) ) then return false end
if ( trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
SetTrails( self:GetOwner(), trace.Entity, nil )
return true
end
--
-- Add default materials to list
-- Note: Addons can easily add to this list in their -- own file placed in autorun or something.
--
list.Set( "trail_materials", "#trail.plasma", "trails/plasma" )
list.Set( "trail_materials", "#trail.tube", "trails/tube" )
list.Set( "trail_materials", "#trail.electric", "trails/electric" )
list.Set( "trail_materials", "#trail.smoke", "trails/smoke" )
list.Set( "trail_materials", "#trail.laser", "trails/laser" )
list.Set( "trail_materials", "#trail.physbeam", "trails/physbeam" )
list.Set( "trail_materials", "#trail.love", "trails/love" )
list.Set( "trail_materials", "#trail.lol", "trails/lol" )
if ( IsMounted( "tf" ) ) then
list.Set( "trail_materials", "#trail.beam001_blu", "effects/beam001_blu" )
list.Set( "trail_materials", "#trail.beam001_red", "effects/beam001_red" )
list.Set( "trail_materials", "#trail.beam001_white", "effects/beam001_white" )
list.Set( "trail_materials", "#trail.arrowtrail_blu", "effects/arrowtrail_blu" )
list.Set( "trail_materials", "#trail.arrowtrail_red", "effects/arrowtrail_red" )
list.Set( "trail_materials", "#trail.repair_claw_trail_blue", "effects/repair_claw_trail_blue" )
list.Set( "trail_materials", "#trail.repair_claw_trail_red", "effects/repair_claw_trail_red" )
list.Set( "trail_materials", "#trail.australiumtrail_red", "effects/australiumtrail_red" )
list.Set( "trail_materials", "#trail.beam_generic01", "effects/beam_generic01" )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.trails.desc" )
CPanel:ToolPresets( "trails", ConVarsDefault )
CPanel:ColorPicker( "#tool.trails.color", "trails_r", "trails_g", "trails_b", "trails_a" )
CPanel:NumSlider( "#tool.trails.length", "trails_length", 0, 10 )
CPanel:NumSlider( "#tool.trails.startsize", "trails_startsize", 0, 128 )
CPanel:NumSlider( "#tool.trails.endsize", "trails_endsize", 0, 128 )
CPanel:MatSelect( "trails_material", list.Get( "trail_materials" ), true, 0.25, 0.25 )
end

View File

@@ -0,0 +1,301 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.weld.name"
TOOL.ClientConVar[ "forcelimit" ] = "0"
TOOL.ClientConVar[ "nocollide" ] = "0"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1, op = 2 },
{ name = "right", stage = 0 },
{ name = "right_1", stage = 1, op = 1 },
{ name = "right_2", stage = 2, op = 1 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( self:GetOperation() == 1 ) then return false end
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
if ( CLIENT ) then
if ( iNum > 0 ) then self:ClearObjects() end
return true
end
self:SetOperation( 2 )
if ( iNum == 0 ) then
self:SetStage( 1 )
return true
end
if ( iNum == 1 ) then
local ply = self:GetOwner()
if ( !ply:CheckLimit( "constraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local forcelimit = self:GetClientNumber( "forcelimit" )
local nocollide = self:GetClientNumber( "nocollide", 0 ) != 0
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local constr = constraint.Weld( Ent1, Ent2, Bone1, Bone2, forcelimit, nocollide )
if ( IsValid( constr ) ) then
undo.Create( "Weld" )
undo.AddEntity( constr )
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.weld.name" )
undo.Finish( "#tool.weld.name" )
ply:AddCount( "constraints", constr )
ply:AddCleanup( "constraints", constr )
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
end
return true
end
function TOOL:RightClick( trace )
if ( self:GetOperation() == 2 ) then return false end
-- Make sure the object we're about to use is valid
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
-- You can click anywhere on the 3rd pass
if ( iNum < 2 ) then
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
-- Don't weld players, or to players
if ( trace.Entity:IsPlayer() ) then return false end
-- Don't do anything with stuff without any physics..
if ( SERVER && !IsValid( Phys ) ) then return false end
end
if ( iNum == 0 ) then
if ( !IsValid( trace.Entity ) ) then return false end
if ( trace.Entity:GetClass() == "prop_vehicle_jeep" ) then return false end
end
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
self:SetOperation( 1 )
--
-- Stage 0 - grab an object, make a ghost entity
--
if ( iNum == 0 ) then
self:StartGhostEntity( trace.Entity )
self:SetStage( 1 )
return true
end
--
-- Stage 1 - choose the spot and object to weld it to
--
if ( iNum == 1 ) then
if ( CLIENT ) then
self:ReleaseGhostEntity()
return true
end
-- Get information we're about to use
local Norm1, Norm2 = self:GetNormal( 1 ), self:GetNormal( 2 )
local Phys1 = self:GetPhys( 1 )
local WPos2 = self:GetPos( 2 )
-- Note: To keep stuff ragdoll friendly try to treat things as physics objects rather than entities
local Ang1, Ang2 = Norm1:Angle(), ( -Norm2 ):Angle()
local TargetAngle = Phys1:AlignAngles( Ang1, Ang2 )
Phys1:SetAngles( TargetAngle )
-- Move the object so that the hitpos on our object is at the second hitpos
local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) )
-- Set the position
Phys1:SetPos( TargetPos )
Phys1:EnableMotion( false )
-- Wake up the physics object so that the entity updates
Phys1:Wake()
self.RotAxis = Norm2
self:ReleaseGhostEntity()
self:SetStage( 2 )
return true
end
--
-- Stage 2 - Weld it in place.
--
if ( iNum == 2 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "constraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local forcelimit = self:GetClientNumber( "forcelimit" )
local nocollide = self:GetClientNumber( "nocollide", 0 ) != 0
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local Phys1 = self:GetPhys( 1 )
-- The entity became invalid half way through
if ( !IsValid( Ent1 ) ) then
self:ClearObjects()
return false
end
local constr = constraint.Weld( Ent1, Ent2, Bone1, Bone2, forcelimit, nocollide )
if ( IsValid( constr ) ) then
Phys1:EnableMotion( true )
undo.Create( "Weld" )
undo.AddEntity( constr )
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.weld.name" )
undo.Finish( "#tool.weld.name" )
ply:AddCount( "constraints", constr )
ply:AddCleanup( "constraints", constr )
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
return true
end
end
function TOOL:Think()
if ( self:NumObjects() < 1 ) then return end
if ( self:GetOperation() == 1 ) then
if ( SERVER && !IsValid( self:GetEnt( 1 ) ) ) then
self:ClearObjects()
return
end
if ( self:NumObjects() == 1 ) then
self:UpdateGhostEntity()
return
end
if ( SERVER && self:NumObjects() == 2 ) then
local Phys1 = self:GetPhys( 1 )
local cmd = self:GetOwner():GetCurrentCommand()
local degrees = cmd:GetMouseX() * 0.05
local angle = Phys1:RotateAroundAxis( self.RotAxis, degrees )
Phys1:SetAngles( angle )
-- Move so spots join up
local TargetPos = self:GetPos( 2 ) + ( Phys1:GetPos() - self:GetPos( 1 ) )
Phys1:SetPos( TargetPos )
Phys1:Wake()
end
end
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
self:ClearObjects()
return constraint.RemoveConstraints( trace.Entity, "Weld" )
end
function TOOL:FreezeMovement()
return self:GetOperation() == 1 && self:GetStage() == 2
end
function TOOL:Holster()
self:ClearObjects()
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.weld.help" )
CPanel:ToolPresets( "weld", ConVarsDefault )
CPanel:NumSlider( "#tool.forcelimit", "weld_forcelimit", 0, 1000 )
CPanel:ControlHelp( "#tool.forcelimit.help" )
CPanel:CheckBox( "#tool.nocollide", "weld_nocollide" )
end

View File

@@ -0,0 +1,449 @@
TOOL.Category = "Construction"
TOOL.Name = "#tool.wheel.name"
TOOL.ClientConVar[ "torque" ] = "3000"
TOOL.ClientConVar[ "friction" ] = "1"
TOOL.ClientConVar[ "nocollide" ] = "1"
TOOL.ClientConVar[ "forcelimit" ] = "0"
TOOL.ClientConVar[ "fwd" ] = "45"
TOOL.ClientConVar[ "bck" ] = "42"
TOOL.ClientConVar[ "toggle" ] = "0"
TOOL.ClientConVar[ "model" ] = "models/props_vehicles/carparts_wheel01a.mdl"
TOOL.ClientConVar[ "rx" ] = "90"
TOOL.ClientConVar[ "ry" ] = "0"
TOOL.ClientConVar[ "rz" ] = "90"
TOOL.Information = {
{ name = "left" },
{ name = "right" },
{ name = "use" }
}
cleanup.Register( "wheels" )
local function IsValidWheelModel( model )
for mdl, _ in pairs( list.Get( "WheelModels" ) ) do
if ( mdl:lower() == model:lower() ) then return true end
end
return false
end
-- Places a wheel
function TOOL:LeftClick( trace )
if ( trace.Entity and trace.Entity:IsPlayer() ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER and !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
if ( CLIENT ) then return true end
if ( !self:GetWeapon():CheckLimit( "wheels" ) ) then return false end
-- Check the model's validity
local model = self:GetClientInfo( "model" )
if ( !util.IsValidModel( model ) or !util.IsValidProp( model ) or !IsValidWheelModel( model ) ) then return false end
-- Get client's CVars
local torque = self:GetClientNumber( "torque" )
local friction = self:GetClientNumber( "friction" )
local nocollide = self:GetClientNumber( "nocollide" )
local limit = self:GetClientNumber( "forcelimit" )
local toggle = self:GetClientNumber( "toggle" ) != 0
local fwd = self:GetClientNumber( "fwd" )
local bck = self:GetClientNumber( "bck" )
local ply = self:GetOwner()
-- Make sure we have our wheel angle
self.wheelAngle = Angle( math.NormalizeAngle( self:GetClientNumber( "rx" ) ), math.NormalizeAngle( self:GetClientNumber( "ry" ) ), math.NormalizeAngle( self:GetClientNumber( "rz" ) ) )
-- Create the wheel
local wheelEnt = MakeWheel( ply, trace.HitPos, trace.HitNormal:Angle() + self.wheelAngle, model, fwd, bck, nil, nil, toggle, torque )
if ( !IsValid( wheelEnt ) ) then return false end
-- Position
local CurPos = wheelEnt:GetPos()
local NearestPoint = wheelEnt:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local wheelOffset = CurPos - NearestPoint
wheelEnt:SetPos( trace.HitPos + wheelOffset )
-- Wake up the physics object so that the entity updates
if ( IsValid( wheelEnt:GetPhysicsObject() ) ) then wheelEnt:GetPhysicsObject():Wake() end
-- Set the hinge Axis perpendicular to the trace hit surface
local targetPhys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
local LPos1 = wheelEnt:GetPhysicsObject():WorldToLocal( wheelEnt:GetPos() + trace.HitNormal )
local LPos2 = targetPhys:WorldToLocal( trace.HitPos )
local constr, axis = constraint.Motor( wheelEnt, trace.Entity, 0, trace.PhysicsBone, LPos1, LPos2, friction, torque, 0, nocollide, toggle, ply, limit )
undo.Create( "gmod_wheel" )
if ( IsValid( constr ) ) then
undo.AddEntity( constr )
ply:AddCleanup( "wheels", constr )
end
if ( IsValid( axis ) ) then
undo.AddEntity( axis )
ply:AddCleanup( "wheels", axis )
end
undo.AddEntity( wheelEnt )
undo.SetPlayer( ply )
undo.Finish()
wheelEnt:SetMotor( constr )
wheelEnt:SetDirection( constr.direction )
wheelEnt:SetAxis( trace.HitNormal )
wheelEnt:DoDirectionEffect()
return true
end
-- Apply new values to the wheel
function TOOL:RightClick( trace )
if ( trace.Entity and trace.Entity:GetClass() != "gmod_wheel" ) then return false end
if ( CLIENT ) then return true end
local wheelEnt = trace.Entity
-- Only change your own wheels..
if ( IsValid( wheelEnt:GetPlayer() ) and wheelEnt:GetPlayer() != self:GetOwner() ) then
return false
end
-- Get client's CVars
local torque = self:GetClientNumber( "torque" )
local toggle = self:GetClientNumber( "toggle" ) != 0
local fwd = self:GetClientNumber( "fwd" )
local bck = self:GetClientNumber( "bck" )
-- TODO: Friction
-- TODO: Force Limit
wheelEnt.BaseTorque = torque
wheelEnt:SetTorque( torque )
wheelEnt:SetToggle( toggle )
-- Make sure the table exists!
wheelEnt.KeyBinds = wheelEnt.KeyBinds or {}
wheelEnt.key_f = fwd
wheelEnt.key_r = bck
-- Remove old binds
numpad.Remove( wheelEnt.KeyBinds[ 1 ] )
numpad.Remove( wheelEnt.KeyBinds[ 2 ] )
numpad.Remove( wheelEnt.KeyBinds[ 3 ] )
numpad.Remove( wheelEnt.KeyBinds[ 4 ] )
-- Add new binds
wheelEnt.KeyBinds[ 1 ] = numpad.OnDown( self:GetOwner(), fwd, "WheelForward", wheelEnt, true )
wheelEnt.KeyBinds[ 2 ] = numpad.OnUp( self:GetOwner(), fwd, "WheelForward", wheelEnt, false )
wheelEnt.KeyBinds[ 3 ] = numpad.OnDown( self:GetOwner(), bck, "WheelReverse", wheelEnt, true )
wheelEnt.KeyBinds[ 4 ] = numpad.OnUp( self:GetOwner(), bck, "WheelReverse", wheelEnt, false )
return true
end
if ( SERVER ) then
-- For duplicator, creates the wheel.
function MakeWheel( ply, pos, ang, model, key_f, key_r, axis, direction, toggle, baseTorque, Data )
if ( IsValid( ply ) and !ply:CheckLimit( "wheels" ) ) then return NULL end
if ( !IsValidWheelModel( model ) ) then return NULL end
local wheel = ents.Create( "gmod_wheel" )
if ( !IsValid( wheel ) ) then return NULL end
duplicator.DoGeneric( wheel, Data )
wheel:SetModel( model ) -- Backwards compatible for addons directly calling this function
wheel:SetPos( pos )
wheel:SetAngles( ang )
wheel:Spawn()
DoPropSpawnedEffect( wheel )
wheel:SetPlayer( ply )
duplicator.DoGenericPhysics( wheel, ply, Data )
wheel.key_f = key_f
wheel.key_r = key_r
if ( axis ) then
wheel.Axis = axis
end
wheel:SetDirection( direction or 1 )
wheel:SetToggle( toggle or false )
wheel:SetBaseTorque( baseTorque )
wheel:UpdateOverlayText()
wheel.KeyBinds = {}
-- Bind to keypad
wheel.KeyBinds[ 1 ] = numpad.OnDown( ply, key_f, "WheelForward", wheel, true )
wheel.KeyBinds[ 2 ] = numpad.OnUp( ply, key_f, "WheelForward", wheel, false )
wheel.KeyBinds[ 3 ] = numpad.OnDown( ply, key_r, "WheelReverse", wheel, true )
wheel.KeyBinds[ 4 ] = numpad.OnUp( ply, key_r, "WheelReverse", wheel, false )
if ( IsValid( ply ) ) then
ply:AddCount( "wheels", wheel )
ply:AddCleanup( "wheels", wheel )
end
return wheel
end
duplicator.RegisterEntityClass( "gmod_wheel", MakeWheel, "Pos", "Ang", "Model", "key_f", "key_r", "Axis", "Direction", "Toggle", "BaseTorque", "Data" )
end
function TOOL:UpdateGhostWheel( ent, ply )
if ( !IsValid( ent ) ) then return end
local trace = ply:GetEyeTrace()
if ( !trace.Hit or IsValid( trace.Entity ) and ( trace.Entity:IsPlayer() /*|| trace.Entity:GetClass() == "gmod_wheel"*/ ) ) then
ent:SetNoDraw( true )
return
end
local Ang = trace.HitNormal:Angle() + self.wheelAngle
ent:SetAngles( Ang )
local CurPos = ent:GetPos()
local NearestPoint = ent:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local WheelOffset = CurPos - NearestPoint
ent:SetPos( trace.HitPos + WheelOffset )
ent:SetNoDraw( false )
end
-- Maintains the ghost wheel
function TOOL:Think()
local mdl = self:GetClientInfo( "model" )
if ( !IsValidWheelModel( mdl ) ) then self:ReleaseGhostEntity() return end
if ( !IsValid( self.GhostEntity ) or self.GhostEntity:GetModel() != mdl:lower() ) then
self.wheelAngle = Angle( math.NormalizeAngle( self:GetClientNumber( "rx" ) ), math.NormalizeAngle( self:GetClientNumber( "ry" ) ), math.NormalizeAngle( self:GetClientNumber( "rz" ) ) )
self:MakeGhostEntity( mdl, vector_origin, angle_zero )
end
self:UpdateGhostWheel( self.GhostEntity, self:GetOwner() )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.wheel.desc" )
CPanel:ToolPresets( "wheel", ConVarsDefault )
CPanel:KeyBinder( "#tool.wheel.forward", "wheel_fwd", "#tool.wheel.reverse", "wheel_bck" )
CPanel:NumSlider( "#tool.wheel.torque", "wheel_torque", 10, 10000 )
CPanel:NumSlider( "#tool.wheel.forcelimit", "wheel_forcelimit", 0, 50000 )
CPanel:NumSlider( "#tool.wheel.friction", "wheel_friction", 0, 100 )
CPanel:CheckBox( "#tool.wheel.nocollide", "wheel_nocollide" )
CPanel:CheckBox( "#tool.wheel.toggle", "wheel_toggle" )
CPanel:PropSelect( "#tool.wheel.model", "wheel_model", list.Get( "WheelModels" ), 0 )
end
-- Don't copy paste all of those ridiculous angles, just use one variable for all of them
local zero = { wheel_rx = 0, wheel_ry = 0, wheel_rz = 0 }
local one = { wheel_rx = 90, wheel_ry = 0, wheel_rz = 0 }
local two = { wheel_rx = 90, wheel_ry = 0, wheel_rz = 90 }
list.Set( "WheelModels", "models/props_junk/sawblade001a.mdl", one )
list.Set( "WheelModels", "models/props_vehicles/carparts_wheel01a.mdl", two )
list.Set( "WheelModels", "models/props_vehicles/apc_tire001.mdl", zero )
list.Set( "WheelModels", "models/props_vehicles/tire001a_tractor.mdl", zero )
list.Set( "WheelModels", "models/props_vehicles/tire001b_truck.mdl", zero )
list.Set( "WheelModels", "models/props_vehicles/tire001c_car.mdl", zero )
list.Set( "WheelModels", "models/props_wasteland/controlroom_filecabinet002a.mdl", one )
list.Set( "WheelModels", "models/props_borealis/bluebarrel001.mdl", one )
list.Set( "WheelModels", "models/props_c17/oildrum001.mdl", one )
list.Set( "WheelModels", "models/props_c17/playground_carousel01.mdl", one )
list.Set( "WheelModels", "models/props_c17/chair_office01a.mdl", one )
list.Set( "WheelModels", "models/props_c17/TrapPropeller_Blade.mdl", one )
list.Set( "WheelModels", "models/props_wasteland/wheel01.mdl", two )
list.Set( "WheelModels", "models/props_trainstation/trainstation_clock001.mdl", zero )
list.Set( "WheelModels", "models/props_junk/metal_paintcan001a.mdl", one )
list.Set( "WheelModels", "models/props_c17/pulleywheels_large01.mdl", zero )
list.Set( "WheelModels", "models/props_phx/oildrum001_explosive.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/breakable_tire.mdl", one )
list.Set( "WheelModels", "models/props_phx/gibs/tire1_gib.mdl", one )
list.Set( "WheelModels", "models/props_phx/normal_tire.mdl", one )
list.Set( "WheelModels", "models/props_phx/mechanics/medgear.mdl", one )
list.Set( "WheelModels", "models/props_phx/mechanics/biggear.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/bevel9.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/bevel90_24.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/bevel12.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/bevel24.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/bevel36.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/spur9.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/spur12.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/spur24.mdl", one )
list.Set( "WheelModels", "models/props_phx/gears/spur36.mdl", one )
list.Set( "WheelModels", "models/props_phx/smallwheel.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/747wheel.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/trucktire.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/trucktire2.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/metal_wheel1.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/metal_wheel2.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/wooden_wheel1.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/wooden_wheel2.mdl", one )
list.Set( "WheelModels", "models/props_phx/construct/metal_plate_curve360.mdl", one )
list.Set( "WheelModels", "models/props_phx/construct/metal_plate_curve360x2.mdl", one )
list.Set( "WheelModels", "models/props_phx/construct/wood/wood_curve360x1.mdl", one )
list.Set( "WheelModels", "models/props_phx/construct/wood/wood_curve360x2.mdl", one )
list.Set( "WheelModels", "models/props_phx/construct/windows/window_curve360x1.mdl", one )
list.Set( "WheelModels", "models/props_phx/construct/windows/window_curve360x2.mdl", one )
list.Set( "WheelModels", "models/props_phx/trains/wheel_medium.mdl", one )
list.Set( "WheelModels", "models/props_phx/trains/medium_wheel_2.mdl", one )
list.Set( "WheelModels", "models/props_phx/trains/double_wheels.mdl", one )
list.Set( "WheelModels", "models/props_phx/trains/double_wheels2.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/drugster_back.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/drugster_front.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/monster_truck.mdl", one )
list.Set( "WheelModels", "models/props_phx/misc/propeller2x_small.mdl", one )
list.Set( "WheelModels", "models/props_phx/misc/propeller3x_small.mdl", one )
list.Set( "WheelModels", "models/props_phx/misc/paddle_small.mdl", one )
list.Set( "WheelModels", "models/props_phx/misc/paddle_small2.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/magnetic_small.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/magnetic_small_base.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/magnetic_medium.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/magnetic_med_base.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/magnetic_large.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/magnetic_large_base.mdl", one )
list.Set( "WheelModels", "models/props_phx/wheels/moped_tire.mdl", one )
--Tile Model Pack Wheels
list.Set( "WheelModels", "models/hunter/misc/cone1x05.mdl", one )
list.Set( "WheelModels", "models/hunter/tubes/circle2x2.mdl", one )
list.Set( "WheelModels", "models/hunter/tubes/circle4x4.mdl", one )
--Primitive Mechanics
list.Set( "WheelModels", "models/mechanics/wheels/bmw.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/bmwl.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/rim_1.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/tractor.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/wheel_2.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/wheel_2l.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/wheel_extruded_48.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/wheel_race.mdl", one )
list.Set( "WheelModels", "models/mechanics/wheels/wheel_smooth2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x12.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x12_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x12_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x24.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x24_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x24_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x6.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x6_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear12x6_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x12.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x12_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x12_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x24.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x24_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x24_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x6.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x6_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear16x6_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x12.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x12_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x12_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x24.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x24_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x24_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x6.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x6_large.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears/gear24x6_small.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_12t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_18t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_24t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_36t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_48t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_60t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_12t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_18t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_24t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_36t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_48t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_60t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_12t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_18t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_24t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_36t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_48t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/gear_60t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/bevel_12t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/bevel_18t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/bevel_24t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/bevel_36t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/bevel_48t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/bevel_60t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/vert_12t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/vert_18t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/vert_24t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/vert_36t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_20t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_40t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_80t1.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_20t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_40t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_80t2.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_20t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_40t3.mdl", one )
list.Set( "WheelModels", "models/Mechanics/gears2/pinion_80t3.mdl", one )
--XQM Model Pack Wheels
list.Set( "WheelModels", "models/NatesWheel/nateswheel.mdl", zero )
list.Set( "WheelModels", "models/NatesWheel/nateswheelwide.mdl", zero )
list.Set( "WheelModels", "models/XQM/JetEnginePropeller.mdl", zero )
list.Set( "WheelModels", "models/XQM/JetEnginePropellerMedium.mdl", zero )
list.Set( "WheelModels", "models/XQM/JetEnginePropellerBig.mdl", zero )
list.Set( "WheelModels", "models/XQM/JetEnginePropellerHuge.mdl", zero )
list.Set( "WheelModels", "models/XQM/JetEnginePropellerLarge.mdl", zero )
list.Set( "WheelModels", "models/XQM/HelicopterRotor.mdl", zero )
list.Set( "WheelModels", "models/XQM/HelicopterRotorMedium.mdl", zero )
list.Set( "WheelModels", "models/XQM/HelicopterRotorBig.mdl", zero )
list.Set( "WheelModels", "models/XQM/HelicopterRotorHuge.mdl", zero )
list.Set( "WheelModels", "models/XQM/HelicopterRotorLarge.mdl", zero )
list.Set( "WheelModels", "models/XQM/Propeller1.mdl", zero )
list.Set( "WheelModels", "models/XQM/Propeller1Medium.mdl", zero )
list.Set( "WheelModels", "models/XQM/Propeller1Big.mdl", zero )
list.Set( "WheelModels", "models/XQM/Propeller1Huge.mdl", zero )
list.Set( "WheelModels", "models/XQM/Propeller1Large.mdl", zero )
list.Set( "WheelModels", "models/XQM/AirPlaneWheel1.mdl", zero )
list.Set( "WheelModels", "models/XQM/AirPlaneWheel1Medium.mdl", zero )
list.Set( "WheelModels", "models/XQM/AirPlaneWheel1Big.mdl", zero )
list.Set( "WheelModels", "models/XQM/AirPlaneWheel1Huge.mdl", zero )
list.Set( "WheelModels", "models/XQM/AirPlaneWheel1Large.mdl", zero )
--Xeon133's Wheels
list.Set( "WheelModels", "models/xeon133/offroad/Off-road-20.mdl", zero )
list.Set( "WheelModels", "models/xeon133/offroad/Off-road-30.mdl", zero )
list.Set( "WheelModels", "models/xeon133/offroad/Off-road-40.mdl", zero )
list.Set( "WheelModels", "models/xeon133/offroad/Off-road-50.mdl", zero )
list.Set( "WheelModels", "models/xeon133/offroad/Off-road-60.mdl", zero )
list.Set( "WheelModels", "models/xeon133/offroad/Off-road-70.mdl", zero )
list.Set( "WheelModels", "models/xeon133/offroad/Off-road-80.mdl", zero )

View File

@@ -0,0 +1,224 @@
TOOL.Category = "Constraints"
TOOL.Name = "#tool.winch.name"
TOOL.ClientConVar[ "rope_material" ] = "cable/rope"
TOOL.ClientConVar[ "rope_width" ] = "3"
TOOL.ClientConVar[ "fwd_speed" ] = "64"
TOOL.ClientConVar[ "bwd_speed" ] = "64"
TOOL.ClientConVar[ "fwd_group" ] = "44"
TOOL.ClientConVar[ "bwd_group" ] = "41"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"
TOOL.Information = {
{ name = "left", stage = 0 },
{ name = "left_1", stage = 1, op = 1 },
{ name = "right", stage = 0 },
{ name = "reload" }
}
function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local iNum = self:NumObjects()
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( iNum + 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
self:SetOperation( 1 )
if ( iNum > 0 ) then
if ( CLIENT ) then
self:ClearObjects()
return true
end
local ply = self:GetOwner()
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local material = self:GetClientInfo( "rope_material" )
local width = self:GetClientNumber( "rope_width", 3 )
local fwd_bind = self:GetClientNumber( "fwd_group", 44 )
local bwd_bind = self:GetClientNumber( "bwd_group", 41 )
local fwd_speed = self:GetClientNumber( "fwd_speed", 64 )
local bwd_speed = self:GetClientNumber( "bwd_speed", 64 )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
local toggle = false
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local constr, rope, controller = constraint.Winch( ply, Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, fwd_bind, bwd_bind, fwd_speed, bwd_speed, material, toggle, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
undo.Create( "Winch" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
if ( IsValid( controller ) ) then undo.AddEntity( controller ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.winch.name" )
undo.Finish( "#tool.winch.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
if ( IsValid( controller ) ) then ply:AddCleanup( "ropeconstraints", controller ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
else
self:SetStage( iNum + 1 )
end
return true
end
function TOOL:RightClick( trace )
if ( self:GetOperation() == 1 ) then return false end
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local Phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone )
self:SetObject( 1, trace.Entity, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal )
local ply = self:GetOwner()
local tr_new = {}
tr_new.start = trace.HitPos
tr_new.endpos = trace.HitPos + ( trace.HitNormal * 16384 )
tr_new.filter = { ply }
if ( IsValid( trace.Entity ) ) then
table.insert( tr_new.filter, trace.Entity )
end
local tr = util.TraceLine( tr_new )
if ( !tr.Hit ) then
self:ClearObjects()
return false
end
-- Don't try to constrain world to world
if ( trace.HitWorld && tr.HitWorld ) then
self:ClearObjects()
return false
end
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then
self:ClearObjects()
return false
end
if ( IsValid( tr.Entity ) && tr.Entity:IsPlayer() ) then
self:ClearObjects()
return false
end
-- Check to see if the player can create a winch constraint with the entity in the trace
if ( !hook.Run( "CanTool", ply, tr, "winch", self, 2 ) ) then
self:ClearObjects()
return false
end
local Phys2 = tr.Entity:GetPhysicsObjectNum( tr.PhysicsBone )
self:SetObject( 2, tr.Entity, tr.HitPos, Phys2, tr.PhysicsBone, trace.HitNormal )
if ( CLIENT ) then
self:ClearObjects()
return true
end
if ( !ply:CheckLimit( "ropeconstraints" ) ) then
self:ClearObjects()
return false
end
-- Get client's CVars
local material = self:GetClientInfo( "rope_material" )
local width = self:GetClientNumber( "rope_width", 3 )
local fwd_bind = self:GetClientNumber( "fwd_group", 44 )
local bwd_bind = self:GetClientNumber( "bwd_group", 41 )
local fwd_speed = self:GetClientNumber( "fwd_speed", 64 )
local bwd_speed = self:GetClientNumber( "bwd_speed", 64 )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
local toggle = false
-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local constr, rope, controller = constraint.Winch( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, fwd_bind, bwd_bind, fwd_speed, bwd_speed, material, toggle, Color( colorR, colorG, colorB ) )
if ( IsValid( constr ) ) then
undo.Create( "Winch" )
undo.AddEntity( constr )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
if ( IsValid( controller ) ) then undo.AddEntity( controller ) end
undo.SetPlayer( ply )
undo.SetCustomUndoText( "Undone #tool.winch.name" )
undo.Finish( "#tool.winch.name" )
ply:AddCount( "ropeconstraints", constr )
ply:AddCleanup( "ropeconstraints", constr )
if ( IsValid( rope ) ) then ply:AddCleanup( "ropeconstraints", rope ) end
if ( IsValid( controller ) ) then ply:AddCleanup( "ropeconstraints", controller ) end
end
-- Clear the objects so we're ready to go again
self:ClearObjects()
return true
end
function TOOL:Reload( trace )
if ( !IsValid( trace.Entity ) || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
return constraint.RemoveConstraints( trace.Entity, "Winch" )
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:Help( "#tool.winch.help" )
CPanel:ToolPresets( "winch", ConVarsDefault )
CPanel:KeyBinder( "#tool.winch.forward", "winch_fwd_group", "#tool.winch.backward", "winch_bwd_group" )
CPanel:NumSlider( "#tool.winch.fspeed", "winch_fwd_speed", 0, 1000 )
CPanel:ControlHelp( "#tool.winch.fspeed.help" )
CPanel:NumSlider( "#tool.winch.bspeed", "winch_bwd_speed", 0, 1000 )
CPanel:ControlHelp( "#tool.winch.bspeed.help" )
CPanel:NumSlider( "#tool.winch.width", "winch_rope_width", 0, 10 )
CPanel:RopeSelect( "winch_rope_material" )
CPanel:ColorPicker( "#tool.winch.color", "winch_color_r", "winch_color_g", "winch_color_b" )
end

View File

@@ -0,0 +1,169 @@
-- Variables that are used on both client and server
SWEP.Instructions = "Shoot a prop to attach a Manhack.\nRight click to attach a rollermine."
SWEP.Author = "Facepunch"
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.UseHands = true
SWEP.ViewModel = "models/weapons/c_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.PrintName = "#manhack_welder"
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.UseHands = true
local ShootSound = Sound( "Metal.SawbladeStick" )
--[[---------------------------------------------------------
Reload does nothing
-----------------------------------------------------------]]
function SWEP:Reload()
end
--[[---------------------------------------------------------
Think does nothing
-----------------------------------------------------------]]
function SWEP:Think()
end
--[[---------------------------------------------------------
PrimaryAttack
-----------------------------------------------------------]]
function SWEP:PrimaryAttack()
local owner = self:GetOwner()
local tr = util.TraceLine( util.GetPlayerTrace( owner ) )
--if ( tr.HitWorld ) then return end
if ( IsFirstTimePredicted() ) then
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetNormal( tr.HitNormal )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
util.Effect( "Sparks", effectdata )
end
self:EmitSound( ShootSound )
self:ShootEffects()
-- The rest is only done on the server
if ( CLIENT ) then return end
-- Make a manhack
local ent = ents.Create( "npc_manhack" )
if ( !IsValid( ent ) ) then return end
ent:SetPos( tr.HitPos + owner:GetAimVector() * -16 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
local weld = nil
if ( tr.HitWorld ) then
-- freeze it in place
ent:GetPhysicsObject():EnableMotion( false )
else
-- Weld it to the object that we hit
weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 )
end
if ( owner:IsPlayer() ) then
undo.Create( "npc_manhack" )
undo.AddEntity( weld )
undo.AddEntity( ent )
undo.SetPlayer( owner )
undo.Finish()
end
end
--[[---------------------------------------------------------
SecondaryAttack
-----------------------------------------------------------]]
function SWEP:SecondaryAttack()
local owner = self:GetOwner()
local tr = util.TraceLine( util.GetPlayerTrace( owner ) )
--if ( tr.HitWorld ) then return end
self:EmitSound( ShootSound )
self:ShootEffects()
if ( IsFirstTimePredicted() ) then
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetNormal( tr.HitNormal )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
util.Effect( "Sparks", effectdata )
end
-- The rest is only done on the server
if ( CLIENT ) then return end
-- Make a manhack
local ent = ents.Create( "npc_rollermine" )
if ( !IsValid( ent ) ) then return end
ent:SetPos( tr.HitPos + owner:GetAimVector() * -16 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
local weld = nil
if ( !tr.HitWorld ) then
-- Weld it to the object that we hit
weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 )
end
if ( owner:IsPlayer() ) then
undo.Create( "npc_rollermine" )
undo.AddEntity( weld )
undo.AddEntity( ent )
undo.SetPlayer( owner )
undo.Finish()
end
end
--[[---------------------------------------------------------
Name: ShouldDropOnDie
Desc: Should this weapon be dropped when its owner dies?
-----------------------------------------------------------]]
function SWEP:ShouldDropOnDie()
return false
end