Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. //This function will replace the ragdolls' BuildBonePositions function
  2.  
  3. local function GSBuildBones( self, numbones, numphysbone ) //Note: the two last argument doesn't seem to work
  4.  
  5.     local ModelType = self:GetModelType() //Retrive the modeltype
  6.    
  7.     local Bonetree = GSBonetrees[ ModelType ] //Make a variable containing our bonetree
  8.    
  9.     local Index = self:EntIndex() //Used for removing
  10.    
  11.     local ShouldRemove = true //If all the bones are gone
  12.    
  13.     for _, bone in pairs( self.GSDecappedBones ) do //Loop through bones
  14.    
  15.         local Searched = {} //Create a tabel containing all the searched bones
  16.                                    
  17.         local ParentBone = bone //Localize parentbone
  18.            
  19.         repeat
  20.                
  21.             table.insert( Searched, ParentBone ) //Insert it into the searched table
  22.             ParentBone = self:GetParentBone( ParentBone ) //Try the current bone                   
  23.                                
  24.         until ( table.HasValue( Searched, ParentBone ) || !table.HasValue( self.GSDecappedBones, ParentBone ) || !ParentBone )
  25.        
  26.         if ( !ParentBone || ParentBone == bone ) then
  27.        
  28.             ParentBone = self:GetBoneBackup()
  29.         end
  30.        
  31.         if ( !ParentBone ) then
  32.        
  33.             /*RunConsoleCommand( "GSRemoveRagdoll", Index )
  34.             return*/
  35.         end
  36.        
  37.         ParentBone = self:TranslatePhysBoneToBone( ParentBone )
  38.        
  39.         if ( ParentBone ) then
  40.        
  41.             local Pos = self:GetBoneMatrix( ParentBone ):GetTranslation()
  42.            
  43.             local RealBone = self:TranslatePhysBoneToBone( bone ) //Translate the physbone
  44.            
  45.             local BoneMatrix = self:GetBoneMatrix( RealBone )
  46.             if ValidEntity(BoneMatrix) then
  47.                 BoneMatrix:Scale( vector_origin ) //vector_origin = Vector( 0, 0, 0 )
  48.                 BoneMatrix:SetTranslation( Pos )
  49.                 self:SetBoneMatrix( RealBone, BoneMatrix )
  50.             end
  51.         end
  52.     end    
  53. end
  54.  
  55.  
  56. //Description: recieves info from the server
  57.  
  58. local function GSInitializeCS( Umsg )
  59.    
  60.     local Ent = Umsg:ReadEntity()
  61.    
  62.     Ent.PhysCount = Umsg:ReadLong()
  63.    
  64.     local OldFunc = Ent.BuildBonePositions
  65.    
  66.     if ( OldFunc ) then //It allready has a BuildBonePositions function :O
  67.    
  68.         //Lets merge it with our own :D
  69.        
  70.         Ent.BuildBonePositions = function( self, NumBones, NumPhysBones )
  71.        
  72.             OldFunc( self, NumBones, NumPhysBones ) //Call the old function
  73.             GSBuildBones( self, NumBones, NumPhysBones ) //Call our function
  74.         end
  75.     else
  76.    
  77.         Ent.BuildBonePositions = GSBuildBones //Give it our function to use
  78.     end
  79.    
  80.     Ent.GSDecappedBones = {}
  81. end
  82.  
  83. usermessage.Hook( "GSInitializeCS", GSInitializeCS ) //Hook it up
  84.  
  85.  
  86. //Description: Recieves bones to decap
  87.  
  88. local function GSRecieveBones( Umsg )
  89.  
  90.     local Ent = Umsg:ReadEntity()
  91.    
  92.     Ent.GSDecappedBones = Ent.GSDecappedBones || {}
  93.    
  94.     local Count = Umsg:ReadLong()
  95.    
  96.     for i = 1, Count do
  97.    
  98.         if ( Ent.GSDecappedBones ) then
  99.    
  100.             table.insert( Ent.GSDecappedBones, Umsg:ReadLong() )
  101.         end
  102.     end
  103. end
  104.  
  105. usermessage.Hook( "GSRecieveBones", GSRecieveBones )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement