Advertisement
FlacoBey

Untitled

Feb 3rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.81 KB | None | 0 0
  1. #include sdktools
  2. #include sdkhooks
  3.  
  4. new bool:IsHealer[MAXPLAYERS+1] = false;
  5. static Handle hHealCount, hMaxHealth, hDurationRing;
  6.  
  7. Handle HealTimer[MAXPLAYERS+1];
  8.  
  9. new TriggerRef[MAXPLAYERS+1];
  10.  
  11. int g_HaloSprite;
  12. int g_BeamSprite;
  13. int yourColor[4] = {255, 100, 0, 255};
  14.  
  15. public OnPluginStart()
  16. {
  17.     hHealCount = CreateConVar("hCvarHealCount", "5", "Кол-во лечения", FCVAR_NONE, true, 1.0, true, 50000.0);
  18.     hMaxHealth = CreateConVar("hCvarMaxHeal", "75", "Максимальный прохил", FCVAR_NONE);
  19.     hDurationRing = CreateConVar("hCvarDuration", "15.0", "Время жизни кольца", FCVAR_NONE)
  20.     //CoolDown = CreateConVar("hCvarCoolDown", "15.0", "Кул даун юзания", FCVAR_NONE)
  21. }
  22.  
  23. public OnMapStart()
  24. {
  25.     HookEvent("bullet_impact", hImpact)
  26.     HookEvent("player_afk", hAfkFix)
  27.     CreateTimer(60.0, hSetMedic, TIMER_FLAG_NO_MAPCHANGE)
  28.    
  29.     g_BeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt", true);
  30.     g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt", true);
  31. }
  32.  
  33. public hAfkFix(Handle:event, const String:name[], bool:dontBroadcast)
  34. {
  35.     new client = GetClientOfUserId(GetEventInt(event, "player"));
  36.     if(IsHealer[client])
  37.     {
  38.         IsHealer[client] = false;
  39.         new healer = GetAnyRandomSurvivor()
  40.         IsHealer[healer] = true;
  41.         PrintToChatAll("Медик %N отошёл от игры", client);
  42.         PrintToChatAll("%N стал новым медиком", healer);
  43.     }
  44. }
  45.  
  46. public hImpact(Handle:event, const String:name[], bool:dontBroadcast)
  47. {
  48.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  49.     new Float:f_Pos[3];
  50.     f_Pos[0] = GetEventFloat(event, "x");
  51.     f_Pos[1] = GetEventFloat(event, "y");
  52.     f_Pos[2] = GetEventFloat(event, "z");
  53.    
  54.     if(bIsSurvivor(client))
  55.     {
  56.         if(IsHealer[client])
  57.         {
  58.             TE_SetupBeamRingPoint(f_Pos, 0.0, -600.0, g_BeamSprite, g_HaloSprite, 0, 66, GetConVarFloat(hDurationRing), 1.2, 1.0, yourColor, 40, 0)
  59.             TE_SendToAll();
  60.             TriggerMultiple(f_Pos, client);
  61.             CreateTimer(GetConVarFloat(hDurationRing), KillTrigger, client);
  62.         }
  63.     }
  64. }
  65.  
  66. public Action:KillTrigger(Handle:timer, any:client)
  67. {
  68.     int entity = TriggerRef[client];
  69.     AcceptEntityInput(entity, "kill");
  70. }
  71.  
  72. public Action:hSetMedic(Handle timer, any fuck)
  73. {
  74.     new client = GetAnyRandomSurvivor()
  75.     if(client > 0)
  76.     {
  77.         IsHealer[client] = true;
  78.         GiveFunction(client, "pistol_magnum")
  79.         PrintToChatAll("%N стал медиком", client);
  80.     }
  81. }
  82.  
  83. public OnClientPutInServer(client)
  84. {
  85.     //SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
  86.     SDKHook(client, SDKHook_WeaponCanUse, WeaponCanUse);
  87. }
  88.  
  89. public OnClientDisconnect(client)
  90. {
  91.     //SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage);
  92.     SDKUnhook(client, SDKHook_WeaponCanUse, WeaponCanUse);
  93.     if(IsHealer[client] == true)
  94.     {
  95.         IsHealer[client] = false;
  96.         new healer = GetAnyRandomSurvivor()
  97.         IsHealer[healer] = true;
  98.         PrintToChatAll("Медик %N покинул игру", client);
  99.         PrintToChatAll("%N стал новым медиком", healer);
  100.     }
  101.    
  102.     if (HealTimer[client] != INVALID_HANDLE)
  103.     {
  104.         KillTimer(HealTimer[client]);
  105.         HealTimer[client] = INVALID_HANDLE;
  106.     }
  107. }
  108.  
  109. public Action:WeaponCanUse(client, weapon)
  110. {
  111.     if(bIsSurvivor(client))
  112.     {
  113.         if(IsHealer[client])
  114.         {
  115.             new wepn = GetPlayerWeaponSlot(client, 1)
  116.             if (!IsValidEntity(wepn))
  117.             {
  118.                 return Plugin_Continue;
  119.             }
  120.             decl String:sWeaponEx[32];
  121.             GetEntityClassname(wepn, sWeaponEx, sizeof(sWeaponEx));
  122.            
  123.             new String:sClassName[64];
  124.             GetEntityClassname(weapon, sClassName, sizeof(sClassName));
  125.            
  126.             if(StrEqual(sWeaponEx, "weapon_pistol_magnum"))
  127.             {
  128.                 if(StrEqual(sClassName, "weapon_melee") || StrEqual(sClassName, "weapon_pistol"))
  129.                 {
  130.                     return Plugin_Handled;
  131.                 }
  132.             }
  133.         }
  134.     }
  135.     return Plugin_Continue;
  136. }
  137.  
  138. /*
  139. public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)  
  140. {
  141.     if(bIsSurvivor(victim) && bIsSurvivor(attacker))
  142.     {
  143.         if(IsHealer[attacker] == true)
  144.         {
  145.             decl String:classname[64];
  146.             GetClientWeapon(attacker, classname, sizeof(classname));
  147.             if(StrEqual(classname, "weapon_pistol_magnum"))
  148.             {
  149.                 damage = 0.0
  150.                 int heal = GetClientHealth(victim)
  151.                 if(GetConVarInt(hMaxHealth) < heal)
  152.                 {
  153.                     SetEntityHealth(victim, GetConVarInt(hHealCount) + 4);
  154.                 }
  155.             }
  156.         }
  157.     }
  158. }
  159. */
  160.  
  161. TriggerMultiple(float vPosHeal[3], client)
  162. {
  163.     new trigger = CreateEntityByName("trigger_multiple");
  164.     if (trigger < 1)
  165.     {
  166.         AcceptEntityInput(trigger, "Kill");
  167.         LogError("ERROR:WCP-231-K57");
  168.         return;
  169.     }
  170.  
  171.     DispatchKeyValue(trigger, "spawnflags", "1");
  172.     DispatchKeyValue(trigger, "wait", "0");
  173.     DispatchSpawn(trigger);
  174.     ActivateEntity(trigger);
  175.     SetEntityModel(trigger, "models/w_models/weapons/w_desert_eagle.mdl");
  176.     TeleportEntity(trigger, vPosHeal, NULL_VECTOR, NULL_VECTOR);
  177.    
  178.     SetEntPropVector(trigger, Prop_Send, "m_vecMins", Float:{-100.0, -100.0, -83.0});
  179.     SetEntPropVector(trigger, Prop_Send, "m_vecMaxs", Float:{100.0, 100.0, 83.0});
  180.     SetEntProp(trigger, Prop_Send, "m_nSolidType", 2);
  181.     new iEffects = GetEntProp(trigger, Prop_Send, "m_fEffects");
  182.     iEffects = 32;
  183.     SetEntProp(trigger, Prop_Send, "m_fEffects", iEffects);
  184.     HookSingleEntityOutput(trigger, "OnStartTouch", OnStartTouch);
  185.     HookSingleEntityOutput(trigger, "OnEndTouch", OnEndTouch);
  186.     TriggerRef[client] = EntIndexToEntRef(trigger);
  187.    
  188. }
  189.  
  190. public OnStartTouch(const String:output[], ent, client, Float:delay)
  191. {
  192.     if(bIsSurvivor(client))
  193.     {
  194.         if (HealTimer[client] == INVALID_HANDLE)
  195.         {
  196.             PrintToChatAll("%N вошёл в зону", client);
  197.             HealTimer[client] = CreateTimer(1.0, HealTime, client, TIMER_REPEAT);
  198.         }
  199.     }
  200. }
  201.  
  202. public OnEndTouch(const String:output[], ent, client, Float:delay)
  203. {
  204.     if(bIsSurvivor(client))
  205.     {
  206.         if (HealTimer[client] != INVALID_HANDLE)
  207.         {
  208.             KillTimer(HealTimer[client]);
  209.             HealTimer[client] = INVALID_HANDLE;
  210.         }
  211.         PrintToChatAll("%N покинул зону", client);
  212.     }
  213. }
  214.  
  215. public Action:HealTime(Handle:timer, any:client)
  216. {
  217.     new heal = GetClientHealth(client);
  218.     new Need = GetClientHealth(client) + GetConVarInt(hHealCount);
  219.     if (heal < GetConVarInt(hMaxHealth))
  220.     {
  221.         SetEntityHealth(client, Need);
  222.     }
  223.     return Plugin_Stop;
  224. }
  225.  
  226.  
  227. stock GetAnyRandomSurvivor()
  228. {
  229.     new electables = 0, pool[4];
  230.     for (new player = 1; player <= MaxClients; player++)
  231.     {
  232.         if (player > 0 && bIsSurvivor(player))
  233.         {
  234.             pool[electables] = player;
  235.             electables += 1;
  236.         }
  237.     }
  238.     return pool[GetRandomInt(0, electables)];
  239. }
  240.  
  241. void GiveFunction(int client, char[] name)
  242. {
  243.     char sBuf[32];
  244.     int flags = GetCommandFlags("give");
  245.     SetCommandFlags("give", flags & ~FCVAR_CHEAT);
  246.     FormatEx(sBuf, sizeof sBuf, "give %s", name);
  247.     FakeClientCommand(client, sBuf);
  248. }
  249.  
  250. stock bool bIsSurvivor(int client)
  251. {
  252.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement