mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-13 20:12:39 +03:00
Add files via upload
This commit is contained in:
124
code/Tool.cs
Normal file
124
code/Tool.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using Sandbox;
|
||||
using Sandbox.Tools;
|
||||
|
||||
[Library( "weapon_tool", Title = "Toolgun" )]
|
||||
partial class Tool : Carriable
|
||||
{
|
||||
[ConVar.ClientData( "tool_current" )]
|
||||
public static string UserToolCurrent { get; set; } = "tool_boxgun";
|
||||
|
||||
public override string ViewModelPath => "weapons/rust_pistol/v_rust_pistol.vmdl";
|
||||
|
||||
[Net, Predicted]
|
||||
public BaseTool CurrentTool { get; set; }
|
||||
|
||||
public override void Spawn()
|
||||
{
|
||||
base.Spawn();
|
||||
|
||||
SetModel( "weapons/rust_pistol/rust_pistol.vmdl" );
|
||||
}
|
||||
|
||||
public override void Simulate( Client owner )
|
||||
{
|
||||
UpdateCurrentTool( owner );
|
||||
|
||||
CurrentTool?.Simulate();
|
||||
}
|
||||
|
||||
private void UpdateCurrentTool( Client owner )
|
||||
{
|
||||
var toolName = owner.GetUserString( "tool_current", "tool_boxgun" );
|
||||
if ( toolName == null )
|
||||
return;
|
||||
|
||||
// Already the right tool
|
||||
if ( CurrentTool != null && CurrentTool.Parent == this && CurrentTool.Owner == owner.Pawn && CurrentTool.ClassInfo.IsNamed( toolName ) )
|
||||
return;
|
||||
|
||||
if ( CurrentTool != null )
|
||||
{
|
||||
CurrentTool?.Deactivate();
|
||||
CurrentTool = null;
|
||||
}
|
||||
|
||||
CurrentTool = Library.Create<BaseTool>( toolName, false );
|
||||
|
||||
if ( CurrentTool != null )
|
||||
{
|
||||
CurrentTool.Parent = this;
|
||||
CurrentTool.Owner = owner.Pawn as Player;
|
||||
CurrentTool.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ActiveStart( Entity ent )
|
||||
{
|
||||
base.ActiveStart( ent );
|
||||
|
||||
CurrentTool?.Activate();
|
||||
}
|
||||
|
||||
public override void ActiveEnd( Entity ent, bool dropped )
|
||||
{
|
||||
base.ActiveEnd( ent, dropped );
|
||||
|
||||
CurrentTool?.Deactivate();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
CurrentTool?.Deactivate();
|
||||
CurrentTool = null;
|
||||
}
|
||||
|
||||
public override void OnCarryDrop( Entity dropper )
|
||||
{
|
||||
}
|
||||
|
||||
[Event.Frame]
|
||||
public void OnFrame()
|
||||
{
|
||||
if ( !IsActiveChild() ) return;
|
||||
|
||||
CurrentTool?.OnFrame();
|
||||
}
|
||||
}
|
||||
|
||||
namespace Sandbox.Tools
|
||||
{
|
||||
public partial class BaseTool : NetworkComponent
|
||||
{
|
||||
public Tool Parent { get; set; }
|
||||
public Player Owner { get; set; }
|
||||
|
||||
protected virtual float MaxTraceDistance => 10000.0f;
|
||||
|
||||
public virtual void Activate()
|
||||
{
|
||||
CreatePreviews();
|
||||
}
|
||||
|
||||
public virtual void Deactivate()
|
||||
{
|
||||
DeletePreviews();
|
||||
}
|
||||
|
||||
public virtual void Simulate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void OnFrame()
|
||||
{
|
||||
UpdatePreviews();
|
||||
}
|
||||
|
||||
public virtual void CreateHitEffects( Vector3 pos )
|
||||
{
|
||||
Parent?.CreateHitEffects( pos );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user