Guest User

CSS Hands Customization

a guest
Jan 14th, 2013
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4.  
  5. #pragma semicolon 1
  6.  
  7. #define EF_NODRAW 32
  8.  
  9. new HandsModel;
  10.  
  11. new OldWeapon[MAXPLAYERS + 1];
  12. new bool:isSpawned[MAXPLAYERS+1];
  13. new ClientVM[MAXPLAYERS+1][2];
  14.  
  15. public OnPluginStart()
  16. {
  17.     HookEvent("player_death", Event_PlayerDeath);
  18.     HookEvent("player_spawn", Event_PlayerSpawn);
  19.    
  20.     for (new client = 1; client <= MaxClients; client++)
  21.     {
  22.         if (IsClientInGame(client))
  23.         {
  24.             SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost);
  25.  
  26.             ClientVM[client][0] = GetEntPropEnt(client, Prop_Send, "m_hViewModel");
  27.            
  28.             new PVM = -1;
  29.             while ((PVM = FindEntityByClassname(PVM, "predicted_viewmodel")) != -1)
  30.             {
  31.                 if (GetEntPropEnt(PVM, Prop_Send, "m_hOwner") == client)
  32.                 {
  33.                     if (GetEntProp(PVM, Prop_Send, "m_nViewModelIndex") == 1)
  34.                     {
  35.                         ClientVM[client][1] = PVM;
  36.                         break;
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
  43.  
  44. public OnMapStart()
  45. {
  46.     HandsModel = PrecacheModel("models/weapons/v_hands.mdl");
  47. }
  48.  
  49. public OnClientPutInServer(client)
  50. {
  51.     SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost);
  52. }
  53.  
  54. public OnEntityCreated(entity, const String:classname[])
  55. {
  56.     if (StrEqual(classname, "predicted_viewmodel", false))
  57.     {
  58.         SDKHook(entity, SDKHook_Spawn, OnEntitySpawned);
  59.     }
  60. }
  61.  
  62. public OnEntitySpawned(entity)
  63. {
  64.     new Owner = GetEntPropEnt(entity, Prop_Send, "m_hOwner");
  65.     if ((Owner > 0) && (Owner <= MaxClients))
  66.     {
  67.         if (GetEntProp(entity, Prop_Send, "m_nViewModelIndex") == 0)
  68.         {
  69.             ClientVM[Owner][0] = entity;
  70.         }
  71.         else if (GetEntProp(entity, Prop_Send, "m_nViewModelIndex") == 1)
  72.         {
  73.             ClientVM[Owner][1] = entity;
  74.         }
  75.     }
  76. }
  77.  
  78. public OnPostThinkPost(client)
  79. {    
  80.     if (!IsPlayerAlive(client))
  81.     {
  82.         return;
  83.     }
  84.    
  85.     new WeaponIndex = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  86.    
  87.     if (WeaponIndex == -1)
  88.     {
  89.         OldWeapon[client] = WeaponIndex;
  90.         return;
  91.     }
  92.    
  93.     if (WeaponIndex != OldWeapon[client])
  94.     {
  95.         decl String:ClassName[30];
  96.         GetEdictClassname(WeaponIndex, ClassName, sizeof(ClassName));
  97.         if (StrEqual("weapon_knife", ClassName, false))
  98.         {
  99.             AcceptEntityInput(WeaponIndex, "hideweapon");
  100.  
  101.             new EntEffects = GetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects");
  102.             EntEffects &= ~EF_NODRAW;
  103.             SetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects", EntEffects);
  104.  
  105.             SetEntProp(ClientVM[client][1], Prop_Send, "m_nModelIndex", HandsModel);
  106.             SetEntPropEnt(ClientVM[client][1], Prop_Send, "m_hWeapon", GetEntPropEnt(ClientVM[client][0], Prop_Send, "m_hWeapon"));
  107.            
  108.             SetEntProp(ClientVM[client][1], Prop_Send, "m_nSequence", GetEntProp(ClientVM[client][0], Prop_Send, "m_nSequence"));
  109.             SetEntPropFloat(ClientVM[client][1], Prop_Send, "m_flPlaybackRate", GetEntPropFloat(ClientVM[client][0], Prop_Send, "m_flPlaybackRate"));
  110.         }
  111.         else
  112.         {
  113.             new EntEffects = GetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects");
  114.             EntEffects |= EF_NODRAW;
  115.             SetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects", EntEffects);
  116.         }
  117.     }
  118.     else
  119.     {
  120.         decl String:ClassName[30];
  121.         GetEdictClassname(WeaponIndex, ClassName, sizeof(ClassName));
  122.         if (StrEqual("weapon_knife", ClassName, false))
  123.         {
  124.             SetEntProp(ClientVM[client][1], Prop_Send, "m_nSequence", GetEntProp(ClientVM[client][0], Prop_Send, "m_nSequence"));
  125.             SetEntPropFloat(ClientVM[client][1], Prop_Send, "m_flPlaybackRate", GetEntPropFloat(ClientVM[client][0], Prop_Send, "m_flPlaybackRate"));
  126.         }
  127.     }
  128.  
  129.     if (isSpawned[client])
  130.     {
  131.         isSpawned[client] = false;
  132.         decl String:ClassName[30];
  133.         GetEdictClassname(WeaponIndex, ClassName, sizeof(ClassName));
  134.         if (StrEqual("weapon_knife", ClassName, false))
  135.         {
  136.             AcceptEntityInput(WeaponIndex, "hideweapon");
  137.         }
  138.     }
  139.    
  140.     OldWeapon[client] = WeaponIndex;
  141. }
  142.  
  143. public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  144. {
  145.     new UserId = GetEventInt(event, "userid");
  146.     new client = GetClientOfUserId(UserId);
  147.    
  148.     new EntEffects = GetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects");
  149.     EntEffects |= EF_NODRAW;
  150.     SetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects", EntEffects);
  151. }
  152.  
  153. public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
  154. {
  155.     new UserId = GetEventInt(event, "userid");
  156.     new client = GetClientOfUserId(UserId);
  157.  
  158.     isSpawned[client] = true;
  159. }
RAW Paste Data