Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.27 KB | None | 0 0
  1. // ==============================================================================================================================
  2. // >>> GLOBAL INCLUDES
  3. // ==============================================================================================================================
  4. #pragma semicolon 1
  5. #include <sourcemod>
  6. #include <sdktools>
  7. #include <sdkhooks>
  8. #include <clientprefs>
  9.  
  10. #include <emitsoundany>
  11. #include <multicolors>
  12. #include <store>
  13.  
  14. // #define DRYRUN
  15.  
  16. // ==============================================================================================================================
  17. // >>> PLUGIN INFORMATION
  18. // ==============================================================================================================================
  19. #define PLUGIN_VERSION "1.3.3"
  20. public Plugin myinfo =
  21. {
  22. name = "[Shop] Slots",
  23. author = "AlexTheRegent",
  24. description = "",
  25. version = PLUGIN_VERSION,
  26. url = ""
  27. }
  28.  
  29. // ==============================================================================================================================
  30. // >>> DEFINES
  31. // ==============================================================================================================================
  32. #pragma newdecls required
  33. #define MPS MAXPLAYERS+1
  34. #define PMP PLATFORM_MAX_PATH
  35. #define MTF MENU_TIME_FOREVER
  36. #define CID(%0) GetClientOfUserId(%0)
  37. #define UID(%0) GetClientUserId(%0)
  38. #define SZF(%0) %0, sizeof(%0)
  39. #define LC(%0) for (int %0 = 1; %0 <= MaxClients; ++%0) if ( IsClientInGame(%0) )
  40.  
  41. #define MAXLENGTH_BETS 256
  42. #define MAXLENGTH_BET 8
  43. #define MAXLENGTH_REELS 32
  44. #define MAXLENGTH_REEL 4
  45.  
  46. // ==============================================================================================================================
  47. // >>> CONSOLE VARIABLES
  48. // ==============================================================================================================================
  49. ConVar g_cvarBets;
  50. ConVar g_cvarSymbols;
  51. ConVar g_cvarRates;
  52. ConVar g_cvarMultipliers;
  53. ConVar g_cvarSoundSpin;
  54. ConVar g_cvarSoundSlot;
  55. ConVar g_cvarLogging;
  56. ConVar g_cvarShowCredits;
  57. ConVar g_cvarCreditsPool;
  58. ConVar g_cvarJackpotCombination;
  59. ConVar g_cvarJackpotMuptiplier;
  60. ConVar g_cvarJackpotWinMessage;
  61. ConVar g_cvarJackpotAdvertisement;
  62. ConVar g_cvarJackpotChance;
  63. ConVar g_cvarJackpotLastWinner;
  64. ConVar g_cvarSpinCooldown;
  65.  
  66. // ==============================================================================================================================
  67. // >>> GLOBAL VARIABLES
  68. // ==============================================================================================================================
  69. KeyValues g_data;
  70.  
  71. Menu g_mainMenu;
  72. Menu g_betsMenu;
  73. Menu g_infoMenu;
  74.  
  75. Handle g_timer[MPS];
  76. Handle g_nextSpinTimeCookie;
  77.  
  78. float g_multipliers[MAXLENGTH_REELS/MAXLENGTH_REEL];
  79.  
  80. char g_reel[MAXLENGTH_REELS/MAXLENGTH_REEL][MAXLENGTH_REEL];
  81. char g_soundSpin[PMP];
  82. char g_soundSlot[PMP];
  83. char g_slotLine[128];
  84. char g_logFile[PMP];
  85. char g_dataFilePath[PMP];
  86.  
  87. int g_combination[MPS][MAXLENGTH_REELS/MAXLENGTH_REEL];
  88. int g_step[MPS][MAXLENGTH_REELS/MAXLENGTH_REEL];
  89. int g_reelLength;
  90. int g_rates[MAXLENGTH_REELS/MAXLENGTH_REEL];
  91. int g_bet[MPS];
  92. int g_creditsPool;
  93. int g_jackpotCombination[MAXLENGTH_REELS/MAXLENGTH_REEL];
  94. int g_jackpotPool;
  95. int g_currentRound;
  96. int g_nextSpinTime[MPS];
  97.  
  98. // ==============================================================================================================================
  99. // >>> LOCAL INCLUDES
  100. // ==============================================================================================================================
  101.  
  102.  
  103. // ==============================================================================================================================
  104. // >>> FORWARDS
  105. // ==============================================================================================================================
  106. public void OnPluginStart()
  107. {
  108. LoadTranslations("slots.phrases.txt");
  109.  
  110. RegConsoleCmd("sm_slots", Command_Slots);
  111. RegAdminCmd("sm_slots_pool", Command_SlotsPool, ADMFLAG_ROOT);
  112. RegAdminCmd("sm_slots_jackpot", Command_SlotsJackpot, ADMFLAG_ROOT);
  113.  
  114. g_mainMenu = new Menu(Handler_MainMenu, MenuAction_DisplayItem|MenuAction_Display);
  115. g_mainMenu.AddItem("play", "play");
  116. g_mainMenu.AddItem("info", "info");
  117.  
  118. if ( GetEngineVersion() == Engine_CSGO ) {
  119. strcopy(SZF(g_slotLine), "█ %s|%s|%s|%s|%s █");
  120. }
  121. else {
  122. strcopy(SZF(g_slotLine), "█ %s|%s|%s|%s|%s █");
  123. }
  124.  
  125. g_cvarBets = CreateConVar("sm_slots_bets", "100 200 500", "available bets, separated by space");
  126. g_cvarSymbols = CreateConVar("sm_slots_symbols", "☠ ☀ ✪ ❤ 〠 ♛", "symbols, separated by space");
  127. g_cvarRates = CreateConVar("sm_slots_rates", "1 1 1 1 1 1", "rates of symbols, separated by space");
  128. g_cvarMultipliers = CreateConVar("sm_slots_multipliers", "-1.0 0.1 0.2 0.3 0.4 0.5", "multipliers of symbols, separated by space");
  129. g_cvarSoundSpin = CreateConVar("sm_slots_sound_spin", "ui/csgo_ui_crate_item_scroll.wav", "sound of wheel spin");
  130. g_cvarSoundSlot = CreateConVar("sm_slots_sound_slot", "ui/item_drop1_common.wav", "sound of wheel spin stop");
  131. g_cvarLogging = CreateConVar("sm_slots_logging", "1", "write logs (1) or not (0)");
  132. g_cvarShowCredits = CreateConVar("sm_slots_show_credits", "1", "show client credits in title (1) or not (0)");
  133. g_cvarCreditsPool = CreateConVar("sm_slots_credits_pool", "0", "enable (1) or disable (0) credits pool");
  134. g_cvarJackpotCombination = CreateConVar("sm_slots_jackpot_combination", "☠ ☠ ☠ ☠ ☠", "jackpot combination (empty to disable)");
  135. g_cvarJackpotMuptiplier = CreateConVar("sm_slots_jackpot_multiplier", "0.1", "how much of clients bets goes to jackpot pool");
  136. g_cvarJackpotWinMessage = CreateConVar("sm_slots_jackpot_win_message", "1", "show message on jackpot to all players (1) or only winner (0)");
  137. g_cvarJackpotAdvertisement = CreateConVar("sm_slots_jackpot_advertisement", "1", "how often in round to display current jackpot value");
  138. g_cvarJackpotChance = CreateConVar("sm_slots_jackpot_chance", "0.01", "jackpot chance in percent. 0 to disable jackpot, -1 to let plugin handle chance");
  139. g_cvarJackpotLastWinner = CreateConVar("sm_slots_jackpot_last_winner", "1", "show (1) or not (0) with current jackpot value information about last jackpot winner: name/amount/date");
  140. g_cvarSpinCooldown = CreateConVar("sm_slots_spin_cooldown", "0", "how often in seconds client can play slot machine");
  141. AutoExecConfig();
  142.  
  143. HookEvent("round_start", Ev_RoundStart);
  144.  
  145. g_nextSpinTimeCookie = RegClientCookie("sm_slots_last_spin_time", "last client spin time", CookieAccess_Protected);
  146.  
  147. LoadData();
  148.  
  149. //#if defined DRYRUN
  150. //#else
  151. //#endif
  152. }
  153.  
  154. public int OnDisplay(int client, char[] buffer, int maxlength)
  155. {
  156. FormatEx(buffer, maxlength, "%T", "slots", client);
  157. }
  158.  
  159. public bool OnClick(int client)
  160. {
  161. Command_Slots(client, 0);
  162. return true;
  163. }
  164.  
  165. void LoadData()
  166. {
  167. BuildPath(Path_SM, SZF(g_dataFilePath), "data/slots.txt");
  168.  
  169. g_data = new KeyValues("slots");
  170. if ( !g_data.ImportFromFile(g_dataFilePath) ) {
  171. LogError("File '%s' not found or empty/broken", g_dataFilePath);
  172. return;
  173. }
  174.  
  175. g_creditsPool = g_data.GetNum("credits_pool", 0);
  176. g_jackpotPool = g_data.GetNum("jackpot_pool", 0);
  177. }
  178.  
  179. //public void OnMapStart(){}
  180.  
  181. public void OnConfigsExecuted()
  182. {
  183. g_cvarSoundSpin.GetString(SZF(g_soundSpin));
  184. PrecacheSoundAny(g_soundSpin);
  185. g_cvarSoundSlot.GetString(SZF(g_soundSlot));
  186. PrecacheSoundAny(g_soundSlot);
  187.  
  188. char buffer[256];
  189. FormatEx(SZF(buffer), "sound/%s", g_soundSpin);
  190. AddFileToDownloadsTable(buffer);
  191. FormatEx(SZF(buffer), "sound/%s", g_soundSlot);
  192. AddFileToDownloadsTable(buffer);
  193.  
  194. g_betsMenu = new Menu(Handler_BetsMenu, MenuAction_DisplayItem|MenuAction_Display);
  195. g_betsMenu.ExitBackButton = true;
  196.  
  197. char bets[MAXLENGTH_BETS], bet[MAXLENGTH_BETS/MAXLENGTH_BET][MAXLENGTH_BET];
  198. g_cvarBets.GetString(SZF(bets));
  199. int bets_count = ExplodeString(bets, " ", bet, sizeof(bet), sizeof(bet[]));
  200. for ( int i = 0; i < bets_count; ++i ) {
  201. g_betsMenu.AddItem(bet[i], "");
  202. }
  203.  
  204. char reel[MAXLENGTH_REELS];
  205. g_cvarSymbols.GetString(SZF(reel));
  206. g_reelLength = ExplodeString(reel, " ", g_reel, sizeof(g_reel), sizeof(g_reel[]));
  207.  
  208. char rates[256], rate[MAXLENGTH_REELS/MAXLENGTH_REEL][8];
  209. g_cvarRates.GetString(SZF(rates));
  210. if ( g_reelLength != ExplodeString(rates, " ", rate, sizeof(rate), sizeof(rate[])) ) {
  211. LogError("count sm_slots_symbols != count sm_slots_rates");
  212. SetFailState("count sm_slots_symbols != count sm_slots_rates");
  213. }
  214. g_rates[0] = StringToInt(rate[0]);
  215. for ( int i = 1; i < g_reelLength; ++i ) {
  216. g_rates[i] = g_rates[i-1] + StringToInt(rate[i]);
  217. }
  218.  
  219. char mutlipliers[256], mutliplier[MAXLENGTH_REELS/MAXLENGTH_REEL][8];
  220. g_cvarMultipliers.GetString(SZF(mutlipliers));
  221. if ( g_reelLength != ExplodeString(mutlipliers, " ", mutliplier, sizeof(mutliplier), sizeof(mutliplier[])) ) {
  222. LogError("count sm_slots_symbols != count sm_slots_multipliers");
  223. SetFailState("count sm_slots_symbols != count sm_slots_multipliers");
  224. }
  225. for ( int i = 0; i < g_reelLength; ++i ) {
  226. g_multipliers[i] = StringToFloat(mutliplier[i]);
  227. }
  228.  
  229. char jackpotCombination[256], combination[MAXLENGTH_REELS/MAXLENGTH_REEL][8];
  230. g_cvarJackpotCombination.GetString(SZF(jackpotCombination));
  231. if ( 5 != ExplodeString(jackpotCombination, " ", combination, sizeof(combination), sizeof(combination[])) ) {
  232. for ( int i = 0; i < 5; ++i ) {
  233. g_jackpotCombination[i] = -1;
  234. }
  235. }
  236. else {
  237. for ( int i = 0; i < 5; ++i ) {
  238. g_jackpotCombination[i] = GetSymbolNumber(combination[i]);
  239. }
  240. }
  241.  
  242. g_infoMenu = new Menu(Handler_InfoMenu, MenuAction_Display);
  243. g_infoMenu.ExitBackButton = true;
  244.  
  245. for ( int i = 0; i < g_reelLength; ++i ) {
  246. char text[128];
  247. FormatEx(SZF(text), "%T", "about symbol", LANG_SERVER, g_reel[i], g_multipliers[i]);
  248. g_infoMenu.AddItem("", text, ITEMDRAW_DISABLED);
  249. }
  250.  
  251. if ( g_cvarLogging.BoolValue ) {
  252. BuildPath(Path_SM, SZF(g_logFile), "logs/shop_slots.txt");
  253. }
  254. }
  255.  
  256. public void OnClientPutInServer(int client)
  257. {
  258. g_nextSpinTime[client] = GetCookieInt(client, g_nextSpinTimeCookie);
  259. }
  260.  
  261. public void OnClientDisconnect(int client)
  262. {
  263. SetCookieInt(client, g_nextSpinTimeCookie, g_nextSpinTime[client]);
  264. }
  265.  
  266. int GetCookieInt(int client, Handle cookie)
  267. {
  268. char buffer[16];
  269. GetClientCookie(client, cookie, SZF(buffer));
  270. return StringToInt(buffer);
  271. }
  272.  
  273. void SetCookieInt(int client, Handle cookie, int value)
  274. {
  275. char buffer[16];
  276. IntToString(value, SZF(buffer));
  277. SetClientCookie(client, cookie, buffer);
  278. }
  279.  
  280. public void Ev_RoundStart(Event event, const char[] evName, bool silent)
  281. {
  282. if ( (g_cvarJackpotAdvertisement.IntValue != 0) && (g_currentRound % g_cvarJackpotAdvertisement.IntValue == 0) ) {
  283. CPrintToChatAll("%T", "advertisement jackpot", LANG_SERVER, GetJackpotPool());
  284.  
  285. if ( g_cvarJackpotLastWinner.BoolValue ) {
  286. int lastJackpot;
  287. char name[64], date[64];
  288. GetJackpotWinner(name, lastJackpot, date);
  289.  
  290. if ( name[0] != 0 ) {
  291. CPrintToChatAll("%T", "advertisement jackpot winner", LANG_SERVER, name, lastJackpot, date);
  292. }
  293. }
  294. }
  295. g_currentRound++;
  296. }
  297.  
  298. // ==============================================================================================================================
  299. // >>> COMMANDS
  300. // ==============================================================================================================================
  301. public Action Command_Slots(int client, int argc)
  302. {
  303. g_mainMenu.Display(client, MTF);
  304. return Plugin_Handled;
  305. }
  306.  
  307. public Action Command_SlotsPool(int client, int argc)
  308. {
  309. if ( argc == 0 ) {
  310. CPrintToChat(client, "%T", "current credits pool", client, GetCreditsPool());
  311. return Plugin_Handled;
  312. }
  313.  
  314. char new_pool[32];
  315. GetCmdArg(1, SZF(new_pool));
  316. SetCreditsPool(StringToInt(new_pool));
  317.  
  318. CPrintToChat(client, "%T", "new credits pool", client, GetCreditsPool());
  319. return Plugin_Handled;
  320. }
  321.  
  322. public Action Command_SlotsJackpot(int client, int argc)
  323. {
  324. if ( argc == 0 ) {
  325. CPrintToChat(client, "%T", "current jackpot pool", client, GetCreditsPool());
  326. return Plugin_Handled;
  327. }
  328.  
  329. char new_pool[32];
  330. GetCmdArg(1, SZF(new_pool));
  331. SetJackpotPool(StringToInt(new_pool));
  332.  
  333. CPrintToChat(client, "%T", "new jackpot pool", client, GetJackpotPool());
  334. return Plugin_Handled;
  335. }
  336.  
  337. // ==============================================================================================================================
  338. // >>> HANDLERS
  339. // ==============================================================================================================================
  340. public int Handler_MainMenu(Menu menu, MenuAction action, int client, int slot)
  341. {
  342. switch (action) {
  343. case MenuAction_DisplayItem: {
  344. char phrase[64];
  345. menu.GetItem(slot, "", 0, _, SZF(phrase));
  346.  
  347. char text[255];
  348. FormatEx(SZF(text), "%T", phrase, client);
  349.  
  350. return RedrawMenuItem(text);
  351. }
  352.  
  353. case MenuAction_Display: {
  354. char title[255];
  355. if ( g_cvarShowCredits.BoolValue ) {
  356. #if defined DRYRUN
  357. FormatEx(SZF(title), "%T", "slots title credits", client, 100);
  358. #else
  359. FormatEx(SZF(title), "%T", "slots title credits", client, Store_GetClientCredits(client));
  360. #endif
  361. }
  362. else {
  363. FormatEx(SZF(title), "%T", "slots title", client);
  364. }
  365.  
  366. menu.SetTitle(title);
  367. }
  368.  
  369. case MenuAction_Select: {
  370. char item[16];
  371. menu.GetItem(slot, SZF(item));
  372.  
  373. if ( StrEqual(item, "play") ) {
  374. if ( g_cvarCreditsPool.BoolValue ) {
  375. CPrintToChat(client, "%T", "current credits pool", client, GetCreditsPool());
  376. }
  377.  
  378. g_betsMenu.Display(client, MTF);
  379. }
  380. else if ( StrEqual(item, "info") ) {
  381. g_infoMenu.Display(client, MTF);
  382. }
  383. else {
  384. LogError(item);
  385. }
  386. }
  387. }
  388.  
  389. return 0;
  390. }
  391.  
  392. public int Handler_BetsMenu(Menu menu, MenuAction action, int client, int slot)
  393. {
  394. switch (action) {
  395. case MenuAction_DisplayItem: {
  396. char bet[MAXLENGTH_BET];
  397. menu.GetItem(slot, SZF(bet));
  398.  
  399. char text[255];
  400. FormatEx(SZF(text), "%T", "bet", client, StringToInt(bet));
  401.  
  402. return RedrawMenuItem(text);
  403. }
  404.  
  405. case MenuAction_Display: {
  406. char title[255];
  407. if ( g_cvarShowCredits.BoolValue ) {
  408. #if defined DRYRUN
  409. FormatEx(SZF(title), "%T", "bet title credits", client, 100);
  410. #else
  411. FormatEx(SZF(title), "%T", "bet title credits", client, Store_GetClientCredits(client));
  412. #endif
  413. }
  414. else {
  415. FormatEx(SZF(title), "%T", "bet title", client);
  416. }
  417. menu.SetTitle(title);
  418. }
  419.  
  420. case MenuAction_Select: {
  421. if ( g_cvarSpinCooldown.IntValue > 0 ) {
  422. int cooldown = g_nextSpinTime[client] - GetTime();
  423. if ( cooldown > 0 ) {
  424. char cooldown_string[64];
  425. FormatCooldown(cooldown, SZF(cooldown_string), client);
  426. CPrintToChat(client, "%T", "spin cooldown", client, cooldown_string);
  427. g_betsMenu.DisplayAt(client, GetMenuSelectionPosition(), MTF);
  428. return 0;
  429. }
  430.  
  431. g_nextSpinTime[client] = GetTime() + g_cvarSpinCooldown.IntValue;
  432.  
  433. char cooldown_string[64];
  434. FormatCooldown(g_cvarSpinCooldown.IntValue, SZF(cooldown_string), client);
  435. CPrintToChat(client, "%T", "spin cooldown", client, cooldown_string);
  436. }
  437.  
  438. char bet[MAXLENGTH_BET];
  439. menu.GetItem(slot, SZF(bet));
  440. g_bet[client] = StringToInt(bet);
  441.  
  442. #if defined DRYRUN
  443. #else
  444. if ( Store_GetClientCredits(client) < g_bet[client] ) {
  445. CPrintToChat(client, "%T", "not enough credits", client, g_bet[client] - Store_GetClientCredits(client));
  446. g_betsMenu.Display(client, MTF);
  447. return 0;
  448. }
  449. #endif
  450.  
  451. if ( g_cvarCreditsPool.BoolValue ) {
  452. if ( GetCreditsPool() < g_bet[client] ) {
  453. CPrintToChat(client, "%T", "not enough credits in pool", client, g_bet[client], g_creditsPool);
  454. g_betsMenu.Display(client, MTF);
  455. return 0;
  456. }
  457. }
  458.  
  459. if ( g_cvarLogging.BoolValue ) {
  460. char auth[32], ip[64], name[32];
  461. GetClientAuthId(client, AuthId_Steam2, SZF(auth));
  462. GetClientIP(client, SZF(ip));
  463. GetClientName(client, SZF(name));
  464.  
  465. LogToFile(g_logFile, "%T", "log before bet", LANG_SERVER, name, auth, ip, g_bet[client]);
  466. }
  467.  
  468. #if defined DRYRUN
  469. #else
  470. Store_SetClientCredits(client, Store_GetClientCredits(client) - g_bet[client]);
  471. #endif
  472.  
  473. if ( g_cvarCreditsPool.BoolValue ) {
  474. SetCreditsPool(GetCreditsPool() + g_bet[client]);
  475. }
  476.  
  477. if ( g_cvarJackpotMuptiplier.FloatValue > 0.0 ) {
  478. SetJackpotPool(GetJackpotPool() + RoundToNearest(g_cvarJackpotMuptiplier.FloatValue * g_bet[client]));
  479. }
  480.  
  481. if ( g_cvarJackpotChance.FloatValue > 0.0 ) {
  482. if ( GetRandomFloat(0.0, 100.0) <= g_cvarJackpotChance.FloatValue ) {
  483. for ( int i = 0; i < 5; ++i ) {
  484. g_combination[client][i] = g_jackpotCombination[i];
  485. g_step[client][i] = (i+1)*10 + GetRandomInt(1, 6);
  486. }
  487. }
  488. else {
  489. for ( int i = 0; i < 5; ++i ) {
  490. g_combination[client][i] = GetRandomSymbol();
  491. g_step[client][i] = (i+1)*10 + GetRandomInt(1, 6);
  492. }
  493.  
  494. if ( IsCombinationJackpot(client) ) {
  495. g_combination[client][GetRandomInt(0, 5-1)]++;
  496. }
  497. }
  498. }
  499. else {
  500. for ( int i = 0; i < 5; ++i ) {
  501. g_combination[client][i] = GetRandomSymbol();
  502. // g_combination[client][i] = 0;
  503. g_step[client][i] = (i+1)*10 + GetRandomInt(1, 6);
  504. }
  505. }
  506.  
  507. // CPrintToChatAll("%s %s %s %s %s", g_reel[g_combination[client][0]], g_reel[g_combination[client][1]], g_reel[g_combination[client][2]], g_reel[g_combination[client][3]], g_reel[g_combination[client][4]]);
  508. g_timer[client] = CreateTimer(0.1, Timer_StartAnimation, UID(client), TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
  509. }
  510.  
  511. case MenuAction_Cancel: {
  512. if ( slot == MenuCancel_ExitBack ) {
  513. g_mainMenu.Display(client, MTF);
  514. }
  515. }
  516. }
  517.  
  518. return 0;
  519. }
  520.  
  521. public int Handler_InfoMenu(Menu menu, MenuAction action, int client, int slot)
  522. {
  523. switch (action) {
  524. case MenuAction_Display: {
  525. char title[255];
  526. FormatEx(SZF(title), "%T", "info title", client);
  527. menu.SetTitle(title);
  528. }
  529.  
  530. case MenuAction_Cancel: {
  531. if ( slot == MenuCancel_ExitBack ) {
  532. g_mainMenu.Display(client, MTF);
  533. }
  534. }
  535. }
  536. }
  537.  
  538. public int Handler_Animation(Menu menu, MenuAction action, int client, int slot)
  539. {
  540. if ( slot == 1 ) {
  541. if ( g_cvarCreditsPool.BoolValue ) {
  542. CPrintToChat(client, "%T", "current credits pool", client, GetCreditsPool());
  543. }
  544.  
  545. g_betsMenu.Display(client, MTF);
  546. }
  547. }
  548.  
  549. // ==============================================================================================================================
  550. // >>> FUNCTIONS
  551. // ==============================================================================================================================
  552. int GetRandomSymbol()
  553. {
  554. int random = GetRandomInt(0, g_rates[g_reelLength-1]);
  555.  
  556. int num = 0;
  557. while ( g_rates[num] < random ) {
  558. num++;
  559. }
  560.  
  561. return num;
  562. }
  563.  
  564. int GetSlotSymbol(int client, int slot, int offset)
  565. {
  566. return (offset + g_combination[client][slot] + g_step[client][slot] + g_reelLength)%g_reelLength;
  567. }
  568.  
  569. void DisplayPanelFromString(int client, char[][] string, int length, bool showControls)
  570. {
  571. Panel panel = new Panel();
  572. for ( int i = 0; i < length; ++i ) {
  573. panel.DrawText(string[i]);
  574. }
  575.  
  576. char text[64];
  577. if ( showControls ) {
  578. FormatEx(SZF(text), "%T", "spin again", client);
  579. panel.DrawItem(text);
  580. FormatEx(SZF(text), "%T", "exit", client);
  581. panel.DrawItem(text);
  582. }
  583. else {
  584. FormatEx(SZF(text), "%T", "spin again disabled", client);
  585. panel.DrawText(text);
  586. FormatEx(SZF(text), "%T", "exit disabled", client);
  587. panel.DrawText(text);
  588. }
  589.  
  590. panel.Send(client, Handler_Animation, MTF);
  591. delete panel;
  592. }
  593.  
  594. void FormatCooldown(int seconds, char[] output, int max_length, int client)
  595. {
  596. int days = seconds / 86400;
  597. seconds -= days * 86400;
  598.  
  599. int hours = seconds / 3600;
  600. seconds -= hours * 3600;
  601.  
  602. int minutes = seconds / 60;
  603. seconds -= minutes * 60;
  604.  
  605. strcopy(output, max_length, "");
  606. if ( days > 0 ) {
  607. Format(output, max_length, "%s%T", output, "format days", client, days);
  608. }
  609. if ( hours > 0 ) {
  610. Format(output, max_length, "%s%T", output, "format hours", client, hours);
  611. }
  612. if ( minutes > 0 ) {
  613. Format(output, max_length, "%s%T", output, "format minutes", client, minutes);
  614. }
  615. if ( seconds > 0 ) {
  616. Format(output, max_length, "%s%T", output, "format seconds", client, seconds);
  617. }
  618. }
  619.  
  620. // ==============================================================================================================================
  621. // >>> TIMERS
  622. // ==============================================================================================================================
  623. public Action Timer_StartAnimation(Handle timer, any userid)
  624. {
  625. int client = CID(userid);
  626. if ( !client ) return Plugin_Stop;
  627.  
  628. char content[][64] = {
  629. "█░░░░░░░░░░░░░░░█",
  630. "█░░░░░░░░░░░░░░░█",
  631. "█░░░░░░░░░░░░░░░█",
  632. "█░░░░░░░░░░░░░░░█",
  633. "█░░░░░░░░░░░░░░░█",
  634. "█░░░░░░░░░░░░░░░█",
  635. " ",
  636. "-----------------"
  637. };
  638.  
  639. Format(content[1], sizeof(content[]), g_slotLine, g_reel[GetSlotSymbol(client, 0, -1)], g_reel[GetSlotSymbol(client, 1, -1)], g_reel[GetSlotSymbol(client, 2, -1)], g_reel[GetSlotSymbol(client, 3, -1)], g_reel[GetSlotSymbol(client, 4, -1)]);
  640. Format(content[2], sizeof(content[]), g_slotLine, g_reel[GetSlotSymbol(client, 0, 0)], g_reel[GetSlotSymbol(client, 1, 0)], g_reel[GetSlotSymbol(client, 2, 0)], g_reel[GetSlotSymbol(client, 3, 0)], g_reel[GetSlotSymbol(client, 4, 0)]);
  641. Format(content[3], sizeof(content[]), g_slotLine, g_reel[GetSlotSymbol(client, 0, 1)], g_reel[GetSlotSymbol(client, 1, 1)], g_reel[GetSlotSymbol(client, 2, 1)], g_reel[GetSlotSymbol(client, 3, 1)], g_reel[GetSlotSymbol(client, 4, 1)]);
  642.  
  643.  
  644. bool playSpinSound = true;
  645. for ( int i = 0; i < 5; ++i ) {
  646. playSpinSound &= CheckSlot(client, i);
  647. }
  648.  
  649. if ( g_step[client][4] <= 0 ) {
  650. DisplayPanelFromString(client, content, 7, true);
  651. OnSpinEnd(client);
  652. return Plugin_Stop;
  653. }
  654.  
  655. if ( g_step[client][4] == 1 ) {
  656. g_step[client][4]--;
  657. }
  658.  
  659. if ( playSpinSound ) {
  660. EmitSoundToClientAny(client, g_soundSpin);
  661. }
  662.  
  663. DisplayPanelFromString(client, content, 7, false);
  664. return Plugin_Continue;
  665. }
  666.  
  667. void OnSpinEnd(int client)
  668. {
  669. int won;
  670. if ( IsCombinationJackpot(client) ) {
  671. won = GetJackpotPool();
  672. SetJackpotPool(0);
  673.  
  674. if ( g_cvarJackpotWinMessage.BoolValue ) {
  675. char name[32];
  676. GetClientName(client, SZF(name));
  677. CPrintToChatAll("%T", "jackpot won all", client, name, won);
  678. }
  679. else {
  680. CPrintToChat(client, "%T", "jackpot won", client, won);
  681. }
  682.  
  683. char name[64], date[64];
  684. GetClientName(client, SZF(name));
  685. FormatTime(SZF(date), "%H:%M %m/%d/%y", GetTime());
  686. SetJackpotWinner(name, won, date);
  687. }
  688. else {
  689. float multiplier = 1.0;
  690. for ( int i = 0; i < 5; ++i ) {
  691. multiplier += g_multipliers[g_combination[client][i]];
  692. }
  693.  
  694. won = RoundToNearest(g_bet[client] * multiplier);
  695. if ( won < 1 ) won = 0;
  696. if ( g_cvarLogging.BoolValue ) {
  697. char auth[32], ip[64], name[32];
  698. GetClientAuthId(client, AuthId_Steam2, SZF(auth));
  699. GetClientIP(client, SZF(ip));
  700. GetClientName(client, SZF(name));
  701.  
  702. LogToFile(g_logFile, "%T", "log after bet", LANG_SERVER, name, auth, ip, g_bet[client], won);
  703. }
  704. }
  705.  
  706. if ( won > 0 ) {
  707. #if defined DRYRUN
  708. #else
  709. Store_SetClientCredits(client, Store_GetClientCredits(client) + won);
  710. #endif
  711. }
  712.  
  713. if ( g_cvarCreditsPool.BoolValue ) {
  714. int rem = GetCreditsPool() - won;
  715. if ( rem < 0 ) rem = 0;
  716. SetCreditsPool(rem);
  717. }
  718.  
  719. EmitSoundToClientAny(client, g_soundSlot);
  720. CPrintToChat(client, "%T", "won", client, won);
  721. }
  722.  
  723. bool CheckSlot(int client, int slot)
  724. {
  725. if ( g_step[client][slot] > 0 ) {
  726. g_step[client][slot]--;
  727.  
  728. if ( g_step[client][slot] == 0 ) {
  729. EmitSoundToClientAny(client, g_soundSlot);
  730. return false;
  731. }
  732. }
  733.  
  734. return true;
  735. }
  736.  
  737. int GetSymbolNumber(const char[] symbol)
  738. {
  739. for ( int i = 0; i < g_reelLength; ++i ) {
  740. if ( StrEqual(g_reel[i], symbol, false) ) {
  741. return i;
  742. }
  743. }
  744. return -1;
  745. }
  746.  
  747. bool IsCombinationJackpot(int client)
  748. {
  749. if ( g_cvarJackpotChance.FloatValue == 0.0 ) {
  750. return false;
  751. }
  752.  
  753. for ( int i = 0; i < 5; ++i ) {
  754. if ( g_combination[client][i] != g_jackpotCombination[i] ) {
  755. return false;
  756. }
  757. }
  758.  
  759. return true;
  760. }
  761.  
  762. void SetCreditsPool(int pool)
  763. {
  764. g_data.SetNum("credits_pool", pool);
  765. g_data.ExportToFile(g_dataFilePath);
  766. g_creditsPool = pool;
  767. }
  768.  
  769. int GetCreditsPool()
  770. {
  771. return g_creditsPool;
  772. }
  773.  
  774. void SetJackpotPool(int pool)
  775. {
  776. g_data.SetNum("jackpot_pool", pool);
  777. g_data.ExportToFile(g_dataFilePath);
  778. g_jackpotPool = pool;
  779. }
  780.  
  781. int GetJackpotPool()
  782. {
  783. return g_jackpotPool;
  784. }
  785.  
  786. void SetJackpotWinner(char[] name, int pool, char[] date)
  787. {
  788. g_data.SetString("last_winner_name", name);
  789. g_data.SetNum("last_winner_pool", pool);
  790. g_data.SetString("last_winner_date", date);
  791. g_data.ExportToFile(g_dataFilePath);
  792. }
  793.  
  794. void GetJackpotWinner(char[] name, int& pool, char[] date)
  795. {
  796. g_data.GetString("last_winner_name", name, 64, "");
  797. pool = g_data.GetNum("last_winner_pool", 0);
  798. g_data.GetString("last_winner_date", date, 64, "");
  799. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement