Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 10.53 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4.  
  5. #pragma semicolon 1
  6.  
  7. #define EF_NODRAW 32
  8.  
  9. new g_iWorldModel;
  10. new g_iWorldModell;
  11. new g_iWorldModelll;
  12.  
  13. new bool:SpawnCheck[MAXPLAYERS+1];
  14. new ClientVM[MAXPLAYERS+1][2];
  15. new bool:IsCustom[MAXPLAYERS+1];
  16. new Client = GetClientOfUserId(GetEventInt(event, "userid"));
  17.  
  18.  
  19. public OnPluginStart()
  20. {
  21.     HookEvent("player_death", Event_PlayerDeath);
  22.     HookEvent("player_spawn", Event_Player_Spawn);
  23.    
  24.     for (new client = 1; client <= MaxClients; client++)
  25.     {
  26.         if (IsClientInGame(client))
  27.         {
  28.             SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost);
  29.            
  30.             //find both of the clients viewmodels
  31.             ClientVM[client][0] = GetEntPropEnt(client, Prop_Send, "m_hViewModel");
  32.            
  33.             new PVM = -1;
  34.             while ((PVM = FindEntityByClassname(PVM, "predicted_viewmodel")) != -1)
  35.             {
  36.                 if (GetEntPropEnt(PVM, Prop_Send, "m_hOwner") == client)
  37.                 {
  38.                     if (GetEntProp(PVM, Prop_Send, "m_nViewModelIndex") == 1)
  39.                     {
  40.                         ClientVM[client][1] = PVM;
  41.                         break;
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
  48.  
  49. public OnMapStart()
  50. {
  51.  
  52.     AddFileToDownloadsTable("models/weapons/gold/v_knife_t.dx80.vtx");
  53.         AddFileToDownloadsTable("models/weapons/gold/v_knife_t.dx90.vtx");
  54.         AddFileToDownloadsTable("models/weapons/gold/v_knife_t.mdl");
  55.         AddFileToDownloadsTable("models/weapons/gold/v_knife_t.sw.vtx");
  56.         AddFileToDownloadsTable("models/weapons/gold/v_knife_t.vvd");
  57.         AddFileToDownloadsTable("models/weapons/gold/v_knife_t.xbox.vtx");
  58.         AddFileToDownloadsTable("models/weapons/gold/w_knife_t.dx80.vtx");
  59.         AddFileToDownloadsTable("models/weapons/gold/w_knife_t.dx90.vtx");
  60.         AddFileToDownloadsTable("models/weapons/gold/w_knife_t.mdl");
  61.         AddFileToDownloadsTable("models/weapons/gold/w_knife_t.sw.vtx");
  62.         AddFileToDownloadsTable("models/weapons/gold/w_knife_t.vvd");
  63.         AddFileToDownloadsTable("models/weapons/gold/w_knife_t.xbox.vtx");
  64.         AddFileToDownloadsTable("models/weapons/gold/w_knife_t.phy");
  65.         AddFileToDownloadsTable("models/weapons/gold/w_knife_ct.dx80.vtx");
  66.         AddFileToDownloadsTable("models/weapons/gold/w_knife_ct.dx90.vtx");
  67.         AddFileToDownloadsTable("models/weapons/gold/w_knife_ct.mdl");
  68.         AddFileToDownloadsTable("models/weapons/gold/w_knife_ct.sw.vtx");
  69.         AddFileToDownloadsTable("models/weapons/gold/w_knife_ct.vvd");
  70.         AddFileToDownloadsTable("models/weapons/gold/w_knife_ct.xbox.vtx");
  71.         AddFileToDownloadsTable("models/weapons/gold/w_knife_ct.phy");
  72.         AddFileToDownloadsTable("materials/models/weapons/v_models/gold/knife_t/knife_t.vmt");
  73.         AddFileToDownloadsTable("materials/models/weapons/v_models/gold/knife_t/knife_t.vtf");
  74.         AddFileToDownloadsTable("materials/models/weapons/v_models/gold/knife_t/knife_t_ref.vtf");
  75.         AddFileToDownloadsTable("materials/models/weapons/w_models/gold/w_knife_t/w_knife_t.vmt");
  76.         AddFileToDownloadsTable("materials/models/weapons/w_models/gold/w_knife_t/w_knife_t.vtf");
  77.     g_iWorldModell = PrecacheModel("models/weapons/gold/w_knife_ct.mdl", true);
  78.     g_iWorldModel = PrecacheModel("models/weapons/gold/v_knife_t.mdl", true);
  79.     g_iWorldModelll = PrecacheModel("models/weapons/gold/w_knife_t.mdl", true);
  80.    
  81. }
  82.  
  83. public OnClientPutInServer(client)
  84. {
  85.     SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost);
  86.         SDKHook(Client, SDKHook_WeaponSwitch, WeaponHook);
  87.     SDKHook(Client, SDKHook_WeaponEquip, WeaponHook);
  88. }
  89.  
  90. AdminflagsToString(flags,String:output[],maxlen) {
  91.     new String:buf[2], len    //not using 'decl' for the String var because we need buf[1] to be 0
  92.  
  93.     for(buf[0] = 'a'; buf[0] <= 'z' && len < maxlen; buf[0]++) {
  94.         if(flags & ReadFlagString(buf)) {
  95.             output[len++] = buf[0]
  96.         }
  97.     }
  98.  
  99.     if(len == maxlen) {    //make sure we dont overflow the output buffer while writing the null terminator
  100.         len--
  101.     }
  102.  
  103.     output[len] = 0        //null terminate the string
  104.     return len        //return number of bytes written for convenience
  105. }
  106.  
  107. public Action:Event_Player_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
  108. {
  109.     new Client = GetClientOfUserId(GetEventInt(event, "userid"));
  110.    
  111.     new ActiveWeapon = GetEntPropEnt(Client, Prop_Data, "m_hActiveWeapon");
  112.     if(ActiveWeapon != -1)
  113.     {
  114.         CreateTimer(0.1, ChangeModelIndex, Client);
  115.     }
  116.     return Plugin_Continue;
  117. }
  118.  
  119. public Action:WeaponHook(Client, weapon)
  120. {
  121.     new ActiveWeapon = GetEntPropEnt(Client, Prop_Data, "m_hActiveWeapon");
  122.     if(ActiveWeapon != -1)
  123.     {
  124.         CreateTimer(0.1, ChangeModelIndex, Client);
  125.     }
  126.     return Plugin_Continue;
  127. }
  128.        
  129. public Action:ChangeModelIndex(Handle:Timer, any:Client)
  130. {
  131.         decl String:buffer[32];
  132.         new flags = GetUserFlagBits(Client)
  133.         AdminflagsToString(flags,buffer,sizeof(buffer));
  134.         if (!IsFakeClient(Client) && (StrContains(buffer, "z") != -1 || StrContains(buffer, "s") != -1)) {
  135.                 new ActiveWeapon = GetEntPropEnt(Client, Prop_Data, "m_hActiveWeapon");
  136.                
  137.                 decl String:sWeapon[64];
  138.                 GetEdictClassname(ActiveWeapon, sWeapon, sizeof(sWeapon));
  139.                 if(StrEqual(sWeapon, "weapon_knife"))
  140.                 {
  141.                        
  142.                        
  143.                         SetEntProp(ActiveWeapon, Prop_Send, "m_iWorldModelIndex", g_iWorldModell);
  144.                         SetEntProp(ActiveWeapon, Prop_Send, "m_iWorldModelIndex", g_iWorldModelll);
  145.                 }
  146.         }
  147. }
  148.  
  149. public OnEntityCreated(entity, const String:classname[])
  150. {
  151.     if (StrEqual(classname, "predicted_viewmodel", false))
  152.     {
  153.         SDKHook(entity, SDKHook_Spawn, OnEntitySpawned);
  154.     }
  155. }
  156.  
  157. //find both of the clients viewmodels
  158. public OnEntitySpawned(entity)
  159. {
  160.     new Owner = GetEntPropEnt(entity, Prop_Send, "m_hOwner");
  161.     if ((Owner > 0) && (Owner <= MaxClients))
  162.     {
  163.         if (GetEntProp(entity, Prop_Send, "m_nViewModelIndex") == 0)
  164.         {
  165.             ClientVM[Owner][0] = entity;
  166.         }
  167.         else if (GetEntProp(entity, Prop_Send, "m_nViewModelIndex") == 1)
  168.         {
  169.             ClientVM[Owner][1] = entity;
  170.         }
  171.     }
  172. }
  173.  
  174. public OnPostThinkPost(client)
  175. {
  176.     static OldWeapon[MAXPLAYERS + 1];
  177.     static OldSequence[MAXPLAYERS + 1];
  178.     static Float:OldCycle[MAXPLAYERS + 1];
  179.    
  180.     decl String:ClassName[30];
  181.     new WeaponIndex;
  182.    
  183.     //handle spectators
  184.     if (!IsPlayerAlive(client))
  185.     {
  186.         new spec = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
  187.         if (spec != -1)
  188.         {
  189.             WeaponIndex = GetEntPropEnt(spec, Prop_Send, "m_hActiveWeapon");
  190.             GetEdictClassname(WeaponIndex, ClassName, sizeof(ClassName));
  191.                         new flags = GetUserFlagBits(Client)
  192.                 AdminflagsToString(flags,buffer,sizeof(buffer));
  193.                 if (!IsFakeClient(Client) && (StrContains(buffer, "z") != -1 || StrContains(buffer, "s") != -1)) {
  194.             if (StrEqual("weapon_knife", ClassName, false))
  195.             {
  196.                 SetEntProp(ClientVM[client][1], Prop_Send, "m_nModelIndex", g_iWorldModell);
  197.             }
  198.                         }
  199.            
  200.         }
  201.        
  202.         return;
  203.     }
  204.    
  205.     WeaponIndex = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  206.     new Sequence = GetEntProp(ClientVM[client][0], Prop_Send, "m_nSequence");
  207.     new Float:Cycle = GetEntPropFloat(ClientVM[client][0], Prop_Data, "m_flCycle");
  208.    
  209.     if (WeaponIndex <= 0)
  210.     {
  211.         new EntEffects = GetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects");
  212.         EntEffects |= EF_NODRAW;
  213.         SetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects", EntEffects);
  214.        
  215.         IsCustom[client] = false;
  216.            
  217.         OldWeapon[client] = WeaponIndex;
  218.         OldSequence[client] = Sequence;
  219.         OldCycle[client] = Cycle;
  220.        
  221.         return;
  222.     }
  223.    
  224.     //just stuck the weapon switching in here aswell instead of a separate hook
  225.     if (WeaponIndex != OldWeapon[client])
  226.     {
  227.         GetEdictClassname(WeaponIndex, ClassName, sizeof(ClassName));
  228.         if (StrEqual("weapon_ump45", ClassName, false))
  229.         {
  230.            
  231.            
  232.             //set model and copy over props from viewmodel to used viewmodel
  233.             SetEntProp(ClientVM[client][1], Prop_Send, "m_nModelIndex", g_iWorldModell);
  234.             SetEntPropEnt(ClientVM[client][1], Prop_Send, "m_hWeapon", GetEntPropEnt(ClientVM[client][0], Prop_Send, "m_hWeapon"));
  235.            
  236.             SetEntProp(ClientVM[client][1], Prop_Send, "m_nSequence", GetEntProp(ClientVM[client][0], Prop_Send, "m_nSequence"));
  237.             SetEntPropFloat(ClientVM[client][1], Prop_Send, "m_flPlaybackRate", GetEntPropFloat(ClientVM[client][0], Prop_Send, "m_flPlaybackRate"));
  238.            
  239.             IsCustom[client] = true;
  240.         }
  241.        
  242.         else
  243.         {
  244.             //hide unused viewmodel if the current weapon isn't using it
  245.             new EntEffects = GetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects");
  246.             EntEffects |= EF_NODRAW;
  247.             SetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects", EntEffects);
  248.            
  249.             IsCustom[client] = false;
  250.         }
  251.     }
  252.     else
  253.     {
  254.         if (IsCustom[client])
  255.         {
  256.             //copy the animation stuff from the viewmodel to the used one every frame
  257.             SetEntProp(ClientVM[client][1], Prop_Send, "m_nSequence", GetEntProp(ClientVM[client][0], Prop_Send, "m_nSequence"));
  258.             SetEntPropFloat(ClientVM[client][1], Prop_Send, "m_flPlaybackRate", GetEntPropFloat(ClientVM[client][0], Prop_Send, "m_flPlaybackRate"));
  259.            
  260.             if ((Cycle < OldCycle[client]) && (Sequence == OldSequence[client]))
  261.             {
  262.                 SetEntProp(ClientVM[client][1], Prop_Send, "m_nSequence", 0);
  263.             }
  264.         }
  265.     }
  266.     //hide viewmodel a frame after spawning
  267.     if (SpawnCheck[client])
  268.     {
  269.         SpawnCheck[client] = false;
  270.         if (IsCustom[client])
  271.         {
  272.             new EntEffects = GetEntProp(ClientVM[client][0], Prop_Send, "m_fEffects");
  273.             EntEffects |= EF_NODRAW;
  274.             SetEntProp(ClientVM[client][0], Prop_Send, "m_fEffects", EntEffects);
  275.         }
  276.     }
  277.    
  278.     OldWeapon[client] = WeaponIndex;
  279.     OldSequence[client] = Sequence;
  280.     OldCycle[client] = Cycle;
  281. }
  282. //hide viewmodel on death
  283. public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  284. {
  285.     new UserId = GetEventInt(event, "userid");
  286.     new client = GetClientOfUserId(UserId);
  287.    
  288.     new EntEffects = GetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects");
  289.     EntEffects |= EF_NODRAW;
  290.     SetEntProp(ClientVM[client][1], Prop_Send, "m_fEffects", EntEffects);
  291. }