custom_weaponry
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| custom_weaponry [2023/06/02 23:49] – namespace update antigravities | custom_weaponry [2023/08/21 23:12] (current) – frank_lee_smith | ||
|---|---|---|---|
| Line 38: | Line 38: | ||
| base.ReloadPrimary(); | base.ReloadPrimary(); | ||
| } | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | if you would like to make a scope similar to the one on the m24, you can use this code snippet taken from the m24 | ||
| + | <code csharp> | ||
| + | public override void SecondaryAttack() | ||
| + | { | ||
| + | base.SecondaryAttack(); | ||
| + | if ( Game.IsClient ) | ||
| + | { | ||
| + | if ( !Scoped ) | ||
| + | { | ||
| + | ScopeIn(); | ||
| + | } | ||
| + | else if ( Scoped ) | ||
| + | { | ||
| + | ScopeOut(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | ScopeOverlay ScopeOverlay; | ||
| + | void ScopeIn() | ||
| + | { | ||
| + | Scoped = true; | ||
| + | (Owner as Player).CameraController.SensitivityMultiplier = 25 / Game.Preferences.FieldOfView; | ||
| + | (Owner as Player).CameraController.FOVMultiplier = 25 / Game.Preferences.FieldOfView; | ||
| + | if ( Game.IsClient ) | ||
| + | { | ||
| + | ViewModelEntity.EnableDrawing = false; | ||
| + | ScopeOverlay = new ScopeOverlay(); | ||
| + | HUDRootPanel.Current.AddChild( ScopeOverlay ); | ||
| + | PlaySound( " | ||
| + | } | ||
| + | } | ||
| + | void ScopeOut() | ||
| + | { | ||
| + | Scoped = false; | ||
| + | (Owner as Player).CameraController.SensitivityMultiplier = 1; | ||
| + | (Owner as Player).CameraController.FOVMultiplier = 1; | ||
| + | if ( Game.IsClient ) | ||
| + | { | ||
| + | ViewModelEntity.EnableDrawing = true; | ||
| + | ScopeOverlay? | ||
| + | PlaySound( " | ||
| + | } | ||
| + | } | ||
| + | public override void OnActiveEnd() | ||
| + | { | ||
| + | ScopeOverlay? | ||
| + | if ( Owner is Player player ) | ||
| + | { | ||
| + | player.CameraController.SensitivityMultiplier = 1; | ||
| + | player.CameraController.FOVMultiplier = 1; | ||
| + | } | ||
| + | base.OnActiveEnd(); | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | Smoke Grenade Code | ||
| + | |||
| + | <code csharp> | ||
| + | |||
| + | using Editor; | ||
| + | using Sandbox; | ||
| + | namespace TerrorTown; | ||
| + | |||
| + | [Library( " | ||
| + | [Title( "Smoke Grenade" | ||
| + | [EditorModel( " | ||
| + | public class SmokeGrenade : Throwable, IGrenade, IRandomGrenade | ||
| + | { | ||
| + | public override string ViewModelPath => " | ||
| + | public override string WorldModelPath => " | ||
| + | public override void Throw() | ||
| + | { | ||
| + | if ( Game.IsServer ) | ||
| + | { | ||
| + | var Nade = new SmokeGrenadeThrown(); | ||
| + | Nade.SetModel( WorldModelPath ); | ||
| + | Nade.SetupPhysicsFromModel( PhysicsMotionType.Dynamic ); | ||
| + | Nade.Position = Owner.AimRay.Position + (Owner.AimRay.Forward * 24) + (Vector3.Down * 5); | ||
| + | Nade.PhysicsBody.Velocity = (Owner.AimRay.Forward * 900) + (Owner.AimRay.Forward.EulerAngles.ToRotation().Up * 80); | ||
| + | Nade.PhysicsBody.Velocity += Owner.Velocity * 1f; | ||
| + | Nade.PhysicsBody.AngularVelocity = Vector3.Random * 20; | ||
| + | Nade.TimeOffset = TimeSinceClicked.Relative; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public class SmokeGrenadeThrown : BasePhysics | ||
| + | { | ||
| + | public float TimeOffset; | ||
| + | public override void Spawn() | ||
| + | { | ||
| + | base.Spawn(); | ||
| + | SetModel( " | ||
| + | SetupPhysicsFromModel( PhysicsMotionType.Dynamic ); | ||
| + | TimeSinceSpawned = 0; | ||
| + | } | ||
| + | TimeSince TimeSinceSpawned; | ||
| + | Particles Particle; | ||
| + | [GameEvent.Tick.Server] | ||
| + | void tick() | ||
| + | { | ||
| + | if ( TimeSinceSpawned > (5 - TimeOffset) ) | ||
| + | { | ||
| + | if ( Particle == null ) | ||
| + | { | ||
| + | Particle = Particles.Create( " | ||
| + | ParticleCleanupSystem.RegisterForCleanup( Particle ); | ||
| + | } | ||
| + | } | ||
| + | if ( TimeSinceSpawned > (65 - TimeOffset) ) | ||
| + | { | ||
| + | Particle.Destroy(); | ||
| + | } | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
custom_weaponry.1685749767.txt.gz · Last modified: 2023/06/02 23:49 by antigravities