Advertisement
Guest User

Untitled

a guest
May 29th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.22 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <autoexecconfig>
  4. #include <csgocolors>
  5. #include <emitsoundany>
  6.  
  7. #pragma semicolon 1
  8.  
  9. #pragma newdecls required
  10.  
  11. #define SOUND_BLIP "buttons/blip1.wav"
  12. #define PLUGIN_VERSION "1.6"
  13. #define AMMOUNT_OF_COLORS 4
  14.  
  15. int ga_iBeamSpriteIndex[AMMOUNT_OF_COLORS + 1] = {-1, ...};
  16. 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", ""};
  17.  
  18. int g_iHaloSpriteIndex = -1;
  19. int g_iBeaconValidation = 1;
  20. int ga_iPreference[MAXPLAYERS + 1] = {0, ...};
  21.  
  22. bool g_bBeaconOn = false;
  23. bool g_bLateLoad = false;
  24. bool ga_bLoaded[MAXPLAYERS + 1] = {false, ...};
  25.  
  26. char g_sFilePath[255];
  27. char ga_sSteamID[MAXPLAYERS + 1][64];
  28.  
  29. Handle g_hDatabase = null;
  30.  
  31. ConVar gc_bPluginEnabled;
  32. ConVar gc_bTagEnabled;
  33. ConVar gc_iMinimumBeacon;
  34. ConVar gc_bPluginColor;
  35. ConVar gc_fBeaconRadius;
  36. ConVar gc_fBeaconWidth;
  37. ConVar gc_fBeaconTimelimit;
  38. ConVar gc_bWarnPlayers;
  39. ConVar gc_sSoundPath;
  40.  
  41. int ga_iRedColor[4] = {255, 75, 75, 255};
  42.  
  43. public Plugin myinfo =
  44. {
  45. name = "Hunger Games Beacon",
  46. author = "Headline",
  47. description = "Beacons players designed for Hunger Games",
  48. version = PLUGIN_VERSION,
  49. url = "http://michaelwflaherty.com"
  50. };
  51.  
  52. public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int err_max)
  53. {
  54. g_bLateLoad = bLate;
  55.  
  56. return APLRes_Success;
  57. }
  58.  
  59. public void OnPluginStart()
  60. {
  61. AutoExecConfig_SetFile("sm_beacon");
  62. AutoExecConfig_SetCreateFile(true);
  63.  
  64. AutoExecConfig_CreateConVar("beacon_version", PLUGIN_VERSION, "Headline's Beacon Plugin: Version", FCVAR_PLUGIN|FCVAR_NOTIFY);
  65.  
  66. gc_bPluginEnabled = AutoExecConfig_CreateConVar("sm_beacon_enabled", "1", "Enables and disables the beacon plugin", FCVAR_NOTIFY, true, 0.0, true, 1.0);
  67.  
  68. 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);
  69.  
  70. 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);
  71.  
  72. 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);
  73.  
  74. gc_fBeaconRadius = AutoExecConfig_CreateConVar("sm_beacon_radius", "750", "Sets the radius for the beacon's rings.", FCVAR_NOTIFY, true, 50.0, true, 1500.0);
  75.  
  76. gc_fBeaconWidth = AutoExecConfig_CreateConVar("sm_beacon_width", "10", "Sets the thickness for the beacon's rings.", FCVAR_NOTIFY, true, 10.0, true, 30.0);
  77.  
  78. 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);
  79.  
  80. 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);
  81.  
  82. 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);
  83.  
  84. AutoExecConfig_ExecuteFile();
  85. AutoExecConfig_CleanFile();
  86.  
  87. HookEvent("player_death", Event_PlayerDeath);
  88. HookEvent("round_end", Event_RoundEnd);
  89. HookEvent("round_start", Event_RoundStart);
  90.  
  91. RegAdminCmd("sm_beaconall", Command_BeaconAll, ADMFLAG_GENERIC, "Toggles beacon on all players");
  92. RegAdminCmd("sm_stopbeacon", Command_StopBeacon, ADMFLAG_GENERIC, "Toggles beacon on all players");
  93. RegAdminCmd("sm_reloadsound", Command_Reload, ADMFLAG_CONFIG, "Refreshes the sounds");
  94.  
  95. RegConsoleCmd("sm_beaconcolor", Command_BeaconColor, "A command to change the client's preferred beacon color");
  96.  
  97. gc_sSoundPath.GetString(g_sFilePath, sizeof(g_sFilePath));
  98.  
  99. if (g_bLateLoad)
  100. {
  101. OnMapStart();
  102. OnConfigsExecuted();
  103. }
  104. }
  105.  
  106. public void OnMapStart()
  107. {
  108. gc_sSoundPath.GetString(g_sFilePath, sizeof(g_sFilePath));
  109. if (StrEqual(g_sFilePath, ""))
  110. {
  111. PrecacheSound(SOUND_BLIP, true);
  112. }
  113. else
  114. {
  115. char sBuffer[225];
  116. Format(sBuffer, sizeof(sBuffer), "sound/%s", g_sFilePath);
  117. PrecacheSoundAny(g_sFilePath);
  118. AddFileToDownloadsTable(sBuffer);
  119. }
  120. for (int i = 0; i < AMMOUNT_OF_COLORS; i++)
  121. {
  122. ga_iBeamSpriteIndex[i] = PrecacheModel(ga_sBeamSpritePath[i]);
  123. }
  124. g_iHaloSpriteIndex = PrecacheModel("materials/sprites/halo.vtf");
  125. g_iBeaconValidation = 1;
  126. }
  127.  
  128. public void OnClientConnected(int client)
  129. {
  130. ga_bLoaded[client] = false;
  131. ga_iPreference[client] = 0;
  132. ga_sSteamID[client] = "";
  133. }
  134.  
  135. public void OnClientDisconnect(int client)
  136. {
  137. if(ga_bLoaded[client] && !StrEqual(ga_sSteamID[client], "", false))
  138. {
  139. char sQuery[300];
  140. Format(sQuery, sizeof(sQuery), "UPDATE hungergamesbeacon SET preference=%i WHERE steamid=\"%s\"", ga_iPreference[client], ga_sSteamID[client]);
  141. SQL_TQuery(g_hDatabase, SQLCallback_Void, sQuery, 2);
  142. }
  143.  
  144. ga_bLoaded[client] = false;
  145. ga_iPreference[client] = 0;
  146. ga_sSteamID[client] = "";
  147. }
  148.  
  149. public void OnConfigsExecuted()
  150. {
  151. if(g_hDatabase == INVALID_HANDLE)
  152. {
  153. SetDBHandle();
  154. }
  155. if(g_bLateLoad)
  156. {
  157. for (int i = 1; i <= MaxClients; i++)
  158. {
  159. if(IsValidClient(i))
  160. {
  161. GetClientAuthId(i, AuthId_Steam2, ga_sSteamID[i], sizeof(ga_sSteamID[]));
  162.  
  163. if (StrContains(ga_sSteamID[i], "STEAM_", true) != -1)
  164. {
  165. LoadSQL(i);
  166. }
  167. else
  168. {
  169. CreateTimer(10.0, RefreshSteamID, GetClientUserId(i), TIMER_FLAG_NO_MAPCHANGE);
  170. }
  171. }
  172. }
  173. }
  174.  
  175. if (gc_bTagEnabled.BoolValue)
  176. {
  177. ConVar hTags = FindConVar("sv_tags");
  178. char sTags[128];
  179. hTags.GetString(sTags, sizeof(sTags));
  180. if (StrContains(sTags, "headline", false) == -1)
  181. {
  182. StrCat(sTags, sizeof(sTags), ", Headline");
  183. hTags.SetString(sTags);
  184. }
  185. }
  186. }
  187.  
  188. public Action RefreshSteamID(Handle hTimer, int iUserID)
  189. {
  190. int client = GetClientOfUserId(iUserID);
  191.  
  192. if(!IsValidClient(client))
  193. {
  194. return;
  195. }
  196.  
  197. GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
  198.  
  199.  
  200. if(StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //still invalid - retry again
  201. {
  202. CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
  203. }
  204. else
  205. {
  206. LoadSQL(client);
  207. }
  208. }
  209.  
  210. public void OnAutoConfigsBuffered()
  211. {
  212. SetDBHandle();
  213. }
  214.  
  215. public void OnClientDisconnected(int client)
  216. {
  217. if (!gc_bPluginEnabled.BoolValue)
  218. {
  219. return;
  220. }
  221.  
  222. if(GetPlayerCount() == gc_iMinimumBeacon.IntValue)
  223. {
  224. g_iBeaconValidation++;
  225. CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  226. }
  227. }
  228.  
  229. public Action Event_PlayerDeath(Handle hEvent, const char[] sName, bool bDontBroadcast)
  230. {
  231. if (!gc_bPluginEnabled.BoolValue)
  232. {
  233. return Plugin_Continue;
  234. }
  235. if(GetPlayerCount() <= gc_iMinimumBeacon.IntValue)
  236. {
  237. if (gc_bWarnPlayers.BoolValue)
  238. {
  239. if (!gc_bPluginColor.BoolValue)
  240. {
  241. PrintToChatAll("Reminder! Teaming while the beacons are on is prohibited!!!");
  242. }
  243. else
  244. {
  245. CPrintToChatAll("Reminder! Teaming while the beacons are on is {PINK}prohibited!!!");
  246. }
  247. }
  248. g_iBeaconValidation++;
  249. CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  250. }
  251. return Plugin_Continue;
  252. }
  253.  
  254. public Action Event_RoundStart(Handle hEvent, const char[] sName, bool bDontBroadcast)
  255. {
  256. if (!gc_bPluginEnabled.BoolValue)
  257. {
  258. return Plugin_Continue;
  259. }
  260. g_iBeaconValidation++;
  261. if (gc_fBeaconTimelimit.FloatValue <= 0.0)
  262. {
  263. return Plugin_Continue;
  264. }
  265. g_bBeaconOn = false;
  266. CreateTimer(gc_fBeaconTimelimit.FloatValue, beacon_all_timelimit, g_iBeaconValidation, TIMER_FLAG_NO_MAPCHANGE);
  267. return Plugin_Continue;
  268. }
  269.  
  270. public Action beacon_all_timelimit(Handle hTimer, any iValidation)
  271. {
  272. if(g_iBeaconValidation == iValidation)
  273. {
  274. g_iBeaconValidation++;
  275. CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  276. }
  277. }
  278.  
  279. public Action Event_RoundEnd(Handle hEvent, const char[] sName, bool bDontBroadcast)
  280. {
  281. if (!gc_bPluginEnabled.BoolValue)
  282. {
  283. return Plugin_Continue;
  284. }
  285. g_bBeaconOn = false;
  286. g_iBeaconValidation++;
  287. return Plugin_Continue;
  288. }
  289.  
  290. public Action Command_Reload(int client, int iArgs)
  291. {
  292. if (iArgs != 0)
  293. {
  294. ReplyToCommand(client, "[SM] Usage : sm_reloadsound");
  295. return Plugin_Handled;
  296. }
  297. gc_sSoundPath.GetString(g_sFilePath, sizeof(g_sFilePath));
  298. return Plugin_Handled;
  299. }
  300.  
  301. public Action Command_BeaconColor(int client, int args)
  302. {
  303. if (!IsValidClient(client))
  304. {
  305. ReplyToCommand(client, "[SM] You must be ingame to use this command!");
  306. return Plugin_Handled;
  307. }
  308. if (args != 0)
  309. {
  310. ReplyToCommand(client, "[SM] Usage : sm_beaconcolor");
  311. return Plugin_Handled;
  312. }
  313. OpenBeaconMenu(client);
  314. return Plugin_Handled;
  315. }
  316.  
  317. public void OpenBeaconMenu(int client)
  318. {
  319. Menu MainMenu = new Menu(MainMenu_CallBack, MenuAction_Select | MenuAction_End);
  320. MainMenu.SetTitle("Beacon Preference Menu :");
  321.  
  322. MainMenu.AddItem("red", "Red", (ga_iPreference[client] == 0)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
  323. MainMenu.AddItem("blue", "Blue", (ga_iPreference[client] == 1)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
  324. MainMenu.AddItem("yellow", "Yellow", (ga_iPreference[client] == 2)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
  325. MainMenu.AddItem("green", "Green", (ga_iPreference[client] == 3)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
  326.  
  327.  
  328. DisplayMenu(MainMenu, client, MENU_TIME_FOREVER);
  329. }
  330.  
  331. public int MainMenu_CallBack(Menu MainMenu, MenuAction action, int param1, int param2)
  332. {
  333. switch (action)
  334. {
  335. case MenuAction_Select:
  336. {
  337. char item[64];
  338. GetMenuItem(MainMenu, param2, item, sizeof(item));
  339.  
  340. if (StrEqual(item, "red"))
  341. {
  342. ga_iPreference[param1] = 0;
  343. OpenBeaconMenu(param1);
  344. }
  345. else if (StrEqual(item, "blue"))
  346. {
  347. ga_iPreference[param1] = 1;
  348. OpenBeaconMenu(param1);
  349. }
  350. else if (StrEqual(item, "yellow"))
  351. {
  352. ga_iPreference[param1] = 2;
  353. OpenBeaconMenu(param1);
  354. }
  355. else if (StrEqual(item, "green"))
  356. {
  357. ga_iPreference[param1] = 3;
  358. OpenBeaconMenu(param1);
  359. }
  360. }
  361. case MenuAction_End:
  362. {
  363. CloseHandle(MainMenu);
  364. }
  365. }
  366. }
  367.  
  368.  
  369. public Action Command_StopBeacon(int client, int iArgs)
  370. {
  371. if (iArgs != 0)
  372. {
  373. ReplyToCommand(client, "[SM] Usage : sm_stopbeacon");
  374. }
  375. if (!gc_bPluginEnabled.BoolValue)
  376. {
  377. ReplyToCommand(client, "Hunger Games Beacon is Disabled");
  378. return Plugin_Handled;
  379. }
  380. g_iBeaconValidation++;
  381. g_bBeaconOn = false;
  382. if (!gc_bPluginColor.BoolValue)
  383. {
  384. PrintToChatAll("[SM] %N toggled beacon OFF", client);
  385. }
  386. else
  387. {
  388. CPrintToChatAll("[SM] {PINK}%N {NORMAL}toggled beacon {PINK}OFF", client);
  389. }
  390. return Plugin_Handled;
  391. }
  392.  
  393. public Action Command_BeaconAll(int client, int iArgs)
  394. {
  395. if (iArgs != 0)
  396. {
  397. ReplyToCommand(client, "[SM] Usage : sm_beaconall");
  398. }
  399. if (!gc_bPluginEnabled.BoolValue)
  400. {
  401. ReplyToCommand(client, "Hunger Games Beacon is Disabled");
  402. return Plugin_Handled;
  403. }
  404. if (!gc_bPluginColor.BoolValue)
  405. {
  406. PrintToChatAll("[SM] %N toggled beacon ON", client);
  407. }
  408. else
  409. {
  410. CPrintToChatAll("[SM] {PINK}%N {NORMAL}toggled beacon {PINK}ON", client);
  411. }
  412. if (g_bBeaconOn)
  413. {
  414. g_iBeaconValidation++;
  415. if (!gc_bPluginColor.BoolValue)
  416. {
  417. PrintToChatAll("[SM] %N toggled beacon OFF", client);
  418. }
  419. else
  420. {
  421. CPrintToChatAll("[SM] {PINK}%N {NORMAL}toggled beacon {PINK}OFF", client);
  422. }
  423. }
  424. g_bBeaconOn = true;
  425. g_iBeaconValidation++;
  426. CreateTimer(1.0, BeaconAll_Callback, g_iBeaconValidation, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  427. return Plugin_Handled;
  428. }
  429.  
  430. public Action BeaconAll_Callback(Handle hTimer, any iValidation)
  431. {
  432. if(iValidation != g_iBeaconValidation)
  433. {
  434. return Plugin_Stop;
  435. }
  436. for(int i = 1; i <= MaxClients; i++)
  437. {
  438. if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) >= 2)
  439. {
  440. float a_fOrigin[3];
  441. GetClientAbsOrigin(i, a_fOrigin);
  442. a_fOrigin[2] += 10;
  443.  
  444. for(int j = 1; j <= MaxClients; j++)
  445. {
  446. float b_fOrigin[3];
  447. GetClientAbsOrigin(j, b_fOrigin);
  448. b_fOrigin[2] += 10;
  449. switch (ga_iPreference[i])
  450. {
  451. case 0:
  452. {
  453. 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);
  454. }
  455. case 1:
  456. {
  457. 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);
  458. }
  459. case 2:
  460. {
  461. 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);
  462. }
  463. case 3:
  464. {
  465. 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);
  466. }
  467. }
  468.  
  469. TE_SendToClient(i);
  470.  
  471. GetClientEyePosition(i, b_fOrigin);
  472. if (!StrEqual(g_sFilePath, ""))
  473. {
  474. EmitAmbientSoundAny(g_sFilePath, a_fOrigin, i, SNDLEVEL_RAIDSIREN);
  475. }
  476. else
  477. {
  478. EmitAmbientSound(SOUND_BLIP, a_fOrigin, i, SNDLEVEL_RAIDSIREN);
  479. }
  480. }
  481. }
  482. }
  483. return Plugin_Continue;
  484. }
  485.  
  486. bool IsValidClient(int iClient)
  487. {
  488. if(iClient < 1 || iClient > MaxClients || !IsClientConnected(iClient) || IsClientInKickQueue(iClient) || IsClientSourceTV(iClient))
  489. {
  490. return false;
  491. }
  492. else
  493. {
  494. return IsClientInGame(iClient);
  495. }
  496. }
  497.  
  498. stock int GetPlayerCount()
  499. {
  500. int iPlayers;
  501. for (int i = 1; i <= MaxClients; i++)
  502. {
  503. if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) >= 2)
  504. {
  505. iPlayers++;
  506. }
  507. }
  508. return iPlayers;
  509. }
  510.  
  511. stock void SetDBHandle()
  512. {
  513. if(g_hDatabase == INVALID_HANDLE)
  514. {
  515. SQL_TConnect(SQLCallback_Connect, "hungergamesbeacon");
  516. }
  517. }
  518.  
  519. public void SQLCallback_Connect(Handle hOwner, Handle hHndl, const char[] sError, any data)
  520. {
  521. if(hHndl == INVALID_HANDLE)
  522. {
  523. SetFailState("Error connecting to database. %s", sError);
  524. }
  525. else
  526. {
  527. g_hDatabase = hHndl;
  528. 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);
  529. }
  530. }
  531.  
  532. public void SQLCallback_Void(Handle hOwner, Handle hHndl, const char[] sError, int iData)
  533. {
  534. if(hHndl == INVALID_HANDLE)
  535. {
  536. SetFailState("Error (%i): %s", iData, sError);
  537. }
  538. }
  539.  
  540.  
  541. public void LoadSQL(int client)
  542. {
  543. if(!IsValidClient(client))
  544. {
  545. return;
  546. }
  547.  
  548. GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
  549.  
  550. if(StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //if ID is invalid
  551. {
  552. CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
  553. }
  554.  
  555. if(g_hDatabase == INVALID_HANDLE) //connect not loaded - retry to give it time
  556. {
  557. CreateTimer(1.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
  558. }
  559. else
  560. {
  561. char sQuery[300];
  562. Format(sQuery, sizeof(sQuery), "SELECT `preference` FROM hungergamesbeacon WHERE steamid=\"%s\"", ga_sSteamID[client]);
  563. SQL_TQuery(g_hDatabase, SQLCallback_CheckSQL, sQuery, GetClientUserId(client));
  564. }
  565. }
  566.  
  567. public Action RepeatCheckRank(Handle hTimer, int iUserID)
  568. {
  569. int client = GetClientOfUserId(iUserID);
  570. LoadSQL(client);
  571. }
  572.  
  573. public void SQLCallback_CheckSQL(Handle hOwner, Handle hHndl, const char[] sError, int iUserID)
  574. {
  575. if(hHndl == INVALID_HANDLE)
  576. {
  577. SetFailState("Error: %s", sError);
  578. }
  579.  
  580. int client = GetClientOfUserId(iUserID);
  581. if (!IsValidClient(client))
  582. {
  583. return;
  584. }
  585. else
  586. {
  587. if (SQL_GetRowCount(hHndl) == 1)
  588. {
  589. SQL_FetchRow(hHndl);
  590.  
  591. ga_iPreference[client] = SQL_FetchInt(hHndl, 0);
  592.  
  593. ga_bLoaded[client] = true;
  594. }
  595. else
  596. {
  597. if(g_hDatabase == INVALID_HANDLE)
  598. {
  599. CreateTimer(2.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
  600. }
  601. else //new player
  602. {
  603. char sQuery[300];
  604. Format(sQuery, sizeof(sQuery), "INSERT INTO hungergamesbeacon (steamid, preference) VALUES(\"%s\", %i)", ga_sSteamID[client], ga_iPreference[client]);
  605. SQL_TQuery(g_hDatabase, SQLCallback_Void, sQuery, 3);
  606. ga_bLoaded[client] = true;
  607. }
  608. }
  609. }
  610. }
  611.  
  612. /* Changelog
  613. 1.0 - Initial Release
  614. 1.1 - Added CVAR sm_players_for_beacon
  615. 1.2 - ThatOneGuy helped fix the issue where sm_beaconall would cause the beacons to happen twice.
  616. 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!
  617. 1.4 - Updated plugin to 1.7 transitional syntax & Added AutoExecConfigCaching & Made my Tagging system OFF by default xD
  618. 1.4.1 - Removed Caching because it is not necessary, added my URL, and then applied ddhoward's suggestions
  619. 1.4.2 - Fixed an issue where beacons wouldnt turn on unless the threshold was met exactly. (Changed == to <=)
  620. 1.4.3 - Retabbed and fixed bug with my sv_tags thing
  621. 1.5 - Added a system so you can use your own custom sounds
  622. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement