DeathChaos25

[L4D2] Legs

Sep 8th, 2015
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.13 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #define DEBUG
  4.  
  5. #define PLUGIN_AUTHOR "DeathChaos25"
  6. #define PLUGIN_VERSION "1.00"
  7.  
  8. static const String:MODEL_NICK_LEGS[] = "models/survivors/survivor_gambler_legs.mdl";
  9. static const String:MODEL_ROCHELLE_LEGS[] = "models/survivors/survivor_producer_legs.mdl";
  10. static const String:MODEL_COACH_LEGS[] = "models/survivors/survivor_coach_legs.mdl";
  11. static const String:MODEL_ELLIS_LEGS[] = "models/survivors/survivor_mechanic_legs.mdl";
  12. static const String:MODEL_BILL_LEGS[] = "models/survivors/survivor_namvet_legs.mdl";
  13. static const String:MODEL_ZOEY_LEGS[] = "models/survivors/survivor_teenangst_legs.mdl";
  14. static const String:MODEL_FRANCIS_LEGS[] = "models/survivors/survivor_biker_legs.mdl";
  15. static const String:MODEL_LOUIS_LEGS[] = "models/survivors/survivor_manager_legs.mdl";
  16.  
  17. static PreviousAnimation[MAXPLAYERS + 1] = -1;
  18. static CloneModel[MAXPLAYERS + 1] = -1;
  19. static bool:ThirdPerson[MAXPLAYERS + 1] = false;
  20. new PropOff_nSequence;
  21.  
  22. #include <sourcemod>
  23. #include <sdktools>
  24. #include <sdkhooks>
  25.  
  26. public Plugin myinfo =
  27. {
  28.     name = "[L4D2] Legs",
  29.     author = PLUGIN_AUTHOR,
  30.     description = "",
  31.     version = PLUGIN_VERSION,
  32.     url = ""
  33. };
  34.  
  35. public void OnPluginStart()
  36. {
  37.     PropOff_nSequence = FindSendPropInfo("CTerrorPlayer", "m_nSequence");
  38.     CreateTimer(GetRandomFloat(0.1, 0.3), CheckClients, _, TIMER_REPEAT);
  39.     RegConsoleCmd("sm_view", ViewAngles);
  40.     RegConsoleCmd("sm_ang", ChangeAngles);
  41.     RegConsoleCmd("sm_pos", ChangePosition);
  42. }
  43. public OnMapStart()
  44. {
  45.     CheckModelPreCache(MODEL_NICK_LEGS);
  46.     CheckModelPreCache(MODEL_ROCHELLE_LEGS);
  47.     CheckModelPreCache(MODEL_COACH_LEGS);
  48.     CheckModelPreCache(MODEL_ELLIS_LEGS);
  49.     CheckModelPreCache(MODEL_BILL_LEGS);
  50.     CheckModelPreCache(MODEL_ZOEY_LEGS);
  51.     CheckModelPreCache(MODEL_FRANCIS_LEGS);
  52.     CheckModelPreCache(MODEL_LOUIS_LEGS);
  53. }
  54. stock CheckModelPreCache(const String:Modelfile[])
  55. {
  56.     if (!IsModelPrecached(Modelfile))
  57.     {
  58.         PrecacheModel(Modelfile, true);
  59.         PrintToServer("Precaching Model:%s", Modelfile);
  60.     }
  61. }
  62. public void OnGameFrame()
  63. {
  64.     for (new client = 1; client <= MaxClients; client++)
  65.     {
  66.         if (IsSurvivor(client) && !IsFakeClient(client) && IsPlayerAlive(client))
  67.         {
  68.             new sequence = GetEntData(client, PropOff_nSequence);
  69.             if (CloneModel[client] <= 0 || !IsValidEntity(CloneModel[client]))
  70.             {
  71.                 new clone = CreateEntityByName("prop_dynamic_override");
  72.                 decl String:model[64];
  73.                 GetEntPropString(client, Prop_Data, "m_ModelName", model, sizeof(model));
  74.                 if (StrContains(model, "gambler", false) != -1)
  75.                 {
  76.                     SetEntityModel(clone, MODEL_NICK_LEGS);
  77.                 }
  78.                 else if (StrContains(model, "coach", false) != -1)
  79.                 {
  80.                     SetEntityModel(clone, MODEL_COACH_LEGS);
  81.                 }
  82.                 else if (StrContains(model, "producer", false) != -1)
  83.                 {
  84.                     SetEntityModel(clone, MODEL_ROCHELLE_LEGS);
  85.                 }
  86.                 else if (StrContains(model, "mechanic", false) != -1)
  87.                 {
  88.                     SetEntityModel(clone, MODEL_ELLIS_LEGS);
  89.                 }
  90.                 else if (StrContains(model, "namvet", false) != -1)
  91.                 {
  92.                     SetEntityModel(clone, MODEL_BILL_LEGS);
  93.                 }
  94.                 else if (StrContains(model, "teenangst", false) != -1)
  95.                 {
  96.                     SetEntityModel(clone, MODEL_ZOEY_LEGS);
  97.                 }
  98.                 else if (StrContains(model, "biker", false) != -1)
  99.                 {
  100.                     SetEntityModel(clone, MODEL_FRANCIS_LEGS);
  101.                 }
  102.                 else if (StrContains(model, "manager", false) != -1)
  103.                 {
  104.                     SetEntityModel(clone, MODEL_LOUIS_LEGS);
  105.                 }
  106.                 else
  107.                 {
  108.                     AcceptEntityInput(clone, "Kill");
  109.                     LogError("Player Model %s is not supported!", model);
  110.                 }
  111.                 decl Float:vAngles[3];
  112.                 decl Float:vOrigin[3];
  113.                 GetClientAbsOrigin(client, vOrigin);
  114.                 GetClientAbsAngles(client, vAngles);
  115.                
  116.                 SetEntProp(clone, Prop_Data, "m_CollisionGroup", 2);
  117.                 decl String:sTemp[16];
  118.                 Format(sTemp, sizeof(sTemp), "target%d", client);
  119.                 DispatchKeyValue(client, "targetname", sTemp);
  120.                 SetVariantString(sTemp);
  121.                 AcceptEntityInput(clone, "SetParent", clone, clone, 0);
  122.                
  123.                 SetVariantString("bleedout");
  124.                 AcceptEntityInput(clone, "SetParentAttachment");
  125.                
  126.                 SetEntPropFloat(clone, Prop_Send, "m_flPlaybackRate", GetEntPropFloat(client, Prop_Send, "m_flPlaybackRate"));
  127.                 SetEntData(clone, PropOff_nSequence, sequence);
  128.                
  129.                 CloneModel[client] = clone;
  130.                 //ang -80 0 -90
  131.                 //pos -10 -40 -20
  132.                 new Float:pos[3], Float:ang[3];
  133.                 ang[0] = -80.0;
  134.                 ang[1] = 0.0;
  135.                 ang[2] = -90.0;
  136.                
  137.                 pos[0] = -10.0;
  138.                 pos[1] = -40.0;
  139.                 pos[2] = -20.0;
  140.                 TeleportEntity(CloneModel[client], pos, ang, NULL_VECTOR);
  141.                 SDKHook(clone, SDKHook_SetTransmit, Hook_SetTransmit);
  142.             }
  143.            
  144.             if (!PreviousAnimation[client])
  145.             {
  146.                 PreviousAnimation[client] = sequence;
  147.             }
  148.             else if (PreviousAnimation[client] != sequence && PreviousAnimation[client] > 0)
  149.             {
  150.                 new Float:angs[3];
  151.                 GetEntPropVector(client, Prop_Send, "m_angRotation", angs);
  152.                 SetEntPropFloat(CloneModel[client], Prop_Send, "m_flPlaybackRate", GetEntPropFloat(client, Prop_Send, "m_flPlaybackRate"));
  153.                 SetEntData(CloneModel[client], PropOff_nSequence, sequence);
  154.                 for (new i = 0; i < 92; i += 4)
  155.                 {
  156.                     new prop = FindSendPropInfo("CTerrorPlayer", "m_flPoseParameter");
  157.                     new prop2 = FindSendPropInfo("CDynamicProp", "m_flPoseParameter");
  158.                     new value = GetEntData(client, prop + (i));
  159.                    
  160.                     SetEntData(CloneModel[client], prop2 + (i), value);
  161.                 }
  162.                 SetEntPropFloat(CloneModel[client], Prop_Send, "m_flCycle", GetEntPropFloat(client, Prop_Send, "m_flCycle"));
  163.             }
  164.         }
  165.     }
  166. }
  167.  
  168. stock bool:IsSurvivor(client)
  169. {
  170.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
  171. }
  172.  
  173. SetVector(Float:target[3], Float:x, Float:y, Float:z)
  174. {
  175.     target[0] = x;
  176.     target[1] = y;
  177.     target[2] = z;
  178. }
  179.  
  180. public Action:ViewAngles(client, args)
  181. {
  182.     new Float:angles[3];
  183.     GetEntPropVector(CloneModel[client], Prop_Send, "m_vecAngles", angles);
  184.     PrintToChatAll("%f %f %f", angles[0], angles[1], angles[2]);
  185. }
  186.  
  187. public Action:ChangeAngles(client, args)
  188. {
  189.     new String:buffer[32];
  190.     new Float:x, Float:y, Float:z, Float:ang[3];
  191.    
  192.     GetCmdArg(1, buffer, sizeof(buffer));
  193.     x = StringToFloat(buffer);
  194.    
  195.     GetCmdArg(2, buffer, sizeof(buffer));
  196.     y = StringToFloat(buffer);
  197.    
  198.     GetCmdArg(3, buffer, sizeof(buffer));
  199.     z = StringToFloat(buffer);
  200.    
  201.     SetVector(ang, x, y, z);
  202.    
  203.     if (CloneModel[client] > 0 && IsValidEntS(CloneModel[client], "prop_dynamic_override"))
  204.     {
  205.         TeleportEntity(CloneModel[client], NULL_VECTOR, ang, NULL_VECTOR);
  206.     }
  207. }
  208.  
  209. public Action:ChangePosition(client, args)
  210. {
  211.     new String:buffer[32];
  212.     new Float:x, Float:y, Float:z, Float:ang[3];
  213.    
  214.     GetCmdArg(1, buffer, sizeof(buffer));
  215.     x = StringToFloat(buffer);
  216.    
  217.     GetCmdArg(2, buffer, sizeof(buffer));
  218.     y = StringToFloat(buffer);
  219.    
  220.     GetCmdArg(3, buffer, sizeof(buffer));
  221.     z = StringToFloat(buffer);
  222.    
  223.     SetVector(ang, x, y, z);
  224.    
  225.     if (CloneModel[client] > 0 && IsValidEntS(CloneModel[client], "prop_dynamic_override"))
  226.     {
  227.         TeleportEntity(CloneModel[client], ang, NULL_VECTOR, NULL_VECTOR);
  228.     }
  229. }
  230.  
  231. IsValidEntS(ent, String:classname[64])
  232. {
  233.     if (IsValidEnt(ent))
  234.     {
  235.         decl String:name[64];
  236.         GetEdictClassname(ent, name, 64);
  237.         if (StrEqual(classname, name))
  238.         {
  239.             return true;
  240.         }
  241.     }
  242.     return false;
  243. }
  244.  
  245. IsValidEnt(ent)
  246. {
  247.     if (ent > 0 && IsValidEdict(ent) && IsValidEntity(ent))
  248.     {
  249.         return true;
  250.     }
  251.     return false;
  252. }
  253.  
  254. public Action:Hook_SetTransmit(entity, client)
  255. {
  256.     if(!IsSurvivor(client))
  257.     {
  258.         return Plugin_Handled;
  259.     }
  260.     if (entity != CloneModel[client] || GetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView") > 0.0
  261.     || GetEntProp(client, Prop_Send, "m_isHangingFromLedge") == 1 || IsPlayerHeld(client) || IsIncapacitated(client) || ThirdPerson[client])
  262.     {
  263.         return Plugin_Handled;
  264.     }
  265.     return Plugin_Continue;
  266. }
  267.  
  268. stock bool:IsPlayerHeld(client)
  269. {
  270.     new jockey = GetEntPropEnt(client, Prop_Send, "m_jockeyAttacker");
  271.     new charger = GetEntPropEnt(client, Prop_Send, "m_pummelAttacker");
  272.     new hunter = GetEntPropEnt(client, Prop_Send, "m_pounceAttacker");
  273.     new smoker = GetEntPropEnt(client, Prop_Send, "m_tongueOwner");
  274.     if (jockey > 0 || charger > 0 || hunter > 0 || smoker > 0)
  275.     {
  276.         return true;
  277.     }
  278.     return false;
  279. }
  280. stock bool:IsIncapacitated(client)
  281. {
  282.     if (GetEntProp(client, Prop_Send, "m_isIncapacitated", 1) > 0)
  283.         return true;
  284.     return false;
  285. }
  286.  
  287. public Action:CheckClients(Handle:timer)
  288. {
  289.     for (new iClientIndex = 1; iClientIndex <= MaxClients; iClientIndex++)
  290.     {
  291.         if (IsClientInGame(iClientIndex) && !IsFakeClient(iClientIndex))
  292.         {
  293.             if (GetClientTeam(iClientIndex) == 2 || GetClientTeam(iClientIndex) == 3) // Only query clients on survivor or infected team, ignore spectators.
  294.             {
  295.                 QueryClientConVar(iClientIndex, "c_thirdpersonshoulder", QueryClientConVarCallback);
  296.             }
  297.         }
  298.     }
  299. }
  300.  
  301. public QueryClientConVarCallback(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
  302. {
  303.     if (IsClientInGame(client) && !IsClientInKickQueue(client))
  304.     {
  305.         if (result != ConVarQuery_Okay)
  306.         {
  307.             ThirdPerson[client] = true;
  308.         }
  309.         else if (!StrEqual(cvarValue, "false") && !StrEqual(cvarValue, "0"))
  310.         {
  311.             ThirdPerson[client] = true;
  312.         }
  313.         else ThirdPerson[client] = false;
  314.     }
  315. }
Advertisement
Add Comment
Please, Sign In to add comment