mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-19 20:11:46 +03:00
Add files via upload
This commit is contained in:
211
code/weapons/Flashlight.cs
Normal file
211
code/weapons/Flashlight.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
using Sandbox;
|
||||
|
||||
[Library( "weapon_flashlight", Title = "Flashlight", Spawnable = true )]
|
||||
partial class Flashlight : Weapon
|
||||
{
|
||||
public override string ViewModelPath => "weapons/rust_flashlight/v_rust_flashlight.vmdl";
|
||||
public override float SecondaryRate => 2.0f;
|
||||
|
||||
protected virtual Vector3 LightOffset => Vector3.Forward * 10;
|
||||
|
||||
private SpotLightEntity worldLight;
|
||||
private SpotLightEntity viewLight;
|
||||
|
||||
[Net, Local, Predicted]
|
||||
private bool LightEnabled { get; set; } = true;
|
||||
|
||||
TimeSince timeSinceLightToggled;
|
||||
|
||||
public override void Spawn()
|
||||
{
|
||||
base.Spawn();
|
||||
|
||||
SetModel( "weapons/rust_pistol/rust_pistol.vmdl" );
|
||||
|
||||
worldLight = CreateLight();
|
||||
worldLight.SetParent( this, "slide", new Transform( LightOffset ) );
|
||||
worldLight.EnableHideInFirstPerson = true;
|
||||
worldLight.Enabled = false;
|
||||
}
|
||||
|
||||
public override void CreateViewModel()
|
||||
{
|
||||
base.CreateViewModel();
|
||||
|
||||
viewLight = CreateLight();
|
||||
viewLight.SetParent( ViewModelEntity, "light", new Transform( LightOffset ) );
|
||||
viewLight.EnableViewmodelRendering = true;
|
||||
viewLight.Enabled = LightEnabled;
|
||||
}
|
||||
|
||||
private SpotLightEntity CreateLight()
|
||||
{
|
||||
var light = new SpotLightEntity
|
||||
{
|
||||
Enabled = true,
|
||||
DynamicShadows = true,
|
||||
Range = 512,
|
||||
Falloff = 1.0f,
|
||||
LinearAttenuation = 0.0f,
|
||||
QuadraticAttenuation = 1.0f,
|
||||
Brightness = 2,
|
||||
Color = Color.White,
|
||||
InnerConeAngle = 20,
|
||||
OuterConeAngle = 40,
|
||||
FogStength = 1.0f,
|
||||
Owner = Owner,
|
||||
};
|
||||
|
||||
light.UseFog();
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
public override void Simulate( Client cl )
|
||||
{
|
||||
if ( cl == null )
|
||||
return;
|
||||
|
||||
base.Simulate( cl );
|
||||
|
||||
bool toggle = Input.Pressed( InputButton.Flashlight ) || Input.Pressed( InputButton.Attack1 );
|
||||
|
||||
if ( timeSinceLightToggled > 0.1f && toggle )
|
||||
{
|
||||
LightEnabled = !LightEnabled;
|
||||
|
||||
PlaySound( LightEnabled ? "flashlight-on" : "flashlight-off" );
|
||||
|
||||
if ( worldLight.IsValid() )
|
||||
{
|
||||
worldLight.Enabled = LightEnabled;
|
||||
}
|
||||
|
||||
if ( viewLight.IsValid() )
|
||||
{
|
||||
viewLight.Enabled = LightEnabled;
|
||||
}
|
||||
|
||||
timeSinceLightToggled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanReload()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void AttackSecondary()
|
||||
{
|
||||
if ( MeleeAttack() )
|
||||
{
|
||||
OnMeleeHit();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnMeleeMiss();
|
||||
}
|
||||
|
||||
PlaySound( "rust_flashlight.attack" );
|
||||
}
|
||||
|
||||
private bool MeleeAttack()
|
||||
{
|
||||
var forward = Owner.EyeRot.Forward;
|
||||
forward = forward.Normal;
|
||||
|
||||
bool hit = false;
|
||||
|
||||
foreach ( var tr in TraceBullet( Owner.EyePos, Owner.EyePos + forward * 80, 20.0f ) )
|
||||
{
|
||||
if ( !tr.Entity.IsValid() ) continue;
|
||||
|
||||
tr.Surface.DoBulletImpact( tr );
|
||||
|
||||
hit = true;
|
||||
|
||||
if ( !IsServer ) continue;
|
||||
|
||||
using ( Prediction.Off() )
|
||||
{
|
||||
var damageInfo = DamageInfo.FromBullet( tr.EndPos, forward * 100, 25 )
|
||||
.UsingTraceResult( tr )
|
||||
.WithAttacker( Owner )
|
||||
.WithWeapon( this );
|
||||
|
||||
tr.Entity.TakeDamage( damageInfo );
|
||||
}
|
||||
}
|
||||
|
||||
return hit;
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void OnMeleeMiss()
|
||||
{
|
||||
Host.AssertClient();
|
||||
|
||||
if ( IsLocalPawn )
|
||||
{
|
||||
_ = new Sandbox.ScreenShake.Perlin();
|
||||
}
|
||||
|
||||
ViewModelEntity?.SetAnimBool( "attack", true );
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
private void OnMeleeHit()
|
||||
{
|
||||
Host.AssertClient();
|
||||
|
||||
if ( IsLocalPawn )
|
||||
{
|
||||
_ = new Sandbox.ScreenShake.Perlin( 1.0f, 1.0f, 3.0f );
|
||||
}
|
||||
|
||||
ViewModelEntity?.SetAnimBool( "attack_hit", true );
|
||||
}
|
||||
|
||||
private void Activate()
|
||||
{
|
||||
if ( worldLight.IsValid() )
|
||||
{
|
||||
worldLight.Enabled = LightEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
private void Deactivate()
|
||||
{
|
||||
if ( worldLight.IsValid() )
|
||||
{
|
||||
worldLight.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ActiveStart( Entity ent )
|
||||
{
|
||||
base.ActiveStart( ent );
|
||||
|
||||
if ( IsServer )
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ActiveEnd( Entity ent, bool dropped )
|
||||
{
|
||||
base.ActiveEnd( ent, dropped );
|
||||
|
||||
if ( IsServer )
|
||||
{
|
||||
if ( dropped )
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
62
code/weapons/Pistol.cs
Normal file
62
code/weapons/Pistol.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Sandbox;
|
||||
|
||||
[Library( "weapon_pistol", Title = "Pistol", Spawnable = true )]
|
||||
partial class Pistol : Weapon
|
||||
{
|
||||
public override string ViewModelPath => "weapons/rust_pistol/v_rust_pistol.vmdl";
|
||||
|
||||
public override float PrimaryRate => 15.0f;
|
||||
public override float SecondaryRate => 1.0f;
|
||||
|
||||
public TimeSince TimeSinceDischarge { get; set; }
|
||||
|
||||
public override void Spawn()
|
||||
{
|
||||
base.Spawn();
|
||||
|
||||
SetModel( "weapons/rust_pistol/rust_pistol.vmdl" );
|
||||
}
|
||||
|
||||
public override bool CanPrimaryAttack()
|
||||
{
|
||||
return base.CanPrimaryAttack() && Input.Pressed( InputButton.Attack1 );
|
||||
}
|
||||
|
||||
public override void AttackPrimary()
|
||||
{
|
||||
TimeSincePrimaryAttack = 0;
|
||||
TimeSinceSecondaryAttack = 0;
|
||||
|
||||
(Owner as AnimEntity)?.SetAnimBool( "b_attack", true );
|
||||
|
||||
ShootEffects();
|
||||
PlaySound( "rust_pistol.shoot" );
|
||||
ShootBullet( 0.05f, 1.5f, 9.0f, 3.0f );
|
||||
}
|
||||
|
||||
private void Discharge()
|
||||
{
|
||||
if ( TimeSinceDischarge < 0.5f )
|
||||
return;
|
||||
|
||||
TimeSinceDischarge = 0;
|
||||
|
||||
var muzzle = GetAttachment( "muzzle" ) ?? default;
|
||||
var pos = muzzle.Position;
|
||||
var rot = muzzle.Rotation;
|
||||
|
||||
ShootEffects();
|
||||
PlaySound( "rust_pistol.shoot" );
|
||||
ShootBullet( pos, rot.Forward, 0.05f, 1.5f, 9.0f, 3.0f );
|
||||
|
||||
ApplyAbsoluteImpulse( rot.Backward * 200.0f );
|
||||
}
|
||||
|
||||
protected override void OnPhysicsCollision( CollisionEventData eventData )
|
||||
{
|
||||
if ( eventData.Speed > 500.0f )
|
||||
{
|
||||
Discharge();
|
||||
}
|
||||
}
|
||||
}
|
||||
66
code/weapons/SMG.cs
Normal file
66
code/weapons/SMG.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Sandbox;
|
||||
|
||||
[Library( "weapon_smg", Title = "SMG", Spawnable = true )]
|
||||
partial class SMG : Weapon
|
||||
{
|
||||
public override string ViewModelPath => "weapons/rust_smg/v_rust_smg.vmdl";
|
||||
|
||||
public override float PrimaryRate => 15.0f;
|
||||
public override float SecondaryRate => 1.0f;
|
||||
public override float ReloadTime => 5.0f;
|
||||
|
||||
public override void Spawn()
|
||||
{
|
||||
base.Spawn();
|
||||
|
||||
SetModel( "weapons/rust_smg/rust_smg.vmdl" );
|
||||
}
|
||||
|
||||
public override void AttackPrimary()
|
||||
{
|
||||
TimeSincePrimaryAttack = 0;
|
||||
TimeSinceSecondaryAttack = 0;
|
||||
|
||||
(Owner as AnimEntity)?.SetAnimBool( "b_attack", true );
|
||||
|
||||
//
|
||||
// Tell the clients to play the shoot effects
|
||||
//
|
||||
ShootEffects();
|
||||
PlaySound( "rust_smg.shoot" );
|
||||
|
||||
//
|
||||
// Shoot the bullets
|
||||
//
|
||||
ShootBullet( 0.1f, 1.5f, 5.0f, 3.0f );
|
||||
}
|
||||
|
||||
public override void AttackSecondary()
|
||||
{
|
||||
// Grenade lob
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
protected override void ShootEffects()
|
||||
{
|
||||
Host.AssertClient();
|
||||
|
||||
Particles.Create( "particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle" );
|
||||
Particles.Create( "particles/pistol_ejectbrass.vpcf", EffectEntity, "ejection_point" );
|
||||
|
||||
if ( Owner == Local.Pawn )
|
||||
{
|
||||
new Sandbox.ScreenShake.Perlin( 0.5f, 4.0f, 1.0f, 0.5f );
|
||||
}
|
||||
|
||||
ViewModelEntity?.SetAnimBool( "fire", true );
|
||||
CrosshairPanel?.CreateEvent( "fire" );
|
||||
}
|
||||
|
||||
public override void SimulateAnimator( PawnAnimator anim )
|
||||
{
|
||||
anim.SetParam( "holdtype", 2 ); // TODO this is shit
|
||||
anim.SetParam( "aimat_weight", 1.0f );
|
||||
}
|
||||
|
||||
}
|
||||
111
code/weapons/Shotgun.cs
Normal file
111
code/weapons/Shotgun.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using Sandbox;
|
||||
|
||||
[Library( "weapon_shotgun", Title = "Shotgun", Spawnable = true )]
|
||||
partial class Shotgun : Weapon
|
||||
{
|
||||
public override string ViewModelPath => "weapons/rust_pumpshotgun/v_rust_pumpshotgun.vmdl";
|
||||
public override float PrimaryRate => 1;
|
||||
public override float SecondaryRate => 1;
|
||||
public override float ReloadTime => 0.5f;
|
||||
|
||||
public override void Spawn()
|
||||
{
|
||||
base.Spawn();
|
||||
|
||||
SetModel( "weapons/rust_pumpshotgun/rust_pumpshotgun.vmdl" );
|
||||
}
|
||||
|
||||
public override void AttackPrimary()
|
||||
{
|
||||
TimeSincePrimaryAttack = 0;
|
||||
TimeSinceSecondaryAttack = 0;
|
||||
|
||||
(Owner as AnimEntity)?.SetAnimBool( "b_attack", true );
|
||||
|
||||
//
|
||||
// Tell the clients to play the shoot effects
|
||||
//
|
||||
ShootEffects();
|
||||
PlaySound( "rust_pumpshotgun.shoot" );
|
||||
|
||||
//
|
||||
// Shoot the bullets
|
||||
//
|
||||
ShootBullets( 10, 0.1f, 10.0f, 9.0f, 3.0f );
|
||||
}
|
||||
|
||||
public override void AttackSecondary()
|
||||
{
|
||||
TimeSincePrimaryAttack = -0.5f;
|
||||
TimeSinceSecondaryAttack = -0.5f;
|
||||
|
||||
(Owner as AnimEntity)?.SetAnimBool( "b_attack", true );
|
||||
|
||||
//
|
||||
// Tell the clients to play the shoot effects
|
||||
//
|
||||
DoubleShootEffects();
|
||||
PlaySound( "rust_pumpshotgun.shootdouble" );
|
||||
|
||||
//
|
||||
// Shoot the bullets
|
||||
//
|
||||
ShootBullets( 20, 0.4f, 20.0f, 8.0f, 3.0f );
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
protected override void ShootEffects()
|
||||
{
|
||||
Host.AssertClient();
|
||||
|
||||
Particles.Create( "particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle" );
|
||||
Particles.Create( "particles/pistol_ejectbrass.vpcf", EffectEntity, "ejection_point" );
|
||||
|
||||
ViewModelEntity?.SetAnimBool( "fire", true );
|
||||
|
||||
if ( IsLocalPawn )
|
||||
{
|
||||
new Sandbox.ScreenShake.Perlin( 1.0f, 1.5f, 2.0f );
|
||||
}
|
||||
|
||||
CrosshairPanel?.CreateEvent( "fire" );
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
protected virtual void DoubleShootEffects()
|
||||
{
|
||||
Host.AssertClient();
|
||||
|
||||
Particles.Create( "particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle" );
|
||||
|
||||
ViewModelEntity?.SetAnimBool( "fire_double", true );
|
||||
CrosshairPanel?.CreateEvent( "fire" );
|
||||
|
||||
if ( IsLocalPawn )
|
||||
{
|
||||
new Sandbox.ScreenShake.Perlin( 3.0f, 3.0f, 3.0f );
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnReloadFinish()
|
||||
{
|
||||
IsReloading = false;
|
||||
|
||||
TimeSincePrimaryAttack = 0;
|
||||
TimeSinceSecondaryAttack = 0;
|
||||
|
||||
FinishReload();
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
protected virtual void FinishReload()
|
||||
{
|
||||
ViewModelEntity?.SetAnimBool( "reload_finished", true );
|
||||
}
|
||||
|
||||
public override void SimulateAnimator( PawnAnimator anim )
|
||||
{
|
||||
anim.SetParam( "holdtype", 3 ); // TODO this is shit
|
||||
anim.SetParam( "aimat_weight", 1.0f );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user