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:
85
code/Player.Ragdoll.cs
Normal file
85
code/Player.Ragdoll.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using Sandbox;
|
||||
|
||||
partial class SandboxPlayer
|
||||
{
|
||||
[ClientRpc]
|
||||
private void BecomeRagdollOnClient( Vector3 velocity, DamageFlags damageFlags, Vector3 forcePos, Vector3 force, int bone )
|
||||
{
|
||||
var ent = new ModelEntity();
|
||||
ent.Position = Position;
|
||||
ent.Rotation = Rotation;
|
||||
ent.Scale = Scale;
|
||||
ent.MoveType = MoveType.Physics;
|
||||
ent.UsePhysicsCollision = true;
|
||||
ent.EnableAllCollisions = true;
|
||||
ent.CollisionGroup = CollisionGroup.Debris;
|
||||
ent.SetModel( GetModelName() );
|
||||
ent.CopyBonesFrom( this );
|
||||
ent.CopyBodyGroups( this );
|
||||
ent.CopyMaterialGroup( this );
|
||||
ent.TakeDecalsFrom( this );
|
||||
ent.EnableHitboxes = true;
|
||||
ent.EnableAllCollisions = true;
|
||||
ent.SurroundingBoundsMode = SurroundingBoundsType.Physics;
|
||||
ent.RenderColorAndAlpha = RenderColorAndAlpha;
|
||||
ent.PhysicsGroup.Velocity = velocity;
|
||||
|
||||
if ( Local.Pawn == this )
|
||||
{
|
||||
//ent.EnableDrawing = false; wtf
|
||||
}
|
||||
|
||||
ent.SetInteractsAs( CollisionLayer.Debris );
|
||||
ent.SetInteractsWith( CollisionLayer.WORLD_GEOMETRY );
|
||||
ent.SetInteractsExclude( CollisionLayer.Player | CollisionLayer.Debris );
|
||||
|
||||
foreach ( var child in Children )
|
||||
{
|
||||
if ( child is ModelEntity e )
|
||||
{
|
||||
var model = e.GetModelName();
|
||||
if ( model != null && !model.Contains( "clothes" ) )
|
||||
continue;
|
||||
|
||||
var clothing = new ModelEntity();
|
||||
clothing.SetModel( model );
|
||||
clothing.SetParent( ent, true );
|
||||
clothing.RenderColorAndAlpha = e.RenderColorAndAlpha;
|
||||
|
||||
if ( Local.Pawn == this )
|
||||
{
|
||||
// clothing.EnableDrawing = false; wtf
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( damageFlags.HasFlag( DamageFlags.Bullet ) ||
|
||||
damageFlags.HasFlag( DamageFlags.PhysicsImpact ) )
|
||||
{
|
||||
PhysicsBody body = bone > 0 ? ent.GetBonePhysicsBody( bone ) : null;
|
||||
|
||||
if ( body != null )
|
||||
{
|
||||
body.ApplyImpulseAt( forcePos, force * body.Mass );
|
||||
}
|
||||
else
|
||||
{
|
||||
ent.PhysicsGroup.ApplyImpulse( force );
|
||||
}
|
||||
}
|
||||
|
||||
if ( damageFlags.HasFlag( DamageFlags.Blast ) )
|
||||
{
|
||||
if ( ent.PhysicsGroup != null )
|
||||
{
|
||||
ent.PhysicsGroup.AddVelocity( (Position - (forcePos + Vector3.Down * 100.0f)).Normal * (force.Length * 0.2f) );
|
||||
var angularDir = (Rotation.FromYaw( 90 ) * force.WithZ( 0 ).Normal).Normal;
|
||||
ent.PhysicsGroup.AddAngularVelocity( angularDir * (force.Length * 0.02f) );
|
||||
}
|
||||
}
|
||||
|
||||
Corpse = ent;
|
||||
|
||||
ent.DeleteAsync( 10.0f );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user