Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #pragma newdecls required
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- // Plugin Variables
- int g_iLightIndex[MAXPLAYERS+1], g_iPlayerEnum[MAXPLAYERS+1], g_iWeaponIndex[MAXPLAYERS+1], g_iFlashlight_Offset;
- float g_fTime[MAXPLAYERS+1];
- enum ()
- {
- ENUM_INCAPPED = (1 << 0),
- ENUM_INSTART = (1 << 1),
- ENUM_BLOCKED = (1 << 2),
- ENUM_POUNCED = (1 << 3),
- ENUM_ONLEDGE = (1 << 4),
- ENUM_INREVIVE = (1 << 5),
- ENUM_DISTANCE = (1 << 6),
- ENUM_BLOCK = (1 << 7)
- }
- public void OnPluginStart()
- {
- g_iFlashlight_Offset = FindSendPropInfo("CTerrorPlayer", "m_fEffects");
- HookEvents();
- }
- public void OnPluginEnd()
- {
- UnhookEvents();
- for( int i = 1; i <= MaxClients; i++ )
- DeleteLight(i);
- }
- int GetColor(char[] sTemp)
- {
- char sColors[3][4];
- ExplodeString(sTemp, " ", sColors, 3, 4);
- int color;
- color = StringToInt(sColors[0]);
- color += 256 * StringToInt(sColors[1]);
- color += 65536 * StringToInt(sColors[2]);
- return color;
- }
- // ====================================================================================================
- // EVENTS
- // ====================================================================================================
- void HookEvents()
- {
- HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
- HookEvent("player_ledge_grab", Event_LedgeGrab);
- HookEvent("player_spawn", Event_PlayerSpawn);
- HookEvent("revive_begin", Event_ReviveStart);
- HookEvent("revive_end", Event_ReviveEnd);
- HookEvent("revive_success", Event_ReviveSuccess);
- HookEvent("player_death", Event_Unblock);
- HookEvent("lunge_pounce", Event_BlockHunter);
- HookEvent("pounce_end", Event_BlockEndHunt);
- HookEvent("tongue_grab", Event_BlockStart);
- HookEvent("tongue_release", Event_BlockEnd);
- HookEvent("charger_pummel_start", Event_BlockStart);
- HookEvent("charger_carry_start", Event_BlockStart);
- HookEvent("charger_carry_end", Event_BlockEnd);
- HookEvent("charger_pummel_end", Event_BlockEnd);
- HookEvent("jockey_ride", Event_BlockStart);
- HookEvent("jockey_ride_end", Event_BlockEnd);
- }
- void UnhookEvents()
- {
- UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
- UnhookEvent("player_ledge_grab", Event_LedgeGrab);
- UnhookEvent("player_spawn", Event_PlayerSpawn);
- UnhookEvent("revive_begin", Event_ReviveStart);
- UnhookEvent("revive_end", Event_ReviveEnd);
- UnhookEvent("revive_success", Event_ReviveSuccess);
- UnhookEvent("player_death", Event_Unblock);
- UnhookEvent("lunge_pounce", Event_BlockHunter);
- UnhookEvent("pounce_end", Event_BlockEndHunt);
- UnhookEvent("tongue_grab", Event_BlockStart);
- UnhookEvent("tongue_release", Event_BlockEnd);
- UnhookEvent("charger_pummel_start", Event_BlockStart);
- UnhookEvent("charger_carry_start", Event_BlockStart);
- UnhookEvent("charger_carry_end", Event_BlockEnd);
- UnhookEvent("charger_pummel_end", Event_BlockEnd);
- UnhookEvent("jockey_ride", Event_BlockStart);
- UnhookEvent("jockey_ride_end", Event_BlockEnd);
- }
- public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
- {
- for( int i = 1; i < MAXPLAYERS; i++ )
- g_iPlayerEnum[i] = 0;
- }
- public void Event_BlockUserEnd(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("victim"));
- if( client > 0 )
- g_iPlayerEnum[client] &= ~ENUM_BLOCKED;
- }
- public void Event_BlockStart(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("victim"));
- if( client > 0 )
- g_iPlayerEnum[client] |= ENUM_BLOCKED;
- }
- public void Event_BlockEnd(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("victim"));
- if( client > 0 )
- g_iPlayerEnum[client] &= ~ENUM_BLOCKED;
- }
- public void Event_BlockHunter(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("victim"));
- if( client > 0 )
- g_iPlayerEnum[client] |= ENUM_POUNCED;
- }
- public void Event_BlockEndHunt(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("victim"));
- if( client > 0 )
- {
- g_fTime[client] = GetGameTime() - 1.0;
- g_iPlayerEnum[client] &= ~ENUM_POUNCED;
- }
- }
- public void Event_LedgeGrab(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("userid"));
- if( client > 0 )
- g_iPlayerEnum[client] |= ENUM_ONLEDGE;
- }
- public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("userid"));
- if( client > 0 )
- {
- g_iPlayerEnum[client] = 0;
- }
- }
- public void Event_ReviveStart(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("subject"));
- if( client > 0 )
- g_iPlayerEnum[client] |= ENUM_INREVIVE;
- client = GetClientOfUserId(event.GetInt("userid"));
- if( client > 0 )
- g_iPlayerEnum[client] |= ENUM_INREVIVE;
- }
- public void Event_ReviveEnd(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("subject"));
- if( client > 0 )
- g_iPlayerEnum[client] &= ~ENUM_INREVIVE;
- client = GetClientOfUserId(event.GetInt("userid"));
- if( client > 0 )
- g_iPlayerEnum[client] &= ~ENUM_INREVIVE;
- }
- public void Event_ReviveSuccess(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("subject"));
- if( client > 0 )
- {
- g_iPlayerEnum[client] &= ~ENUM_INREVIVE;
- g_iPlayerEnum[client] &= ~ENUM_ONLEDGE;
- }
- client = GetClientOfUserId(event.GetInt("userid"));
- if( client > 0 )
- g_iPlayerEnum[client] &= ~ENUM_INREVIVE;
- }
- public void Event_Unblock(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("userid"));
- if( client > 0)
- g_iPlayerEnum[client] = 0;
- }
- // ====================================================================================================
- // DYNAMIC LIGHT ON/OFF
- // ====================================================================================================
- public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon)
- {
- int entity = g_iLightIndex[client];
- if( GetClientTeam(client) != 2 || !IsPlayerAlive(client) )
- {
- if( IsValidEntRef(entity) == true )
- DeleteLight(client);
- return;
- }
- if( IsValidEntRef(entity) == false )
- {
- entity = CreateLight(client);
- }
- int index = g_iWeaponIndex[client];
- int active = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
- if( index != active )
- {
- g_iWeaponIndex[client] = active;
- if( active == -1 )
- {
- g_iPlayerEnum[client] |= ENUM_BLOCK;
- }
- else
- {
- char sTemp[32];
- GetClientWeapon(client, sTemp, sizeof(sTemp));
- if( strcmp(sTemp, "weapon_melee") == 0 ||
- strcmp(sTemp, "weapon_chainsaw") == 0 ||
- strcmp(sTemp, "weapon_vomitjar") == 0 ||
- strcmp(sTemp, "weapon_pipe_bomb") == 0 ||
- strcmp(sTemp, "weapon_defibrillator") == 0 ||
- strcmp(sTemp, "weapon_first_aid_kit") == 0 ||
- strcmp(sTemp, "weapon_upgradepack_explosive") == 0 ||
- strcmp(sTemp, "weapon_upgradepack_incendiary") == 0 ||
- strcmp(sTemp, "weapon_first_aid_kit") == 0 ||
- strcmp(sTemp, "weapon_pain_pills") == 0 ||
- strcmp(sTemp, "weapon_adrenaline") == 0 ||
- strcmp(sTemp, "cola_bottles") == 0 ||
- strcmp(sTemp, "weapon_fireworkcrate") == 0 ||
- strcmp(sTemp, "weapon_gascan") == 0 ||
- strcmp(sTemp, "weapon_gnome") == 0 ||
- strcmp(sTemp, "weapon_oxygentank") == 0 ||
- strcmp(sTemp, "weapon_propanetank") == 0
- )
- g_iPlayerEnum[client] |= ENUM_BLOCK;
- else
- g_iPlayerEnum[client] &= ~ENUM_BLOCK;
- }
- }
- int playerenum = g_iPlayerEnum[client];
- if(playerenum == 0 && IsValidEntity(entity))
- {
- if(GetFlashlightState(client) == 4)
- {
- AcceptEntityInput(entity, "TurnOn");
- TeleportDynamicLight(client, entity);
- }
- else
- AcceptEntityInput(entity, "TurnOff");
- }
- }
- static int GetFlashlightState(int client)
- {
- return GetEntData(client, g_iFlashlight_Offset);
- }
- void DeleteLight(int client)
- {
- int entity = g_iLightIndex[client];
- g_iLightIndex[client] = 0;
- if(IsValidEntRef(entity) )
- {
- AcceptEntityInput(entity, "Kill");
- }
- }
- int CreateLight(int client)
- {
- int entity = g_iLightIndex[client];
- if( IsValidEntRef(entity) )
- return 0;
- entity = CreateEntityByName("light_dynamic");
- if( entity == -1)
- {
- LogError("Failed to create 'light_dynamic'");
- return 0;
- }
- char sColor[12];
- Format(sColor, sizeof sColor, "200 225 255");
- DispatchKeyValue(entity, "brightness", "1");
- DispatchKeyValueFloat(entity, "spotlight_radius", 32.0);
- DispatchKeyValueFloat(entity, "distance", 125.0);
- DispatchKeyValue(entity, "style", "0");
- SetEntProp(entity, Prop_Send, "m_clrRender", GetColor(sColor));
- DispatchSpawn(entity);
- AcceptEntityInput(entity, "TurnOn");
- g_iLightIndex[client] = EntIndexToEntRef(entity);
- return entity;
- }
- void TeleportDynamicLight(int client, int entity)
- {
- float vLoc[3], vPos[3], vAng[3];
- GetClientEyeAngles(client, vAng);
- GetClientEyePosition(client, vLoc);
- Handle trace;
- float vDir[3], vEnd[3];
- GetAngleVectors(vAng, vDir, NULL_VECTOR, NULL_VECTOR);
- vEnd = vLoc;
- vEnd[0] += vDir[0] * 5000;
- vEnd[1] += vDir[1] * 5000;
- vEnd[2] += vDir[2] * 5000;
- trace = TR_TraceHullFilterEx(vLoc, vEnd, view_as<float>({ -10.0, -10.0, -10.0 }), view_as<float>({ 10.0, 10.0, 10.0 }), MASK_SHOT, TraceFilter, client);
- if( TR_DidHit(trace) )
- {
- TR_GetEndPosition(vPos, trace);
- float fDist = GetVectorDistance(vLoc, vPos);
- if(fDist <= 60.0)
- {
- AcceptEntityInput(entity, "TurnOff");
- }
- else if( fDist <= 500.0 + 50 )
- {
- GetAngleVectors(vAng, vAng, NULL_VECTOR, NULL_VECTOR);
- vPos[0] -= vAng[0] * 50;
- vPos[1] -= vAng[1] * 50;
- vPos[2] -= vAng[2] * 50;
- TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
- }
- else
- {
- GetAngleVectors(vAng, vAng, NULL_VECTOR, NULL_VECTOR);
- vPos[0] = vLoc[0] + (vAng[0] * 500.0);
- vPos[1] = vLoc[1] + (vAng[1] * 500.0);
- vPos[2] = vLoc[2] + (vAng[2] * 500.0);
- TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
- }
- }
- delete trace;
- }
- public bool TraceFilter(int entity, int contentsMask, any client)
- {
- if( entity == client )
- return false;
- return true;
- }
- bool IsValidEntRef(int entity)
- {
- if( entity && EntRefToEntIndex(entity) != INVALID_ENT_REFERENCE )
- return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement