diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2023-07-27 22:11:31 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2023-07-27 22:11:31 +0100 |
| commit | 71db52c5443a7bf82d9a23a770994a42b043be04 (patch) | |
| tree | f75f2605bb1bdc53842cd85c90d105dcc77e1c10 /code/entity | |
Initial commit
Diffstat (limited to 'code/entity')
| -rw-r--r-- | code/entity/DroppedWeapon.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/code/entity/DroppedWeapon.cs b/code/entity/DroppedWeapon.cs new file mode 100644 index 0000000..f0cad67 --- /dev/null +++ b/code/entity/DroppedWeapon.cs @@ -0,0 +1,39 @@ +using MurderGame;
+using Sandbox;
+using System;
+
+public partial class DroppedWeapon : AnimatedEntity
+{
+ public int Ammo { get; set; }
+ public Type WeaponType { get; set; }
+
+ public DroppedWeapon(Weapon weapon) : this()
+ {
+ Ammo = weapon.Ammo;
+ WeaponType = weapon.GetType();
+ }
+
+ public DroppedWeapon()
+ {
+ Tags.Add("droppedweapon");
+ PhysicsEnabled = true;
+ UsePhysicsCollision = true;
+ EnableSelfCollisions = true;
+ EnableSolidCollisions = true;
+ }
+
+ public override void StartTouch( Entity other )
+ {
+ if ( !Game.IsServer ) return;
+ if ( !other.Tags.Has( "livingplayer" ) ) return;
+
+ MurderGame.Player player = (MurderGame.Player)other;
+
+ if ( player.Inventory == null || player.Inventory.PrimaryWeapon != null || !player.Inventory.AllowPickup) return;
+
+ Weapon instance = TypeLibrary.Create<Weapon>( WeaponType );
+ instance.Ammo = Ammo;
+ player.Inventory.SetPrimaryWeapon( instance );
+ Delete();
+ }
+}
|
