FlacoBey

Untitled

Jan 8th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.94 KB | None | 0 0
  1. /*
  2. 1.0
  3. Fixed bug specing a common infected.
  4. Added Pov Modes
  5. 1.0.1
  6. Added Toggle Cmds
  7.  
  8. 1.0.2
  9. changed to PostThink from OnGameFrame
  10.  
  11. 1.1
  12. added Cookiesaving
  13.  
  14. 1.2
  15. Deprecated
  16.  
  17. 1.3
  18. Reverted to 1.1
  19.  
  20. 1.4
  21. Made a 90% workaround with camera going else where when dying (lost packets could still cause it to bug or very low updaterate)
  22.  
  23. 1.5
  24. Added povgod command perma povmod
  25. */
  26.  
  27. #pragma semicolon 1
  28.  
  29. #include <sourcemod>
  30. #include <sdktools>
  31. #include <sdkhooks>
  32. #include <clientprefs>
  33.  
  34. #define PLUGIN_VERSION "1.5"
  35.  
  36.  
  37. static Handle:hCvar_TpMode = INVALID_HANDLE;
  38. static Handle:hCvar_TpDefault = INVALID_HANDLE;
  39.  
  40. static bool:bClientPov[MAXPLAYERS+1] = {true, ...};
  41. static Handle:hCookie_PovPerf = INVALID_HANDLE;
  42.  
  43. static Handle:hClientDisableView[MAXPLAYERS+1] = {INVALID_HANDLE, ...};
  44.  
  45. static iTpMode = 1;
  46. static bool:bTpModeDefault = true;
  47. static bool:bPovGod[MAXPLAYERS+1] = false;
  48.  
  49. static iCamRef[MAXPLAYERS+1];
  50.  
  51.  
  52. public Plugin:myinfo =
  53. {
  54.     name = "ThirdPerson_To_POV",
  55.     author = "Lux",
  56.     description = "Turns Thirdperson events in to Point of view",
  57.     version = PLUGIN_VERSION,
  58.     url = "https://forums.alliedmods.net/showthread.php?p=2518781#post2518781"
  59. };
  60.  
  61.  
  62. public OnPluginStart()
  63. {
  64.     hCookie_PovPerf = RegClientCookie("tp_to_pov_cookie", "", CookieAccess_Protected);
  65.    
  66.     CreateConVar("thirdperson_to_pov_version", PLUGIN_VERSION, "Thirdperson to point of view version", FCVAR_NOTIFY|FCVAR_SPONLY);
  67.     hCvar_TpMode = CreateConVar("tp_pov_mode", "1", "Thirdperson to point of view mode (0 = disable 1 = Semi Events(Being Pounced but not when getting up) 2 = full)", FCVAR_NOTIFY, true, 0.0, true, 2.0);
  68.     hCvar_TpDefault = CreateConVar("tp_pov_default_mode", "1", "Default mode when people join and have no cookie or no cookie option applied, 1 = on | 0 = off, (no cookie option applied is when a client has never used cmds !povoff or !povon on server)", FCVAR_NOTIFY, true, 0.0, true, 1.0);
  69.    
  70.     RegConsoleCmd("sm_povoff", PovOff, "turns pov off");
  71.     RegConsoleCmd("sm_povon", PovOn, "turns pov on");
  72.     RegConsoleCmd("sm_povgod", PovGod, "Keeps pov on nomatter what for survivor who used pov god for current round (Think you're a GOD well see)");
  73.    
  74.     HookEvent("round_start", eRoundStart);
  75.    
  76.     HookConVarChange(hCvar_TpMode, eConvarChanged);
  77.     HookConVarChange(hCvar_TpDefault, eConvarChanged);
  78.    
  79.     AutoExecConfig(true, "ThirdPerson_To_POV1.5");
  80.     CvarsChanged();
  81. }
  82.  
  83. public eConvarChanged(Handle:hCvar, const String:sOldVal[], const String:sNewVal[])
  84. {
  85.     CvarsChanged();
  86. }
  87.  
  88. CvarsChanged()
  89. {
  90.     iTpMode = GetConVarInt(hCvar_TpMode);
  91.     bTpModeDefault = GetConVarInt(hCvar_TpDefault) > 0;
  92. }
  93.  
  94. public eRoundStart(Handle:hEvent, const String:sEventName[], bool:bDontBroadcast)
  95. {
  96.     for(new i = 1; i <= MaxClients; i++)
  97.     {
  98.         bPovGod[i] = false;
  99.         hClientDisableView[i] = INVALID_HANDLE;
  100.     }
  101. }
  102.  
  103.  
  104. public Hook_OnPostThinkPost(iClient)
  105. {
  106.     if(!AreClientCookiesCached(iClient))//block everything until async stuff is done
  107.         return;
  108.    
  109.    
  110.     if(!IsPlayerAlive(iClient) || GetClientTeam(iClient) != 2 || !bClientPov[iClient] || !bShouldBePov(iClient))
  111.     {
  112.         if(!IsValidEntRef(iCamRef[iClient]))
  113.             return;
  114.        
  115.         if(hClientDisableView[iClient] != INVALID_HANDLE)
  116.             return;
  117.            
  118.         hClientDisableView[iClient] = CreateTimer(1.0, DisableView, GetClientUserId(iClient));
  119.        
  120.         DisableCam(iClient);
  121.         return;
  122.     }
  123.     else
  124.     {
  125.         if(!IsValidEntRef(iCamRef[iClient]))
  126.             if(!CreateCamera(iClient))
  127.                 return;
  128.        
  129.         static iModelIndex[MAXPLAYERS+1] = {0, ...};       
  130.         if(iModelIndex[iClient] != GetEntProp(iClient, Prop_Data, "m_nModelIndex", 2))
  131.         {
  132.             iModelIndex[iClient] = GetEntProp(iClient, Prop_Data, "m_nModelIndex", 2);
  133.             SetVariantString("eyes");
  134.             AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "SetParentAttachment");
  135.         }
  136.        
  137.         EnableCam(iClient);
  138.     }
  139. }
  140.  
  141. public Action:DisableView(Handle:hTimer, any:iUserID)
  142. {
  143.     static iClient;
  144.     iClient = GetClientOfUserId(iUserID);
  145.    
  146.     if(iClient < 1 || iClient > MaxClients || !IsClientInGame(iClient) || !IsValidEntRef(iCamRef[iClient]) || bShouldBePov(iClient))
  147.     {
  148.         hClientDisableView[iClient] = INVALID_HANDLE;
  149.         return Plugin_Stop;
  150.     }
  151.    
  152.     AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "kill");
  153.     hClientDisableView[iClient] = INVALID_HANDLE;
  154.     return Plugin_Stop;
  155. }
  156.  
  157. bool:CreateCamera(iClient)
  158. {
  159.     static iEntity;
  160.     iEntity = CreateEntityByName("point_viewcontrol_survivor");
  161.     if(iEntity < 1)
  162.         return false;
  163.    
  164.     DispatchSpawn(iEntity);
  165.    
  166.     ActivateEntity(iEntity);
  167.      
  168.     SetVariantString("!activator");
  169.     AcceptEntityInput(iEntity, "SetParent", iClient);
  170.     SetVariantString("eyes");
  171.     AcceptEntityInput(iEntity, "SetParentAttachment");
  172.    
  173.     TeleportEntity(iEntity, Float:{-4.2, 0.0, 0.0}, NULL_VECTOR, NULL_VECTOR);
  174.    
  175.     iCamRef[iClient] = EntIndexToEntRef(iEntity);
  176.    
  177.     return true;
  178. }
  179.  
  180. static DisableCam(iClient)
  181. {
  182.     return AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "Disable", iClient);
  183. }
  184.  
  185. static EnableCam(iClient)
  186. {
  187.     return AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "Enable", iClient);
  188. }
  189.  
  190. static bool:bShouldBePov(iClient)
  191. {
  192.     if(iTpMode != 0 && bPovGod[iClient])
  193.         return true;
  194.    
  195.     switch(iTpMode)
  196.     {
  197.         case 2:
  198.             return bShouldBePov2(iClient);
  199.         case 1:
  200.             return bShouldBePov1(iClient);
  201.     }
  202.     return false;
  203. }
  204.  
  205.  
  206. static bool:bShouldBePov2(iClient)
  207. {
  208.     if(GetEntPropEnt(iClient, Prop_Send, "m_pummelAttacker") > 0)
  209.         return true;
  210.     if(GetEntPropEnt(iClient, Prop_Send, "m_carryAttacker") > 0)
  211.         return true;
  212.     if(GetEntPropEnt(iClient, Prop_Send, "m_pounceAttacker") > 0)
  213.         return true;
  214.     if(GetEntPropEnt(iClient, Prop_Send, "m_jockeyAttacker") > 0)
  215.         return true;
  216.     if(GetEntProp(iClient, Prop_Send, "m_isHangingFromLedge") > 0)
  217.         return true;
  218.     if(GetEntPropEnt(iClient, Prop_Send, "m_reviveTarget") > 0)
  219.         return true;  
  220.     if(GetEntPropFloat(iClient, Prop_Send, "m_staggerTimer", 1) > -1.0)
  221.         return true;
  222.     switch(GetEntProp(iClient, Prop_Send, "m_iCurrentUseAction"))
  223.     {
  224.         case 1:
  225.         {
  226.             static iTarget;
  227.             iTarget = GetEntPropEnt(iClient, Prop_Send, "m_useActionTarget");
  228.            
  229.             if(iTarget == GetEntPropEnt(iClient, Prop_Send, "m_useActionOwner"))
  230.                 return true;
  231.             else if(iTarget != iClient)
  232.                 return true;
  233.         }
  234.         case 4, 5, 6, 7, 8, 9, 10:
  235.             return true;
  236.     }
  237.    
  238.     static String:sModel[31];
  239.     GetEntPropString(iClient, Prop_Data, "m_ModelName", sModel, sizeof(sModel));
  240.    
  241.     switch(sModel[29])
  242.     {
  243.         case 'b'://nick
  244.         {
  245.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  246.             {
  247.                 case 626, 625, 624, 623, 622, 621, 661, 662, 664, 665, 666, 667, 668, 670, 671, 672, 673, 674, 620, 680, 616:
  248.                     return true;
  249.             }
  250.         }
  251.         case 'd'://rochelle
  252.         {
  253.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  254.             {
  255.                 case 674, 678, 679, 630, 631, 632, 633, 634, 668, 677, 681, 680, 676, 675, 673, 672, 671, 670, 687, 629, 625, 616:
  256.                     return true;
  257.             }
  258.         }
  259.         case 'c'://coach
  260.         {
  261.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  262.             {
  263.                 case 656, 622, 623, 624, 625, 626, 663, 662, 661, 660, 659, 658, 657, 654, 653, 652, 651, 621, 620, 669, 615:
  264.                     return true;
  265.             }
  266.         }
  267.         case 'h'://ellis
  268.         {
  269.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  270.             {
  271.                 case 625, 675, 626, 627, 628, 629, 630, 631, 678, 677, 676, 575, 674, 673, 672, 671, 670, 669, 668, 667, 666, 665, 684, 621:
  272.                     return true;
  273.             }
  274.         }
  275.         case 'v'://bill
  276.         {
  277.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  278.             {
  279.                 case 528, 759, 763, 764, 529, 530, 531, 532, 533, 534, 753, 676, 675, 761, 758, 757, 756, 755, 754, 527, 772, 762, 522:
  280.                     return true;
  281.             }
  282.         }
  283.         case 'n'://zoey
  284.         {
  285.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  286.             {
  287.                 case 537, 819, 823, 824, 538, 539, 540, 541, 542, 543, 813, 828, 825, 822, 821, 820, 818, 817, 816, 815, 814, 536, 809, 572:
  288.                     return true;
  289.             }
  290.         }
  291.         case 'e'://francis
  292.         {
  293.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  294.             {
  295.                 case 532, 533, 534, 535, 536, 537, 769, 768, 767, 766, 765, 764, 763, 762, 761, 760, 759, 758, 757, 756, 531, 530, 775, 525:
  296.                     return true;
  297.             }
  298.         }
  299.         case 'a'://louis
  300.         {
  301.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  302.             {
  303.                 case 529, 530, 531, 532, 533, 534, 766, 765, 764, 763, 762, 761, 760, 759, 758, 757, 756, 755, 754, 753, 527, 772, 528, 522:
  304.                     return true;
  305.             }
  306.         }
  307.         case 'w'://adawong
  308.         {
  309.             switch(GetEntProp(iClient, Prop_Send, "m_nSequence"))
  310.             {
  311.             case 674, 678, 679, 630, 631, 632, 633, 634, 668, 677, 681, 680, 676, 675, 673, 672, 671, 670, 687, 629, 625:
  312.                     return true;
  313.             }
  314.         }
  315.     }
  316.    
  317.     return false;
  318. }
  319.  
  320. static bool:bShouldBePov1(iClient)
  321. {
  322.     if(GetEntPropEnt(iClient, Prop_Send, "m_pummelAttacker") > 0)
  323.         return true;
  324.     if(GetEntPropEnt(iClient, Prop_Send, "m_carryAttacker") > 0)
  325.         return true;
  326.     if(GetEntPropEnt(iClient, Prop_Send, "m_pounceAttacker") > 0)
  327.         return true;
  328.     if(GetEntPropEnt(iClient, Prop_Send, "m_jockeyAttacker") > 0)
  329.         return true;
  330.     if(GetEntProp(iClient, Prop_Send, "m_isHangingFromTongue") > 0)
  331.         return true;
  332.     if(GetEntProp(iClient, Prop_Send, "m_reachedTongueOwner") > 0)
  333.         return true;
  334.     if(GetEntProp(iClient, Prop_Send, "m_iCurrentUseAction") == 1)
  335.     {
  336.         static iTarget;
  337.         iTarget = GetEntPropEnt(iClient, Prop_Send, "m_useActionTarget");
  338.        
  339.         if(iTarget == GetEntPropEnt(iClient, Prop_Send, "m_useActionOwner"))
  340.             return true;
  341.         else if(iTarget != iClient)
  342.             return true;
  343.     }
  344.    
  345.     return false;
  346. }
  347.  
  348. static bool:IsValidEntRef(iEntRef)
  349. {
  350.     return (iEntRef != 0 && EntRefToEntIndex(iEntRef) != INVALID_ENT_REFERENCE);
  351. }
  352.  
  353.  
  354. public Action:PovOff(iClient, iArgs)
  355. {
  356.     if(iClient < 1 || !IsClientInGame(iClient) || IsFakeClient(iClient))
  357.         return Plugin_Continue;
  358.    
  359.     if(AreClientCookiesCached(iClient))
  360.         SetClientCookie(iClient, hCookie_PovPerf, "0");
  361.    
  362.     bClientPov[iClient] = false;
  363.     return Plugin_Continue;
  364. }
  365. public Action:PovOn(iClient, iArgs)
  366. {
  367.     if(iClient < 1 || !IsClientInGame(iClient) || IsFakeClient(iClient))
  368.         return Plugin_Continue;
  369.    
  370.     if(AreClientCookiesCached(iClient))
  371.         SetClientCookie(iClient, hCookie_PovPerf, "1");
  372.    
  373.     bClientPov[iClient] = true;
  374.     return Plugin_Continue;
  375. }
  376.  
  377. public Action:PovGod(iClient, iArgs)
  378. {
  379.     if(iClient < 1 || !IsClientInGame(iClient) || IsFakeClient(iClient))
  380.         return Plugin_Continue;
  381.    
  382.     if(bPovGod[iClient])
  383.         bPovGod[iClient] = false;
  384.     else
  385.         bPovGod[iClient] = true;
  386.    
  387.     return Plugin_Continue;
  388. }
  389.  
  390. public OnClientCookiesCached(iClient)
  391. {
  392.     if(iClient < 1 || !IsClientConnected(iClient))
  393.         return;
  394.    
  395.     static String:sCookie[3];
  396.     GetClientCookie(iClient, hCookie_PovPerf, sCookie, sizeof(sCookie));
  397.     if(sCookie[0] == '\0' || StrEqual(sCookie, "0", false))
  398.     {
  399.         if(bTpModeDefault && sCookie[0] == '\0')
  400.             bClientPov[iClient] = true;
  401.         else
  402.             bClientPov[iClient] = false;
  403.     }
  404.     else
  405.     {
  406.         bClientPov[iClient] = true;
  407.     }
  408. }
  409.  
  410. public OnClientPutInServer(iClient)
  411. {
  412.     if(IsFakeClient(iClient))
  413.         return;
  414.        
  415.     SDKHook(iClient, SDKHook_PostThinkPost, Hook_OnPostThinkPost);
  416. }
  417.  
  418. public OnClientDisconnect(iClient)
  419. {  
  420.     bPovGod[iClient] = false;
  421.     hClientDisableView[iClient] = INVALID_HANDLE;
  422. }
Advertisement
Add Comment
Please, Sign In to add comment