Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #include <autoexecconfig>
- #include <csgocolors>
- #include <emitsoundany>
- #pragma semicolon 1
- #pragma newdecls required
- #define SOUND_BLIP "buttons/blip1.wav"
- #define PLUGIN_VERSION "1.6"
- #define AMMOUNT_OF_COLORS 4
- int ga_iBeamSpriteIndex[AMMOUNT_OF_COLORS + 1] = {-1, ...};
- char ga_sBeamSpritePath[AMMOUNT_OF_COLORS + 1][256] = {"materials/sprites/bomb_planted_ring.vmt", "materials/sprites/bomb_planted_ring_blue.vmt", "materials/sprites/bomb_planted_ring_yellow.vmt", "materials/sprites/bomb_planted_ring_green.vmt", ""};
- int g_iHaloSpriteIndex = -1;
- int g_iBeaconValidation = 1;
- int ga_iPreference[MAXPLAYERS + 1] = {0, ...};
- bool g_bBeaconOn = false;
- bool g_bLateLoad = false;
- bool ga_bLoaded[MAXPLAYERS + 1] = {false, ...};
- char g_sFilePath[255];
- char ga_sSteamID[MAXPLAYERS + 1][64];
- Handle g_hDatabase = null;
- ConVar gc_bPluginEnabled;
- ConVar gc_bTagEnabled;
- ConVar gc_iMinimumBeacon;
- ConVar gc_bPluginColor;
- ConVar gc_fBeaconRadius;
- ConVar gc_fBeaconWidth;
- ConVar gc_fBeaconTimelimit;
- ConVar gc_bWarnPlayers;
- ConVar gc_sSoundPath;
- int ga_iRedColor[4] = {255, 75, 75, 255};
- public Plugin myinfo =
- {
- name = "Hunger Games Beacon",
- author = "Headline",
- description = "Beacons players designed for Hunger Games",
- version = PLUGIN_VERSION,
- url = "http://michaelwflaherty.com"
- };
- public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int err_max)
- {
- g_bLateLoad = bLate;
- return APLRes_Success;
- }
- public void OnPluginStart()
- {
- AutoExecConfig_SetFile("sm_beacon");
- AutoExecConfig_SetCreateFile(true);
- AutoExecConfig_CreateConVar("beacon_version", PLUGIN_VERSION, "Headline's Beacon Plugin: Version", FCVAR_PLUGIN|FCVAR_NOTIFY);
- gc_bPluginEnabled = AutoExecConfig_CreateConVar("sm_beacon_enabled", "1", "Enables and disables the beacon plugin", FCVAR_NOTIFY, true, 0.0, true, 1.0);
- gc_bTagEnabled = AutoExecConfig_CreateConVar("sm_tag_enabled", "0", "Allow \"Headline\" to be added to the server tags?", FCVAR_NOTIFY, true, 0.0, true, 1.0);
- gc_iMinimumBeacon = AutoExecConfig_CreateConVar("sm_players_for_beacon", "2", "Sets the ammount of players for when the beacon should start", FCVAR_NOTIFY, true, 0.0, true, 32.0);
- gc_bPluginColor = AutoExecConfig_CreateConVar("sm_beacon_color", "1", "Enables and disables the beacon plugin's chat colors", FCVAR_NOTIFY, true, 0.0, true, 1.0);
- gc_fBeaconRadius = AutoExecConfig_CreateConVar("sm_beacon_radius", "750", "Sets the radius for the beacon's rings.", FCVAR_NOTIFY, true, 50.0, true, 1500.0);
- gc_fBeaconWidth = AutoExecConfig_CreateConVar("sm_beacon_width", "10", "Sets the thickness for the beacon's rings.", FCVAR_NOTIFY, true, 10.0, true, 30.0);
- gc_fBeaconTimelimit = AutoExecConfig_CreateConVar("sm_beacon_timelimit", "0", "Sets the amount of time (in seconds) until the beacon gets manually turned on (set to 0 to disable)", FCVAR_NOTIFY, true, 0.0, true, 600.0);
- gc_bWarnPlayers = AutoExecConfig_CreateConVar("sm_warn_players", "1", "If it is = 1, players will be warned to not delay the round when beacons start", FCVAR_NOTIFY, true, 0.0, true, 1.0);
- gc_sSoundPath = AutoExecConfig_CreateConVar("sm_beacon_soundpath", "", "Path to use your own sound clip. RELATIVE TO THE SOUNDS FOLDER \n VALID ENTRY \"beacon.mp3\"\n INVALID ENTRY: \"sound\beacon.mp3\"", FCVAR_NOTIFY, true, 0.0, true, 1.0);
- AutoExecConfig_ExecuteFile();
- AutoExecConfig_CleanFile();
- HookEvent("player_death", Event_PlayerDeath);
- HookEvent("round_end", Event_RoundEnd);
- HookEvent("round_start", Event_RoundStart);
- RegAdminCmd("sm_beaconall", Command_BeaconAll, ADMFLAG_GENERIC, "Toggles beacon on all players");
- RegAdminCmd("sm_stopbeacon", Command_StopBeacon, ADMFLAG_GENERIC, "Toggles beacon on all players");
- RegAdminCmd("sm_reloadsound", Command_Reload, ADMFLAG_CONFIG, "Refreshes the sounds");
- RegConsoleCmd("sm_beaconcolor", Command_BeaconColor, "A command to change the client's preferred beacon color");
- gc_sSoundPath.GetString(g_sFilePath, sizeof(g_sFilePath));
- if (g_bLateLoad)
- {
- OnMapStart();
- OnConfigsExecuted();
- }
- }
- public void OnMapStart()
- {
- gc_sSoundPath.GetString(g_sFilePath, sizeof(g_sFilePath));
- if (StrEqual(g_sFilePath, ""))
- {
- PrecacheSound(SOUND_BLIP, true);
- }
- else
- {
- char sBuffer[225];
- Format(sBuffer, sizeof(sBuffer), "sound/%s", g_sFilePath);
- PrecacheSoundAny(g_sFilePath);
- AddFileToDownloadsTable(sBuffer);
- }
- for (int i = 0; i < AMMOUNT_OF_COLORS; i++)
- {
- ga_iBeamSpriteIndex[i] = PrecacheModel(ga_sBeamSpritePath[i]);
- }
- g_iHaloSpriteIndex = PrecacheModel("materials/sprites/halo.vtf");
- g_iBeaconValidation = 1;
- }
- public void OnClientConnected(int client)
- {
- ga_bLoaded[client] = false;
- ga_iPreference[client] = 0;
- ga_sSteamID[client] = "";
- }
- public void OnClientDisconnect(int client)
- {
- if(ga_bLoaded[client] && !StrEqual(ga_sSteamID[client], "", false))
- {
- char sQuery[300];
- Format(sQuery, sizeof(sQuery), "UPDATE hungergamesbeacon SET preference=%i WHERE steamid=\"%s\"", ga_iPreference[client], ga_sSteamID[client]);
- SQL_TQuery(g_hDatabase, SQLCallback_Void, sQuery, 2);
- }
- ga_bLoaded[client] = false;
- ga_iPreference[client] = 0;
- ga_sSteamID[client] = "";
- }
- public void OnConfigsExecuted()
- {
- if(g_hDatabase == INVALID_HANDLE)
- {
- SetDBHandle();
- }
- if(g_bLateLoad)
- {
- for (int i = 1; i <= MaxClients; i++)
- {
- if(IsValidClient(i))
- {
- GetClientAuthId(i, AuthId_Steam2, ga_sSteamID[i], sizeof(ga_sSteamID[]));
- if (StrContains(ga_sSteamID[i], "STEAM_", true) != -1)
- {
- LoadSQL(i);
- }
- else
- {
- CreateTimer(10.0, RefreshSteamID, GetClientUserId(i), TIMER_FLAG_NO_MAPCHANGE);
- }
- }
- }
- }
- if (gc_bTagEnabled.BoolValue)
- {
- ConVar hTags = FindConVar("sv_tags");
- char sTags[128];
- hTags.GetString(sTags, sizeof(sTags));
- if (StrContains(sTags, "headline", false) == -1)
- {
- StrCat(sTags, sizeof(sTags), ", Headline");
- hTags.SetString(sTags);
- }
- }
- }
- public Action RefreshSteamID(Handle hTimer, int iUserID)
- {
- int client = GetClientOfUserId(iUserID);
- if(!IsValidClient(client))
- {
- return;
- }
- GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
- if(StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //still invalid - retry again
- {
- CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
- }
- else
- {
- LoadSQL(client);
- }
- }
- public void OnAutoConfigsBuffered()
- {
- SetDBHandle();
- }
- public void OnClientDisconnected(int client)
- {
- if (!gc_bPluginEnabled.BoolValue)
- {
- return;
- }
- if(GetPlayerCount() == gc_iMinimumBeacon.IntValue)
- {
- g_iBeaconValidation++;
- CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- }
- }
- public Action Event_PlayerDeath(Handle hEvent, const char[] sName, bool bDontBroadcast)
- {
- if (!gc_bPluginEnabled.BoolValue)
- {
- return Plugin_Continue;
- }
- if(GetPlayerCount() <= gc_iMinimumBeacon.IntValue)
- {
- if (gc_bWarnPlayers.BoolValue)
- {
- if (!gc_bPluginColor.BoolValue)
- {
- PrintToChatAll("Reminder! Teaming while the beacons are on is prohibited!!!");
- }
- else
- {
- CPrintToChatAll("Reminder! Teaming while the beacons are on is {PINK}prohibited!!!");
- }
- }
- g_iBeaconValidation++;
- CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- }
- return Plugin_Continue;
- }
- public Action Event_RoundStart(Handle hEvent, const char[] sName, bool bDontBroadcast)
- {
- if (!gc_bPluginEnabled.BoolValue)
- {
- return Plugin_Continue;
- }
- g_iBeaconValidation++;
- if (gc_fBeaconTimelimit.FloatValue <= 0.0)
- {
- return Plugin_Continue;
- }
- g_bBeaconOn = false;
- CreateTimer(gc_fBeaconTimelimit.FloatValue, beacon_all_timelimit, g_iBeaconValidation, TIMER_FLAG_NO_MAPCHANGE);
- return Plugin_Continue;
- }
- public Action beacon_all_timelimit(Handle hTimer, any iValidation)
- {
- if(g_iBeaconValidation == iValidation)
- {
- g_iBeaconValidation++;
- CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- }
- }
- public Action Event_RoundEnd(Handle hEvent, const char[] sName, bool bDontBroadcast)
- {
- if (!gc_bPluginEnabled.BoolValue)
- {
- return Plugin_Continue;
- }
- g_bBeaconOn = false;
- g_iBeaconValidation++;
- return Plugin_Continue;
- }
- public Action Command_Reload(int client, int iArgs)
- {
- if (iArgs != 0)
- {
- ReplyToCommand(client, "[SM] Usage : sm_reloadsound");
- return Plugin_Handled;
- }
- gc_sSoundPath.GetString(g_sFilePath, sizeof(g_sFilePath));
- return Plugin_Handled;
- }
- public Action Command_BeaconColor(int client, int args)
- {
- if (!IsValidClient(client))
- {
- ReplyToCommand(client, "[SM] You must be ingame to use this command!");
- return Plugin_Handled;
- }
- if (args != 0)
- {
- ReplyToCommand(client, "[SM] Usage : sm_beaconcolor");
- return Plugin_Handled;
- }
- OpenBeaconMenu(client);
- return Plugin_Handled;
- }
- public void OpenBeaconMenu(int client)
- {
- Menu MainMenu = new Menu(MainMenu_CallBack, MenuAction_Select | MenuAction_End);
- MainMenu.SetTitle("Beacon Preference Menu :");
- MainMenu.AddItem("red", "Red", (ga_iPreference[client] == 0)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
- MainMenu.AddItem("blue", "Blue", (ga_iPreference[client] == 1)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
- MainMenu.AddItem("yellow", "Yellow", (ga_iPreference[client] == 2)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
- MainMenu.AddItem("green", "Green", (ga_iPreference[client] == 3)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
- DisplayMenu(MainMenu, client, MENU_TIME_FOREVER);
- }
- public int MainMenu_CallBack(Menu MainMenu, MenuAction action, int param1, int param2)
- {
- switch (action)
- {
- case MenuAction_Select:
- {
- char item[64];
- GetMenuItem(MainMenu, param2, item, sizeof(item));
- if (StrEqual(item, "red"))
- {
- ga_iPreference[param1] = 0;
- OpenBeaconMenu(param1);
- }
- else if (StrEqual(item, "blue"))
- {
- ga_iPreference[param1] = 1;
- OpenBeaconMenu(param1);
- }
- else if (StrEqual(item, "yellow"))
- {
- ga_iPreference[param1] = 2;
- OpenBeaconMenu(param1);
- }
- else if (StrEqual(item, "green"))
- {
- ga_iPreference[param1] = 3;
- OpenBeaconMenu(param1);
- }
- }
- case MenuAction_End:
- {
- CloseHandle(MainMenu);
- }
- }
- }
- public Action Command_StopBeacon(int client, int iArgs)
- {
- if (iArgs != 0)
- {
- ReplyToCommand(client, "[SM] Usage : sm_stopbeacon");
- }
- if (!gc_bPluginEnabled.BoolValue)
- {
- ReplyToCommand(client, "Hunger Games Beacon is Disabled");
- return Plugin_Handled;
- }
- g_iBeaconValidation++;
- g_bBeaconOn = false;
- if (!gc_bPluginColor.BoolValue)
- {
- PrintToChatAll("[SM] %N toggled beacon OFF", client);
- }
- else
- {
- CPrintToChatAll("[SM] {PINK}%N {NORMAL}toggled beacon {PINK}OFF", client);
- }
- return Plugin_Handled;
- }
- public Action Command_BeaconAll(int client, int iArgs)
- {
- if (iArgs != 0)
- {
- ReplyToCommand(client, "[SM] Usage : sm_beaconall");
- }
- if (!gc_bPluginEnabled.BoolValue)
- {
- ReplyToCommand(client, "Hunger Games Beacon is Disabled");
- return Plugin_Handled;
- }
- if (!gc_bPluginColor.BoolValue)
- {
- PrintToChatAll("[SM] %N toggled beacon ON", client);
- }
- else
- {
- CPrintToChatAll("[SM] {PINK}%N {NORMAL}toggled beacon {PINK}ON", client);
- }
- if (g_bBeaconOn)
- {
- g_iBeaconValidation++;
- if (!gc_bPluginColor.BoolValue)
- {
- PrintToChatAll("[SM] %N toggled beacon OFF", client);
- }
- else
- {
- CPrintToChatAll("[SM] {PINK}%N {NORMAL}toggled beacon {PINK}OFF", client);
- }
- }
- g_bBeaconOn = true;
- g_iBeaconValidation++;
- CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- return Plugin_Handled;
- }
- public Action BeaconAll_Callback(Handle hTimer, any iValidation)
- {
- if(iValidation != g_iBeaconValidation)
- {
- return Plugin_Stop;
- }
- for(int i = 1; i <= MaxClients; i++)
- {
- if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) >= 2)
- {
- float a_fOrigin[3];
- GetClientAbsOrigin(i, a_fOrigin);
- a_fOrigin[2] += 10;
- for(int j = 1; j <= MaxClients; j++)
- {
- float b_fOrigin[3];
- GetClientAbsOrigin(j, b_fOrigin);
- b_fOrigin[2] += 10;
- switch (ga_iPreference[i])
- {
- case 0:
- {
- TE_SetupBeamRingPoint(b_fOrigin, 10.0, gc_fBeaconRadius.FloatValue, ga_iBeamSpriteIndex[0], g_iHaloSpriteIndex, 0, 10, 0.6, gc_fBeaconWidth.FloatValue, 0.5, ga_iRedColor, 5, 0);
- }
- case 1:
- {
- TE_SetupBeamRingPoint(b_fOrigin, 10.0, gc_fBeaconRadius.FloatValue, ga_iBeamSpriteIndex[1], g_iHaloSpriteIndex, 0, 10, 0.6, gc_fBeaconWidth.FloatValue, 0.5, ga_iRedColor, 5, 0);
- }
- case 2:
- {
- TE_SetupBeamRingPoint(b_fOrigin, 10.0, gc_fBeaconRadius.FloatValue, ga_iBeamSpriteIndex[2], g_iHaloSpriteIndex, 0, 10, 0.6, gc_fBeaconWidth.FloatValue, 0.5, ga_iRedColor, 5, 0);
- }
- case 3:
- {
- TE_SetupBeamRingPoint(b_fOrigin, 10.0, gc_fBeaconRadius.FloatValue, ga_iBeamSpriteIndex[3], g_iHaloSpriteIndex, 0, 10, 0.6, gc_fBeaconWidth.FloatValue, 0.5, ga_iRedColor, 5, 0);
- }
- }
- TE_SendToClient(i);
- GetClientEyePosition(i, b_fOrigin);
- if (!StrEqual(g_sFilePath, ""))
- {
- EmitAmbientSoundAny(g_sFilePath, a_fOrigin, i, SNDLEVEL_RAIDSIREN);
- }
- else
- {
- EmitAmbientSound(SOUND_BLIP, a_fOrigin, i, SNDLEVEL_RAIDSIREN);
- }
- }
- }
- }
- return Plugin_Continue;
- }
- bool IsValidClient(int iClient)
- {
- if(iClient < 1 || iClient > MaxClients || !IsClientConnected(iClient) || IsClientInKickQueue(iClient) || IsClientSourceTV(iClient))
- {
- return false;
- }
- else
- {
- return IsClientInGame(iClient);
- }
- }
- stock int GetPlayerCount()
- {
- int iPlayers;
- for (int i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) >= 2)
- {
- iPlayers++;
- }
- }
- return iPlayers;
- }
- stock void SetDBHandle()
- {
- if(g_hDatabase == INVALID_HANDLE)
- {
- SQL_TConnect(SQLCallback_Connect, "hungergamesbeacon");
- }
- }
- public void SQLCallback_Connect(Handle hOwner, Handle hHndl, const char[] sError, any data)
- {
- if(hHndl == INVALID_HANDLE)
- {
- SetFailState("Error connecting to database. %s", sError);
- }
- else
- {
- g_hDatabase = hHndl;
- SQL_TQuery(g_hDatabase, SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `toghgcredits` ( `id` int(20) NOT NULL AUTO_INCREMENT, `steamid` varchar(32) NOT NULL, `preference` int(20) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=latin1 AUTO_INCREMENT=1", 0);
- }
- }
- public void SQLCallback_Void(Handle hOwner, Handle hHndl, const char[] sError, int iData)
- {
- if(hHndl == INVALID_HANDLE)
- {
- SetFailState("Error (%i): %s", iData, sError);
- }
- }
- public void LoadSQL(int client)
- {
- if(!IsValidClient(client))
- {
- return;
- }
- GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
- if(StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //if ID is invalid
- {
- CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
- }
- if(g_hDatabase == INVALID_HANDLE) //connect not loaded - retry to give it time
- {
- CreateTimer(1.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
- }
- else
- {
- char sQuery[300];
- Format(sQuery, sizeof(sQuery), "SELECT `preference` FROM hungergamesbeacon WHERE steamid=\"%s\"", ga_sSteamID[client]);
- SQL_TQuery(g_hDatabase, SQLCallback_CheckSQL, sQuery, GetClientUserId(client));
- }
- }
- public Action RepeatCheckRank(Handle hTimer, int iUserID)
- {
- int client = GetClientOfUserId(iUserID);
- LoadSQL(client);
- }
- public void SQLCallback_CheckSQL(Handle hOwner, Handle hHndl, const char[] sError, int iUserID)
- {
- if(hHndl == INVALID_HANDLE)
- {
- SetFailState("Error: %s", sError);
- }
- int client = GetClientOfUserId(iUserID);
- if (!IsValidClient(client))
- {
- return;
- }
- else
- {
- if (SQL_GetRowCount(hHndl) == 1)
- {
- SQL_FetchRow(hHndl);
- ga_iPreference[client] = SQL_FetchInt(hHndl, 0);
- ga_bLoaded[client] = true;
- }
- else
- {
- if(g_hDatabase == INVALID_HANDLE)
- {
- CreateTimer(2.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
- }
- else //new player
- {
- char sQuery[300];
- Format(sQuery, sizeof(sQuery), "INSERT INTO hungergamesbeacon (steamid, preference) VALUES(\"%s\", %i)", ga_sSteamID[client], ga_iPreference[client]);
- SQL_TQuery(g_hDatabase, SQLCallback_Void, sQuery, 3);
- ga_bLoaded[client] = true;
- }
- }
- }
- }
- /* Changelog
- 1.0 - Initial Release
- 1.1 - Added CVAR sm_players_for_beacon
- 1.2 - ThatOneGuy helped fix the issue where sm_beaconall would cause the beacons to happen twice.
- 1.3 - Created a warning for when beacons come on and a CVAR to go with it. Also added a sv_tags with my name in it so I can see servers using this!
- 1.4 - Updated plugin to 1.7 transitional syntax & Added AutoExecConfigCaching & Made my Tagging system OFF by default xD
- 1.4.1 - Removed Caching because it is not necessary, added my URL, and then applied ddhoward's suggestions
- 1.4.2 - Fixed an issue where beacons wouldnt turn on unless the threshold was met exactly. (Changed == to <=)
- 1.4.3 - Retabbed and fixed bug with my sv_tags thing
- 1.5 - Added a system so you can use your own custom sounds
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement