Advertisement
FlacoBey

Untitled

Feb 5th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.01 KB | None | 0 0
  1. #include sdktools
  2. #include sdkhooks
  3. #include colors
  4.  
  5. #define prefix "\x05[Medic]"
  6.  
  7. new bool:IsHealer[MAXPLAYERS+1] = false;
  8. new bool:IsUsing = false;
  9. new bool:hHasLeftArea = false;
  10. new bool:IsHaveMedic = false;
  11. static Handle hHealCount, hMaxHealth, hDurationRing;
  12.  
  13. Handle HealTimer[MAXPLAYERS+1], TimerRepeatRing;
  14.  
  15. int g_HaloSprite;
  16. int g_BeamSprite;
  17. int yourColor[4] = {220, 20, 60, 255};
  18. int yourColor2[4] = {205, 92, 92, 255};
  19.  
  20. public OnPluginStart()
  21. {
  22.     hHealCount = CreateConVar("hCvarHealCount", "5", "Кол-во лечения", FCVAR_NONE, true, 1.0, true, 50000.0);
  23.     hMaxHealth = CreateConVar("hCvarMaxHeal", "75", "Максимальный прохил", FCVAR_NONE);
  24.     hDurationRing = CreateConVar("hCvarDuration", "15.0", "Время жизни кольца", FCVAR_NONE, true, 1.0, true, 25.0)
  25.    
  26.     //hDistance = CreateConVar("hCvarDuration", "600.0", "Дистаннция", FCVAR_NONE)
  27.     //CoolDown = CreateConVar("hCvarCoolDown", "15.0", "Кул даун юзания", FCVAR_NONE)
  28.     RegConsoleCmd("sm_rmedic", hRandomMedic);
  29.     RegConsoleCmd("sm_bm", hBecomeMedic);
  30.     AutoExecConfig(true, "hMedicPlug");
  31. }
  32.  
  33. public OnMapStart()
  34. {
  35.     HookEvent("player_team", hMedicChangeTeam)
  36.     HookEvent("player_death", hDeath)
  37.     HookEvent("player_left_start_area", hLeftStart)
  38.     HookEvent("bullet_impact", hImpact)
  39.    
  40.     g_BeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt", true);
  41.     g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt", true);
  42.    
  43.     for(int i = 1; i <= MaxClients; ++i)
  44.     {
  45.         IsHealer[i] = false;
  46.     }
  47.     IsUsing = false;
  48.     hHasLeftArea = false;
  49. }
  50.  
  51. public Action:hBecomeMedic(client, args)
  52. {
  53.     if(hHasLeftArea)
  54.     {
  55.         if(bIsSurvivor(client))
  56.         {
  57.             if(IsHaveMedic == false)
  58.             {
  59.                 IsHealer[client] = true;
  60.                 IsHaveMedic = true;
  61.                 CPrintToChatAll("%s {red}%N \x05прописал \x04!bm \x05и стал новым медиком", prefix, client);
  62.                 GiveFunction(client, "pistol_magnum");
  63.             }
  64.         }
  65.     }
  66.     else
  67.     {
  68.         CPrintToChat(client, "%s {blue}Раунд ещё не начался.", prefix)
  69.     }
  70. }
  71.  
  72. public hDeath(Handle:event, const String:name[], bool:dontBroadcast)
  73. {
  74.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  75.     if(IsHealer[client])
  76.     {
  77.         CPrintToChatAll("%s \x05Медик \x04погиб в перестрелке(земля ему пухом).", prefix, client);
  78.     }
  79. }
  80.  
  81. public Action:hRandomMedic(client, args)
  82. {
  83.     if(IsHealer[client])
  84.     {
  85.         int SurvivorsCount = 0;
  86.         for(int i = 1; i <= MaxClients; ++i)
  87.         {
  88.             if(bIsSurvivor(i))
  89.             {
  90.                 SurvivorsCount++;
  91.             }
  92.         }
  93.         if (SurvivorsCount > 1)
  94.         {
  95.             new NewHealer = GetRandomClient()
  96.             IsHealer[client] = false;
  97.             IsHealer[NewHealer] = true;
  98.             IsHaveMedic = true;
  99.             CPrintToChatAll("%s {red}%N \x05отдал медика рандомному сурву.", prefix, client);
  100.             CPrintToChatAll("%s {red}%N \x05стал новым медиком", prefix, NewHealer);
  101.             new weap = GetPlayerWeaponSlot(client, 1);
  102.             RemovePlayerItem(client, weap);
  103.             GiveFunction(NewHealer, "pistol_magnum");
  104.             GiveFunction(client, "pistol");
  105.         }
  106.         else
  107.         {
  108.             CPrintToChatAll("%s {red}Нужно, как минимум 2 игрока за выживших.", prefix);
  109.         }
  110.     }
  111.     else
  112.     {
  113.         CPrintToChatAll("%s {red}Вы не медик.", prefix);
  114.     }
  115. }
  116.  
  117. public hLeftStart(Handle:event, const String:name[], bool:dontBroadcast)
  118. {
  119.     if(hHasLeftArea == false)
  120.     {
  121.         new client = GetRandomClient()
  122.         IsHealer[client] = true;
  123.         GiveFunction(client, "pistol_magnum")
  124.         CPrintToChatAll("%s {blue}%N \x05стал медиком", prefix, client);
  125.         hHasLeftArea = true;
  126.         IsHaveMedic = true;
  127.     }
  128. }
  129.  
  130. public hMedicChangeTeam(Handle:event, const String:name[], bool:dontBroadcast)
  131. {
  132.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  133.     if(IsHealer[client])
  134.     {
  135.         CPrintToChatAll("%s \x05Медик %N \x04поменял команду, либо вышел.", prefix, client)
  136.         int SurvivorsCount = 0;
  137.         for(int i = 1; i <= MaxClients; ++i)
  138.         {
  139.             if(bIsSurvivor(i))
  140.             {
  141.                 SurvivorsCount++;
  142.             }
  143.         }
  144.         if(SurvivorsCount > 0)
  145.         {
  146.             new healer = GetRandomClient()
  147.             GiveFunction(healer, "pistol_magnum");
  148.             IsHealer[healer] = true;
  149.             IsHealer[client] = false;
  150.             CPrintToChatAll("%s {red}%N \x05стал новым медиком", prefix, healer);
  151.             GiveFunction(healer, "pistol_magnum");
  152.         }
  153.         else
  154.         {
  155.             for(int i = 1; i <= MaxClients; ++i)
  156.             {
  157.                 IsHealer[i] = false;
  158.             }
  159.             IsHaveMedic = false;
  160.             CPrintToChatAll("%s {red}В команде выживших, только боты!", prefix);
  161.             CPrintToChatAll("%s {blue}Зайдите за команду выживших и пропишите !bm, чтобы стать медиком!", prefix);
  162.         }
  163.     }
  164. }
  165.  
  166. public hImpact(Handle:event, const String:name[], bool:dontBroadcast)
  167. {
  168.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  169.     new Float:f_Pos[3];
  170.     f_Pos[0] = GetEventFloat(event, "x");
  171.     f_Pos[1] = GetEventFloat(event, "y");
  172.     f_Pos[2] = GetEventFloat(event, "z");
  173.    
  174.     f_Pos[2] += 30;
  175.     if(IsUsing != true)
  176.     {
  177.         if(bIsSurvivor(client))
  178.         {
  179.             int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  180.             char sWeaponEx[32];
  181.             GetEntityClassname(iCurrentWeapon, sWeaponEx, sizeof(sWeaponEx))
  182.             if(StrEqual(sWeaponEx, "weapon_pistol_magnum"))
  183.             {
  184.                 if(IsHealer[client])
  185.                 {
  186.                     TE_SetupBeamRingPoint(f_Pos, 400.0, 405.0, g_BeamSprite, g_HaloSprite, 0, 66, GetConVarFloat(hDurationRing), 4.2, 1.0, yourColor, 20, 0)
  187.                     TE_SendToAll();
  188.                    
  189.                     TE_SetupBeamRingPoint(f_Pos, 0.0, 390.0, g_BeamSprite, g_HaloSprite, 0, 66, 1.5, 1.2, 1.0, yourColor2, 120, 0)
  190.                     TE_SendToAll();
  191.                    
  192.                     new Handle:vPosition;
  193.                     TimerRepeatRing = CreateDataTimer(1.0, TimerRing, vPosition, TIMER_REPEAT | TIMER_DATA_HNDL_CLOSE)
  194.                
  195.                     WritePackFloat(vPosition, f_Pos[0]);
  196.                     WritePackFloat(vPosition, f_Pos[1]);
  197.                     WritePackFloat(vPosition, f_Pos[2]);
  198.                    
  199.                     new Handle:pack;
  200.                     HealTimer[client] = CreateDataTimer(1.0, Healing, pack, TIMER_REPEAT | TIMER_DATA_HNDL_CLOSE);
  201.                     IsUsing = true;
  202.                     WritePackCell(pack, client);
  203.                     WritePackFloat(pack, f_Pos[0]);
  204.                     WritePackFloat(pack, f_Pos[1]);
  205.                     WritePackFloat(pack, f_Pos[2]);
  206.                     WritePackFloat(pack, GetEngineTime());
  207.                 }
  208.             }
  209.         }
  210.     }
  211. }
  212.  
  213. public Action:TimerRing(Handle:timer, Handle:vPosition)
  214. {
  215.     float vPos[3];
  216.     ResetPack(vPosition);
  217.     vPos[0] = ReadPackFloat(vPosition);
  218.     vPos[1] = ReadPackFloat(vPosition);
  219.     vPos[2] = ReadPackFloat(vPosition);
  220.    
  221.     TE_SetupBeamRingPoint(vPos, 0.0, 390.0, g_BeamSprite, g_HaloSprite, 0, 66, 1.5, 1.2, 1.0, yourColor2, 120, 0)
  222.     TE_SendToAll();
  223. }
  224.  
  225.  
  226. public Action:Healing(Handle:timer, Handle:pack)
  227. {
  228.     float bPos[3], vPos[3];
  229.    
  230.     ResetPack(pack);
  231.     new client = ReadPackCell(pack);
  232.     bPos[0] = ReadPackFloat(pack);
  233.     bPos[1] = ReadPackFloat(pack);
  234.     bPos[2] = ReadPackFloat(pack);
  235.     new Float:time=ReadPackFloat(pack);
  236.    
  237.     if(GetEngineTime() - time < GetConVarFloat(hDurationRing))
  238.     {
  239.         for (new i = 1; i <= MaxClients; i++)
  240.         {
  241.             if(bIsSurvivorWitchOutBotCheck(i))
  242.             {
  243.                 GetEntPropVector(i, Prop_Send, "m_vecOrigin", vPos);
  244.                 float fTargetDistance = GetVectorDistance(bPos, vPos);
  245.                
  246.                 if (fTargetDistance > 400.0) continue;
  247.                 if (!IsVisibleTo(bPos, vPos)) continue;
  248.                
  249.                 new HP = GetClientHealth(i);
  250.                 if(HP < GetConVarInt(hMaxHealth) && !IsPlayerIncaped(i))
  251.                 {
  252.                     SetEntProp(i, Prop_Send, "m_iHealth", HP + GetConVarInt(hHealCount), 1);
  253.                 }
  254.             }
  255.         }
  256.     }
  257.     else
  258.     {
  259.         IsUsing = false;
  260.         if(HealTimer[client] != INVALID_HANDLE)
  261.         {
  262.             KillTimer(HealTimer[client]);
  263.             HealTimer[client] = INVALID_HANDLE;
  264.         }
  265.         if(TimerRepeatRing != INVALID_HANDLE)
  266.         {
  267.             KillTimer(TimerRepeatRing);
  268.             TimerRepeatRing = INVALID_HANDLE;
  269.         }
  270.     }
  271. }
  272.  
  273. public OnClientPutInServer(client)
  274. {
  275.     SDKHook(client, SDKHook_WeaponCanUse, WeaponCanUse);
  276. }
  277.  
  278. public OnClientDisconnect(client)
  279. {
  280.     SDKUnhook(client, SDKHook_WeaponCanUse, WeaponCanUse);
  281.    
  282.     if (HealTimer[client] != INVALID_HANDLE)
  283.     {
  284.         KillTimer(HealTimer[client]);
  285.         HealTimer[client] = INVALID_HANDLE;
  286.     }
  287. }
  288.  
  289. public Action:WeaponCanUse(client, weapon)
  290. {
  291.     if(bIsSurvivor(client))
  292.     {
  293.         if(IsHealer[client])
  294.         {
  295.             new wepn = GetPlayerWeaponSlot(client, 1)
  296.             if (!IsValidEntity(wepn))
  297.             {
  298.                 return Plugin_Continue;
  299.             }
  300.             decl String:sWeaponEx[32];
  301.             GetEntityClassname(wepn, sWeaponEx, sizeof(sWeaponEx));
  302.            
  303.             new String:sClassName[64];
  304.             GetEntityClassname(weapon, sClassName, sizeof(sClassName));
  305.            
  306.             if(StrEqual(sWeaponEx, "weapon_pistol_magnum"))
  307.             {
  308.                 if(StrEqual(sClassName, "weapon_melee") || StrEqual(sClassName, "weapon_pistol"))
  309.                 {
  310.                     return Plugin_Handled;
  311.                 }
  312.             }
  313.         }
  314.     }
  315.     return Plugin_Continue;
  316. }
  317.  
  318. stock bool:IsValidClient( client )
  319. {
  320.     if ( client < 1 || client > MaxClients ) return false;
  321.     if ( !IsClientConnected( client )) return false;
  322.     if ( !IsClientInGame( client )) return false;
  323.     if ( GetClientTeam( client ) != 2 ) return false;
  324.     if ( !IsPlayerAlive( client )) return false;
  325.     return true;
  326. }
  327.  
  328. GetRandomClient()
  329. {
  330.      new indexes[MaxClients+1], players = 0;
  331.      for (new i = 1; i <= MaxClients; i++)
  332.      {
  333.          if (bIsSurvivor(i)) indexes[players++] = i;
  334.      }
  335.      if (players > 0) return indexes[GetRandomInt(0, players-1)];
  336.      return 0;
  337. }
  338.  
  339. stock bool:IsPlayerIncaped(client)
  340. {
  341.     return bool:GetEntProp(client, Prop_Send, "m_isIncapacitated");
  342. }
  343.  
  344. void GiveFunction(int client, char[] name)
  345. {
  346.     char sBuf[32];
  347.     int flags = GetCommandFlags("give");
  348.     SetCommandFlags("give", flags & ~FCVAR_CHEAT);
  349.     FormatEx(sBuf, sizeof sBuf, "give %s", name);
  350.     FakeClientCommand(client, sBuf);
  351. }
  352.  
  353. stock bool bIsSurvivor(int client)
  354. {
  355.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && !IsFakeClient(client) && IsPlayerAlive(client);
  356. }
  357.  
  358. stock bool bIsSurvivorWitchOutBotCheck(int client)
  359. {
  360.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
  361. }
  362.  
  363. static bool IsVisibleTo(float position[3], float targetposition[3])
  364. {
  365.     float vAngles[3], vLookAt[3];
  366.    
  367.     MakeVectorFromPoints(position, targetposition, vLookAt); // compute vector from start to target
  368.     GetVectorAngles(vLookAt, vAngles); // get angles from vector for trace
  369.    
  370.     // execute Trace
  371.     Handle trace = TR_TraceRayFilterEx(position, vAngles, MASK_SHOT, RayType_Infinite, _TraceFilter);
  372.    
  373.     bool isVisible = false;
  374.     if (TR_DidHit(trace))
  375.     {
  376.         float vStart[3];
  377.         TR_GetEndPosition(vStart, trace); // retrieve our trace endpoint
  378.        
  379.         if ((GetVectorDistance(position, vStart, false) + 25.0) >= GetVectorDistance(position, targetposition))
  380.         {
  381.             isVisible = true; // if trace ray length plus tolerance equal or bigger absolute distance, you hit the target
  382.         }
  383.     }
  384.    
  385.     return isVisible;
  386. }
  387.  
  388. public bool _TraceFilter(int entity, int contentsMask)
  389. {
  390.     if (!entity || entity <= MaxClients || !IsValidEntity(entity)) // dont let WORLD, or invalid entities be hit
  391.     {
  392.         return false;
  393.     }
  394.     return true;
  395. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement