#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
bool gUsed;
bool gNoStopTimer;
Handle g_iTimer[10];
int g_iTimerCount;
bool success_button_used;
int MaxEntities;
public Plugin myinfo = {
name = "triggers Unlock",
author = "GF",
description = "unlock map triggers",
version = "0.1",
url = ""
}
public void OnPluginStart() {
MaxEntities = GetMaxEntities() * 2;
HookEvent("waiting_checkpoint_button_used", Event_button_used);
HookEvent("success_checkpoint_button_used", Event_success_button_used);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("player_use", Event_player_use);
HookEvent("round_end", Event_MapEnd,EventHookMode_PostNoCopy);
HookEvent("map_transition", Event_MapEnd,EventHookMode_PostNoCopy);
HookEvent("finale_win", Event_MapEnd,EventHookMode_PostNoCopy);
HookEvent("round_end", Event_MapEnd,EventHookMode_PostNoCopy);
HookEvent("mission_lost", Event_MapEnd,EventHookMode_PostNoCopy);
RegConsoleCmd("sm_usetrigger", CMD_usetrigger);
}
public Action CMD_usetrigger(int client, int args) {
usetrigger(client);
}
void killTimers() {
for ( int i = 0; i < g_iTimerCount+1; i++ ) {
delete g_iTimer[i];
}
}
public Action Event_MapEnd(Event event, const char[] name, bool dontBroadcast) {
if (gNoStopTimer == false) {
killTimers();
}
gNoStopTimer = true;
gUsed = false;
gNoStopTimer = false;
g_iTimerCount = 0;
success_button_used = false;
}
public void OnMapEnd() {
if (gNoStopTimer == false) {
killTimers();
}
gNoStopTimer = true;
}
public void Event_player_use(Event event, const char[] name, bool dontBroadcast) {
int client = GetClientOfUserId(GetEventInt(event, "userid"));
int Target = GetEventInt(event, "targetid");
if (gUsed == false && allowedMap(Target) == true) {
char Temp[64];
if (Target > 0 && IsValidEntity(Target)) {
GetEntPropString(Target, Prop_Data, "m_iName", Temp, 64);
if (StrEqual(Temp, "finale_cleanse_exit_door", false)) {
if (GetEntProp(Target, Prop_Data, "m_bLocked", 1)== 1) {
gUsed = true;
g_iTimer[g_iTimerCount] = CreateTimer(1.0, Timer_doorOpen, client);
g_iTimerCount++;
}
}
else if (StrEqual(Temp, "bridge_start_button", false)) {
if (GetEntProp(Target, Prop_Data, "m_bLocked", 1)== 1) {
gUsed = true;
g_iTimer[g_iTimerCount] = CreateTimer(1.0, Timer_doorOpen, client);
g_iTimerCount++;
}
}
}
}
}
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) {
gUsed = false;
gNoStopTimer = false;
g_iTimerCount = 0;
success_button_used = false;
}
void NullifyHandle(Handle timer)
{
for( int i = 0; i < g_iTimerCount+1; i++ )
{
if( timer == g_iTimer[i])
{
g_iTimer[i] = null;
break;
}
}
}
public Action Event_button_used(Event event, const char[] name, bool dontBroadcast) {
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (gUsed == false && allowedMap() == true) {
gUsed = true;
g_iTimer[g_iTimerCount] = CreateTimer(1.0, Timer_doorOpen, client);
g_iTimerCount++;
}
}
public Action Event_success_button_used(Event event, const char[] name, bool dontBroadcast) {
success_button_used = true;
}
public Action Timer_doorOpen(Handle timer, any client) {
check_Fix_doorOpened();
if (success_button_used == false) {
PrintHintTextToAll("The trigger will be unlocked in 30 seconds!");
PrintToChatAll("\x05The trigger will be unlocked in 30 seconds!");
g_iTimer[g_iTimerCount] = CreateTimer(30.0, Timer_doorOpen10);
g_iTimerCount++;
}
NullifyHandle(timer);
}
public Action Timer_doorOpen10(Handle timer) {
check_Fix_doorOpened();
if (success_button_used == false) {
PrintHintTextToAll("Trigger Unlocked!");
PrintToChatAll("\x05Trigger Unlocked!");
usetrigger();
}
NullifyHandle(timer);
}
void check_c6m3_port_doorOpened() {
char mapName [48];
GetCurrentMap(mapName, sizeof(mapName));
if (StrEqual(mapName, "c6m3_port", false)) {
int Entity = FindEntityWildcard("generator_elevator_button");
if (!IsValidEntity(Entity) || GetEntProp(Entity, Prop_Data, "m_bLocked", 1)==0) success_button_used = true;
}
}
void check_Fix_doorOpened() {
check_c5m2_park_doorOpened();
check_c6m3_port_doorOpened();
}
void check_c5m2_park_doorOpened() {
char mapName [48];
GetCurrentMap(mapName, sizeof(mapName));
if (StrEqual(mapName, "c5m2_park", false)) {
int Entity = FindEntityWildcard("finale_cleanse_exit_door");
if (!IsValidEntity(Entity) || GetEntProp(Entity, Prop_Data, "m_bLocked", 1)==0) success_button_used = true;
}
}
bool allowedMap(int Entity = 0) {
char mapName [48];
GetCurrentMap(mapName, sizeof(mapName));
if (StrEqual(mapName, "c1m1_hotel", false)) {
return true;
}
else if (StrEqual(mapName, "c1m4_atrium", false)) {
return true;
}
else if (StrEqual(mapName, "c6m3_port", false)) {
return true;
}
else if (StrEqual(mapName, "c4m2_sugarmill_a", false)) {
return true;
}
else if (StrEqual(mapName, "c4m3_sugarmill_b", false)) {
return true;
}
else if (StrEqual(mapName, "c5m2_park", false)) {
return true;
}
else if (StrEqual(mapName, "c8m4_interior", false)) {
return true;
}
return false;
}
int FindEntityWildcard(const char [] Name, const int Start = -1)
{
// To hold the name taken from the entity being checked.
char TempName[64];
// First, find the "*" wildcard. If it's present, we truncate the search limit.
int StringLimit = StrContains(Name, "*");
// If no match is found, reset to the entire length, to include the terminating NULL.
// There's a sanity check, in case the entity name is malformed.
if (StringLimit < 0)
StringLimit = (strlen(Name) < 64) ? strlen(Name) + 1 : 64;
// Go through the entries from the start until the limit is reached.
for (int i = Start + 1; i < MaxEntities ; i++)
{
// If the entity is invalid, skip to the next entity.
if (!IsValidEntity(i))
continue;
// Get the entity's name to compare.
GetEntPropString(i, Prop_Data, "m_iName", TempName, 64);
// We use strncmp since it allows to limit the length of the search,
// in case the "*" is present.
if (strncmp(Name, TempName, StringLimit, false) == 0)
// We have a match. Stop processing and return the match.
return i;
}
// No match. Return the invalid reference.
return INVALID_ENT_REFERENCE;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
void usetrigger(int client = 0) {
char mapName [48];
int Entity;
if (client == 0) client = anyClient();
GetCurrentMap(mapName, sizeof(mapName));
//PrintToChatAll("GetCurrentMap");
if (StrEqual(mapName, "c8m5_rooftop", false) )
{
Entity = FindEntityWildcard("radio_button");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "press", client);
//Entity = FindEntityWildcard("radio");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "use", client);
}
else if (StrEqual(mapName, "c1m1_hotel", false))
{
Entity = FindEntityWildcard("elevator_button");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "unlock", client);
//Entity = FindEntityWildcard("elevator_button");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "press", client);
}
else if (StrEqual(mapName, "c1m4_atrium", false))
{
Entity = FindEntityWildcard("button_elev_3rdfloor");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "unlock", client);
//Entity = FindEntityWildcard("button_elev_3rdfloor");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "press", client);
}
else if (StrEqual(mapName, "c6m3_port", false))
{
Entity = FindEntityWildcard("generator_elevator_button");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "unlock", client);
//Entity = FindEntityWildcard("generator_elevator_button");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "press", client);
}
else if (StrEqual(mapName, "c4m2_sugarmill_a", false))
{
Entity = FindEntityWildcard("button_inelevator");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "unlock", client);
//Entity = FindEntityWildcard("button_inelevator");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "press", client);
}
else if (StrEqual(mapName, "c4m3_sugarmill_b", false))
{
Entity = FindEntityWildcard("button_inelevator");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "unlock", client);
//Entity = FindEntityWildcard("button_inelevator");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "press", client);
}
else if (StrEqual(mapName, "c5m2_park", false))
{
Entity = FindEntityWildcard("finale_cleanse_exit_door");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "unlock", client);
//Entity = FindEntityWildcard("finale_cleanse_exit_door");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "open", client);
}
else if (StrEqual(mapName, "c8m4_interior", false))
{
Entity = FindEntityWildcard("elevator_button");
if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "unlock", client);
//Entity = FindEntityWildcard("finale_cleanse_exit_door");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "open", client);
}
else if (StrEqual(mapName, "c7m3_port", false))
{
Entity = FindEntityWildcard("bridge_start_button");
if (IsValidEntity(Entity)) {
AcceptEntityInput(Entity, "unlock", client);
}
//Entity = FindEntityWildcard("finale_cleanse_exit_door");
//if (IsValidEntity(Entity)) AcceptEntityInput(Entity, "open", client);
}
}
int anyClient(){
for(int i = 1; i <= MaxClients; i++){
if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) != 3 && IsPlayerAlive(i)) {
return i;
}
}
}