Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <shop>
  3. #include <sdktools_sound>
  4. #include <sdktools_stringtables>
  5. #pragma newdecls required
  6.  
  7. char Plugin_tag[] = "\x01[ \x04Конкурс\x01 ]";
  8. #define PLUS "+"
  9. #define MINUS "-"
  10. #define DIVISOR "/"
  11. #define MULTIPL "*"
  12.  
  13. char operators[][] = {PLUS, MINUS, DIVISOR, MULTIPL};
  14.  
  15. char Sound_download[] = "sound/shop/Applause.mp3";
  16.  
  17. char soundplay[sizeof(Sound_download) - 5] = "*";
  18. int nbrmin;
  19. int nbrmax;
  20. int mincredits;
  21. int maxcredits;
  22. static int questionResult;
  23. int credits;
  24. float minquestion;
  25. float maxquestion;
  26. float timeanswer;
  27.  
  28. Handle timerQuestionEnd;
  29.  
  30. public Plugin myinfo =
  31. {
  32. name = "Math Credits",
  33. author = "Arkarr / Psychologist21 & AlmazON",
  34. description = "Математические задачи за кредиты (конкурс)",
  35. version = "1.2.1",
  36. url = "http://www.sourcemod.net, http://hlmod.ru"
  37. };
  38.  
  39. public void OnPluginStart()
  40. {
  41. ConVar cvar = CreateConVar("sm_MathCredits_minimum_number", "1", "Каким должно быть минимальное число в примере?");
  42. HookConVarChange(cvar, CVAR_MinimumNumber);
  43. nbrmin = cvar.IntValue;
  44. HookConVarChange(cvar = CreateConVar("sm_MathCredits_maximum_number", "100", "Каким должно быть максимальное число в примере?"), CVAR_MaximumNumber);
  45. nbrmax = cvar.IntValue;
  46. HookConVarChange(cvar = CreateConVar("sm_MathCredits_minimum_credits", "5", "Минимальное количество кредитов, заработанных за правильный ответ.", _, true, 1.0), CVAR_MinimumCredits);
  47. mincredits = cvar.IntValue;
  48. HookConVarChange(cvar = CreateConVar("sm_MathCredits_maximum_credits", "100", "Максимальное количество кредитов, заработанных за правильный ответ.", _, true, 1.0), CVAR_MaximumCredits);
  49. maxcredits = cvar.IntValue;
  50. HookConVarChange(cvar = CreateConVar("sm_MathCredits_time_answer_questions", "15", "Время в секундах для того, чтобы дать ответ на вопрос.", _, true, 5.0), CVAR_TimeAnswer);
  51. timeanswer = cvar.FloatValue;
  52. HookConVarChange(cvar = CreateConVar("sm_MathCredits_time_minamid_questions", "100", "Минимальное время в секундах между каждым из вопросов.", _, true, 5.0), CVAR_MinQuestion);
  53. minquestion = cvar.FloatValue;
  54. HookConVarChange(cvar = CreateConVar("sm_MathCredits_time_maxamid_questions", "250", "Максимальное время в секундах между каждым из вопросов.", _, true, 10.0), CVAR_MaxQuestion);
  55. maxquestion = cvar.FloatValue;
  56. AutoExecConfig(true, "shop_math");
  57.  
  58. strcopy(soundplay[GetEngineVersion() == Engine_CSGO], sizeof(soundplay), Sound_download[6]);
  59. }
  60.  
  61. public void CVAR_MinimumNumber(ConVar convar, const char[] oldValue, const char[] newValue)
  62. {
  63. nbrmin = convar.IntValue;
  64. }
  65. public void CVAR_MaximumNumber(ConVar convar, const char[] oldValue, const char[] newValue)
  66. {
  67. nbrmax = convar.IntValue;
  68. }
  69. public void CVAR_MinimumCredits(ConVar convar, const char[] oldValue, const char[] newValue)
  70. {
  71. mincredits = convar.IntValue;
  72. }
  73. public void CVAR_MaximumCredits(ConVar convar, const char[] oldValue, const char[] newValue)
  74. {
  75. maxcredits = convar.IntValue;
  76. }
  77. public void CVAR_TimeAnswer(ConVar convar, const char[] oldValue, const char[] newValue)
  78. {
  79. timeanswer = convar.FloatValue;
  80. }
  81. public void CVAR_MinQuestion(ConVar convar, const char[] oldValue, const char[] newValue)
  82. {
  83. minquestion = convar.FloatValue;
  84. }
  85. public void CVAR_MaxQuestion(ConVar convar, const char[] oldValue, const char[] newValue)
  86. {
  87. maxquestion = convar.FloatValue;
  88. }
  89.  
  90. public void OnMapStart()
  91. {
  92. PrecacheSound(soundplay, true);
  93. AddFileToDownloadsTable(Sound_download);
  94. }
  95.  
  96. public void OnConfigsExecuted()
  97. {
  98. timerQuestionEnd = null;
  99. CreateTimer(GetRandomFloat(minquestion, maxquestion), CreateQuestion, _, TIMER_FLAG_NO_MAPCHANGE);
  100. }
  101.  
  102. public Action CreateQuestion(Handle timer)
  103. {
  104. char op[sizeof(operators[])];
  105. strcopy(op, sizeof(op), operators[GetRandomInt(0,sizeof(operators)-1)]);
  106.  
  107. int nbr1, nbr2 = GetRandomInt(nbrmin, nbrmax);
  108.  
  109. if(strcmp(op, DIVISOR))
  110. {
  111. nbr1 = GetRandomInt(nbrmin, nbrmax);
  112. questionResult = strcmp(op, PLUS) ? strcmp(op, MINUS) ? nbr1 * nbr2:nbr1 - nbr2:nbr1 + nbr2;
  113. }
  114. else questionResult = (nbr1 = GetRandomInt(nbrmin/nbr2, nbrmax/nbr2) * nbr2) / nbr2;
  115.  
  116. timerQuestionEnd = CreateTimer(timeanswer, EndQuestion, _, TIMER_FLAG_NO_MAPCHANGE);
  117.  
  118. credits = GetRandomInt(mincredits, maxcredits);
  119. for(int i = 1; i <= MaxClients; ++i)
  120. {
  121. if(IsClientInGame(i)) PrintToChat(i, "\n%s \x03%i %s %i = ?\n \x01За For right answer get \x05%i\x01 credits(ов).\n", Plugin_tag, nbr1, op, nbr2, credits);
  122. }
  123. return Plugin_Stop;
  124. }
  125.  
  126. public Action EndQuestion(Handle timer)
  127. {
  128. SendEndQuestion();
  129. return Plugin_Stop;
  130. }
  131.  
  132. public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
  133. {
  134. if(timerQuestionEnd && StringToInt(sArgs) == questionResult && (questionResult || strcmp(sArgs, "0") == 0))
  135. {
  136. int clients[1];
  137. Shop_GiveClientCredits(clients[0] = client, credits);
  138. PrintHintText(clients[0], "You received %i credits.", credits); //CS:S
  139. //PrintHintText(clients[0], "You received <font color='#00FF1E'>%i</font> credits.", credits); //CS:GO
  140. SendEndQuestion(clients[0]);
  141. EmitSound(clients, 1, soundplay);
  142. }
  143. }
  144.  
  145. void SendEndQuestion(int client = 0)
  146. {
  147. int i = MaxClients;
  148. if(client)
  149. {
  150. while(i)
  151. {
  152. if(IsClientInGame(i)) PrintToChat(i, "%s \x03%N \x01received \x05%i \credits for for winning the competition.", Plugin_tag, client, credits);
  153. --i;
  154. }
  155. delete timerQuestionEnd;
  156. }
  157. else
  158. {
  159. while(i)
  160. {
  161. if(IsClientInGame(i)) PrintToChat(i, "%s \x03Time is up\x01, \x05no answer\x01!", Plugin_tag);
  162. --i;
  163. }
  164. }
  165. OnConfigsExecuted();
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement