Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include sdktools
- #include sdkhooks
- #include colors
- #define prefix "\x05[Medic]"
- new bool:IsHealer[MAXPLAYERS+1] = false;
- new bool:IsUsing = false;
- new bool:hHasLeftArea = false;
- new bool:IsHaveMedic = false;
- static Handle hHealCount, hMaxHealth, hDurationRing;
- Handle HealTimer[MAXPLAYERS+1], TimerRepeatRing;
- int g_HaloSprite;
- int g_BeamSprite;
- int yourColor[4] = {220, 20, 60, 255};
- int yourColor2[4] = {205, 92, 92, 255};
- public OnPluginStart()
- {
- hHealCount = CreateConVar("hCvarHealCount", "5", "Кол-во лечения", FCVAR_NONE, true, 1.0, true, 50000.0);
- hMaxHealth = CreateConVar("hCvarMaxHeal", "75", "Максимальный прохил", FCVAR_NONE);
- hDurationRing = CreateConVar("hCvarDuration", "15.0", "Время жизни кольца", FCVAR_NONE, true, 1.0, true, 25.0)
- //hDistance = CreateConVar("hCvarDuration", "600.0", "Дистаннция", FCVAR_NONE)
- //CoolDown = CreateConVar("hCvarCoolDown", "15.0", "Кул даун юзания", FCVAR_NONE)
- RegConsoleCmd("sm_rmedic", hRandomMedic);
- RegConsoleCmd("sm_bm", hBecomeMedic);
- AutoExecConfig(true, "hMedicPlug");
- }
- public OnMapStart()
- {
- HookEvent("player_team", hMedicChangeTeam)
- HookEvent("player_death", hDeath)
- HookEvent("player_left_start_area", hLeftStart)
- HookEvent("bullet_impact", hImpact)
- g_BeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt", true);
- g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt", true);
- for(int i = 1; i <= MaxClients; ++i)
- {
- IsHealer[i] = false;
- }
- IsUsing = false;
- hHasLeftArea = false;
- }
- public Action:hBecomeMedic(client, args)
- {
- if(hHasLeftArea)
- {
- if(bIsSurvivor(client))
- {
- if(IsHaveMedic == false)
- {
- IsHealer[client] = true;
- IsHaveMedic = true;
- CPrintToChatAll("%s {red}%N \x05прописал \x04!bm \x05и стал новым медиком", prefix, client);
- GiveFunction(client, "pistol_magnum");
- }
- }
- }
- else
- {
- CPrintToChat(client, "%s {blue}Раунд ещё не начался.", prefix)
- }
- }
- public hDeath(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event, "userid"));
- if(IsHealer[client])
- {
- CPrintToChatAll("%s \x05Медик \x04погиб в перестрелке(земля ему пухом).", prefix, client);
- }
- }
- public Action:hRandomMedic(client, args)
- {
- if(IsHealer[client])
- {
- int SurvivorsCount = 0;
- for(int i = 1; i <= MaxClients; ++i)
- {
- if(bIsSurvivor(i))
- {
- SurvivorsCount++;
- }
- }
- if (SurvivorsCount > 1)
- {
- new NewHealer = GetRandomClient()
- IsHealer[client] = false;
- IsHealer[NewHealer] = true;
- IsHaveMedic = true;
- CPrintToChatAll("%s {red}%N \x05отдал медика рандомному сурву.", prefix, client);
- CPrintToChatAll("%s {red}%N \x05стал новым медиком", prefix, NewHealer);
- new weap = GetPlayerWeaponSlot(client, 1);
- RemovePlayerItem(client, weap);
- GiveFunction(NewHealer, "pistol_magnum");
- GiveFunction(client, "pistol");
- }
- else
- {
- CPrintToChatAll("%s {red}Нужно, как минимум 2 игрока за выживших.", prefix);
- }
- }
- else
- {
- CPrintToChatAll("%s {red}Вы не медик.", prefix);
- }
- }
- public hLeftStart(Handle:event, const String:name[], bool:dontBroadcast)
- {
- if(hHasLeftArea == false)
- {
- new client = GetRandomClient()
- IsHealer[client] = true;
- GiveFunction(client, "pistol_magnum")
- CPrintToChatAll("%s {blue}%N \x05стал медиком", prefix, client);
- hHasLeftArea = true;
- IsHaveMedic = true;
- }
- }
- public hMedicChangeTeam(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event, "userid"));
- if(IsHealer[client])
- {
- CPrintToChatAll("%s \x05Медик %N \x04поменял команду, либо вышел.", prefix, client)
- int SurvivorsCount = 0;
- for(int i = 1; i <= MaxClients; ++i)
- {
- if(bIsSurvivor(i))
- {
- SurvivorsCount++;
- }
- }
- if(SurvivorsCount > 0)
- {
- new healer = GetRandomClient()
- GiveFunction(healer, "pistol_magnum");
- IsHealer[healer] = true;
- IsHealer[client] = false;
- CPrintToChatAll("%s {red}%N \x05стал новым медиком", prefix, healer);
- GiveFunction(healer, "pistol_magnum");
- }
- else
- {
- for(int i = 1; i <= MaxClients; ++i)
- {
- IsHealer[i] = false;
- }
- IsHaveMedic = false;
- CPrintToChatAll("%s {red}В команде выживших, только боты!", prefix);
- CPrintToChatAll("%s {blue}Зайдите за команду выживших и пропишите !bm, чтобы стать медиком!", prefix);
- }
- }
- }
- public hImpact(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event, "userid"));
- new Float:f_Pos[3];
- f_Pos[0] = GetEventFloat(event, "x");
- f_Pos[1] = GetEventFloat(event, "y");
- f_Pos[2] = GetEventFloat(event, "z");
- f_Pos[2] += 30;
- if(IsUsing != true)
- {
- if(bIsSurvivor(client))
- {
- int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
- char sWeaponEx[32];
- GetEntityClassname(iCurrentWeapon, sWeaponEx, sizeof(sWeaponEx))
- if(StrEqual(sWeaponEx, "weapon_pistol_magnum"))
- {
- if(IsHealer[client])
- {
- TE_SetupBeamRingPoint(f_Pos, 400.0, 405.0, g_BeamSprite, g_HaloSprite, 0, 66, GetConVarFloat(hDurationRing), 4.2, 1.0, yourColor, 20, 0)
- TE_SendToAll();
- TE_SetupBeamRingPoint(f_Pos, 0.0, 390.0, g_BeamSprite, g_HaloSprite, 0, 66, 1.5, 1.2, 1.0, yourColor2, 120, 0)
- TE_SendToAll();
- new Handle:vPosition;
- TimerRepeatRing = CreateDataTimer(1.0, TimerRing, vPosition, TIMER_REPEAT | TIMER_DATA_HNDL_CLOSE)
- WritePackFloat(vPosition, f_Pos[0]);
- WritePackFloat(vPosition, f_Pos[1]);
- WritePackFloat(vPosition, f_Pos[2]);
- new Handle:pack;
- HealTimer[client] = CreateDataTimer(1.0, Healing, pack, TIMER_REPEAT | TIMER_DATA_HNDL_CLOSE);
- IsUsing = true;
- WritePackCell(pack, client);
- WritePackFloat(pack, f_Pos[0]);
- WritePackFloat(pack, f_Pos[1]);
- WritePackFloat(pack, f_Pos[2]);
- WritePackFloat(pack, GetEngineTime());
- }
- }
- }
- }
- }
- public Action:TimerRing(Handle:timer, Handle:vPosition)
- {
- float vPos[3];
- ResetPack(vPosition);
- vPos[0] = ReadPackFloat(vPosition);
- vPos[1] = ReadPackFloat(vPosition);
- vPos[2] = ReadPackFloat(vPosition);
- TE_SetupBeamRingPoint(vPos, 0.0, 390.0, g_BeamSprite, g_HaloSprite, 0, 66, 1.5, 1.2, 1.0, yourColor2, 120, 0)
- TE_SendToAll();
- }
- public Action:Healing(Handle:timer, Handle:pack)
- {
- float bPos[3], vPos[3];
- ResetPack(pack);
- new client = ReadPackCell(pack);
- bPos[0] = ReadPackFloat(pack);
- bPos[1] = ReadPackFloat(pack);
- bPos[2] = ReadPackFloat(pack);
- new Float:time=ReadPackFloat(pack);
- if(GetEngineTime() - time < GetConVarFloat(hDurationRing))
- {
- for (new i = 1; i <= MaxClients; i++)
- {
- if(bIsSurvivorWitchOutBotCheck(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vPos);
- float fTargetDistance = GetVectorDistance(bPos, vPos);
- if (fTargetDistance > 400.0) continue;
- if (!IsVisibleTo(bPos, vPos)) continue;
- new HP = GetClientHealth(i);
- if(HP < GetConVarInt(hMaxHealth) && !IsPlayerIncaped(i))
- {
- SetEntProp(i, Prop_Send, "m_iHealth", HP + GetConVarInt(hHealCount), 1);
- }
- }
- }
- }
- else
- {
- IsUsing = false;
- if(HealTimer[client] != INVALID_HANDLE)
- {
- KillTimer(HealTimer[client]);
- HealTimer[client] = INVALID_HANDLE;
- }
- if(TimerRepeatRing != INVALID_HANDLE)
- {
- KillTimer(TimerRepeatRing);
- TimerRepeatRing = INVALID_HANDLE;
- }
- }
- }
- public OnClientPutInServer(client)
- {
- SDKHook(client, SDKHook_WeaponCanUse, WeaponCanUse);
- }
- public OnClientDisconnect(client)
- {
- SDKUnhook(client, SDKHook_WeaponCanUse, WeaponCanUse);
- if (HealTimer[client] != INVALID_HANDLE)
- {
- KillTimer(HealTimer[client]);
- HealTimer[client] = INVALID_HANDLE;
- }
- }
- public Action:WeaponCanUse(client, weapon)
- {
- if(bIsSurvivor(client))
- {
- if(IsHealer[client])
- {
- new wepn = GetPlayerWeaponSlot(client, 1)
- if (!IsValidEntity(wepn))
- {
- return Plugin_Continue;
- }
- decl String:sWeaponEx[32];
- GetEntityClassname(wepn, sWeaponEx, sizeof(sWeaponEx));
- new String:sClassName[64];
- GetEntityClassname(weapon, sClassName, sizeof(sClassName));
- if(StrEqual(sWeaponEx, "weapon_pistol_magnum"))
- {
- if(StrEqual(sClassName, "weapon_melee") || StrEqual(sClassName, "weapon_pistol"))
- {
- return Plugin_Handled;
- }
- }
- }
- }
- return Plugin_Continue;
- }
- stock bool:IsValidClient( client )
- {
- if ( client < 1 || client > MaxClients ) return false;
- if ( !IsClientConnected( client )) return false;
- if ( !IsClientInGame( client )) return false;
- if ( GetClientTeam( client ) != 2 ) return false;
- if ( !IsPlayerAlive( client )) return false;
- return true;
- }
- GetRandomClient()
- {
- new indexes[MaxClients+1], players = 0;
- for (new i = 1; i <= MaxClients; i++)
- {
- if (bIsSurvivor(i)) indexes[players++] = i;
- }
- if (players > 0) return indexes[GetRandomInt(0, players-1)];
- return 0;
- }
- stock bool:IsPlayerIncaped(client)
- {
- return bool:GetEntProp(client, Prop_Send, "m_isIncapacitated");
- }
- void GiveFunction(int client, char[] name)
- {
- char sBuf[32];
- int flags = GetCommandFlags("give");
- SetCommandFlags("give", flags & ~FCVAR_CHEAT);
- FormatEx(sBuf, sizeof sBuf, "give %s", name);
- FakeClientCommand(client, sBuf);
- }
- stock bool bIsSurvivor(int client)
- {
- return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && !IsFakeClient(client) && IsPlayerAlive(client);
- }
- stock bool bIsSurvivorWitchOutBotCheck(int client)
- {
- return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
- }
- static bool IsVisibleTo(float position[3], float targetposition[3])
- {
- float vAngles[3], vLookAt[3];
- MakeVectorFromPoints(position, targetposition, vLookAt); // compute vector from start to target
- GetVectorAngles(vLookAt, vAngles); // get angles from vector for trace
- // execute Trace
- Handle trace = TR_TraceRayFilterEx(position, vAngles, MASK_SHOT, RayType_Infinite, _TraceFilter);
- bool isVisible = false;
- if (TR_DidHit(trace))
- {
- float vStart[3];
- TR_GetEndPosition(vStart, trace); // retrieve our trace endpoint
- if ((GetVectorDistance(position, vStart, false) + 25.0) >= GetVectorDistance(position, targetposition))
- {
- isVisible = true; // if trace ray length plus tolerance equal or bigger absolute distance, you hit the target
- }
- }
- return isVisible;
- }
- public bool _TraceFilter(int entity, int contentsMask)
- {
- if (!entity || entity <= MaxClients || !IsValidEntity(entity)) // dont let WORLD, or invalid entities be hit
- {
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement