mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-27 16:16:14 +03:00
Add files via upload
This commit is contained in:
96
code/tools/Weld.cs
Normal file
96
code/tools/Weld.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
namespace Sandbox.Tools
|
||||
{
|
||||
[Library( "tool_weld", Title = "Weld", Description = "Weld stuff together", Group = "construction" )]
|
||||
public partial class WeldTool : BaseTool
|
||||
{
|
||||
private Prop target;
|
||||
|
||||
public override void Simulate()
|
||||
{
|
||||
if ( !Host.IsServer )
|
||||
return;
|
||||
|
||||
using ( Prediction.Off() )
|
||||
{
|
||||
var startPos = Owner.EyePos;
|
||||
var dir = Owner.EyeRot.Forward;
|
||||
|
||||
var tr = Trace.Ray( startPos, startPos + dir * MaxTraceDistance )
|
||||
.Ignore( Owner )
|
||||
.Run();
|
||||
|
||||
if ( !tr.Hit || !tr.Body.IsValid() || !tr.Entity.IsValid() || tr.Entity.IsWorld )
|
||||
return;
|
||||
|
||||
if ( tr.Entity.PhysicsGroup == null || tr.Entity.PhysicsGroup.BodyCount > 1 )
|
||||
return;
|
||||
|
||||
if ( tr.Entity is not Prop prop )
|
||||
return;
|
||||
|
||||
if ( Input.Pressed( InputButton.Attack1 ) )
|
||||
{
|
||||
if ( prop.Root is not Prop rootProp )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( target == rootProp )
|
||||
return;
|
||||
|
||||
if ( !target.IsValid() )
|
||||
{
|
||||
target = rootProp;
|
||||
}
|
||||
else
|
||||
{
|
||||
target.Weld( rootProp );
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
else if ( Input.Pressed( InputButton.Attack2 ) )
|
||||
{
|
||||
prop.Unweld( true );
|
||||
|
||||
Reset();
|
||||
}
|
||||
else if ( Input.Pressed( InputButton.Reload ) )
|
||||
{
|
||||
if ( prop.Root is not Prop rootProp )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rootProp.Unweld();
|
||||
|
||||
Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CreateHitEffects( tr.EndPos );
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
base.Activate();
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
base.Deactivate();
|
||||
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user