Advertisement
Guest User

SA-MP Lottery event

a guest
Oct 28th, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. /*
  2. Credits:
  3.  
  4. ZCMD > Command System.
  5.  
  6. Brandon_More (GiGi) > Scripter.
  7.  
  8. Woot > SendClientError - SCP - SendMessageToPlayer functions.
  9.  
  10. Slice (I Think) > Number controllers.
  11. */
  12.  
  13. #include <a_samp>
  14. #include <zcmd>
  15.  
  16. #define ALTCOMMAND:%1->%2; \
  17. COMMAND:%1(playerid, params[]) \
  18. return cmd_%2(playerid, params);
  19.  
  20. new iStr[ 164 ]; // Global String
  21.  
  22. /*
  23. Colo(u)r Name Colo(u)r Value
  24. */
  25. #define COLOR_LIGHTGREY 0xCCCCCCFF
  26. #define COLOR_RED 0xCC3300FF
  27.  
  28. /*
  29. Define Name Define Value
  30. */
  31. #define CANT_USE_CMD "You are not allowed to use this command!"
  32.  
  33. /* Woot stuff */
  34. SendClientError(playerid, errormessage[]) {
  35. new _error[256];
  36. format(_error, 256, "{ffa10d}[Error]: {d58609}%s", errormessage);
  37. if(IsPlayerConnected(playerid)) SendClientMessage(playerid, COLOR_RED, _error);
  38. return 1;
  39. }
  40.  
  41. stock SCP(_id, _param[], _command[] = "") {
  42. format(iStr, sizeof(iStr), "{6a696a}[Command]: /%s {9c9a9c}%s", _command, _param);
  43. return SendMessageToPlayer(_id, COLOR_LIGHTGREY, iStr, 128);
  44. }
  45.  
  46. stock PlayerName(playerid)
  47. {
  48. new name[MAX_PLAYER_NAME];
  49. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  50. return name;
  51. }
  52.  
  53. stock SendMessageToPlayer(playerid, color, text[], len = 132) {
  54. new
  55. text2[ 256 ],
  56. maxstring = 384;
  57.  
  58. if(strlen(text) > len)
  59. {
  60. strmid(text2, text, len, maxstring);
  61. strdel(text, len, maxstring);
  62. strins(text, " ..", len, maxstring);
  63. strins(text2, ".. ", 0, maxstring);
  64. SendClientMessage(playerid, color, text);
  65. SendClientMessage(playerid, color, text2);
  66. return 1;
  67. }
  68. else return SendClientMessage(playerid, color, text);
  69. }
  70. /* Emd woot stuff */
  71.  
  72. new
  73. lotteryNum,
  74. lotteryPrize[ 40 ],
  75. lotteryPrice,
  76. lotteryRange;
  77.  
  78. public OnFilterScriptInit() {
  79. return 1;
  80. }
  81.  
  82. COMMAND:startlot(playerid, params[]){
  83.  
  84. if(!IsPlayerAdmin(playerid))
  85. return SendClientError(playerid,CANT_USE_CMD);
  86.  
  87. new iPrice,
  88. iPrize[ 40 ],
  89. iNumber,
  90. iRange;
  91.  
  92. if( sscanf ( params, "ddsd", iNumber, iPrice, iPrize, iRange))
  93. return SCP(playerid, "[Ticket number][Price of ticket][prize][Range]");
  94.  
  95. if(iPrice > 500000 || iPrice < 2500)
  96. return SendClientError(playerid,"Price of the ticket has to be higher than 2,500 and lower than 500,000");
  97.  
  98. if(iRange < 1 || iRange > 500 || iNumber > 500 || iNumber < 1)
  99. return SendClientError(playerid, "Lottery range is too high - Maximum of 500");
  100.  
  101. lotteryPrize = iPrize;
  102. lotteryPrice = iPrice;
  103. lotteryNum = iNumber;
  104. lotteryRange = iRange;
  105.  
  106. format(iStr, sizeof(iStr), "{7b94a1}[Lottery] {b5cdda} Prize: %s | Ticket Price: $%s", lotteryPrize, number_format(lotteryPrice));
  107. SendClientMessage(playerid,COLOR_LIGHTGREY,iStr);
  108. format(iStr, sizeof(iStr), "{7b94a1}[Lottery] {b5cdda} Use /lot <1-%d> in order to get a chance to win.", iRange);
  109. SendClientMessage(playerid,COLOR_LIGHTGREY,iStr);
  110.  
  111. return 1;
  112. }
  113. COMMAND:changelot(playerid, params[]) {
  114. if(!IsPlayerAdmin(playerid)) return SendClientError(playerid,CANT_USE_CMD);
  115. new iNumber;
  116. if( sscanf ( params, "d", iNumber))
  117. return SCP(playerid, "[Ticket number]");
  118. if(lotteryNum < 1)
  119. return SendClientError(playerid, "There isn't a lottery on..");
  120. lotteryNum = iNumber;
  121. SendClientMessageToAll(COLOR_LIGHTGREY,"{7b94a1}[Lottery] {b5cdda} Warning an Administrator has changed the lottery number.");
  122. return 1;
  123. }
  124. COMMAND:stoplot(playerid, params[]) {
  125. if(!IsPlayerAdmin(playerid)) return SendClientError(playerid,CANT_USE_CMD);
  126. if(lotteryNum < 1)
  127. return SendClientError(playerid, "There isn't a lottery on..");
  128. lotteryNum = 0; lotteryPrice = 0; lotteryRange = 0;
  129. SendClientMessageToAll(COLOR_LIGHTGREY,"An Administrator has stopped the current lottery");
  130. return 1;
  131. }
  132. // During Testing... :)
  133. COMMAND:givemecash(playerid, params[]) {
  134. GivePlayerMoney(playerid, lotteryPrice);
  135. return 1;
  136. }
  137. COMMAND:unfreeze(playerid, params[]) {
  138. TogglePlayerControllable(playerid, true);
  139. return 1;
  140. }
  141. //Finish Testing
  142. COMMAND:lot(playerid, params[]) {
  143. if(!IsPlayerConnected(playerid)) return SendClientError(playerid,CANT_USE_CMD);
  144. new iNumber;
  145. new kesh = GetPlayerMoney(playerid);
  146. if( sscanf ( params, "d", iNumber)) return SCP(playerid, "[Ticket number]");
  147. if(lotteryNum < 1)
  148. return SendClientError(playerid, "There isn't a lottery currently on");
  149. if(iNumber > lotteryRange)
  150. return SendClientError(playerid, "You have exceeded the lottery range");
  151. if(kesh < lotteryPrice)
  152. return SendClientError(playerid, "Not enough kesh");
  153. GivePlayerMoney(playerid, -lotteryPrice);
  154. if(iNumber != lotteryNum) {
  155. SendClientMessage(playerid,COLOR_LIGHTGREY,"{7b94a1}[Lottery]{b5cdda} Thank you for your participation! Unfortunately, you haven't won anything.");
  156. }
  157. else {
  158. format(iStr, sizeof(iStr), "{7b94a1}[Lottery] {b5cdda} %s has won the lottery with #%d - PRIZE: %s!!", PlayerName(playerid), lotteryNum, lotteryPrize);
  159. SendClientMessage(playerid,COLOR_LIGHTGREY,iStr);
  160. lotteryNum = 0; lotteryPrice = 0; lotteryRange = 0;
  161. SendClientMessage(playerid, COLOR_LIGHTGREY,"You have been frozen, untill you have recieved your reward from an Administrator");
  162. TogglePlayerControllable(playerid, false);
  163. }
  164. return 1;
  165. }
  166.  
  167. // number_format function by Slice i think
  168. stock number_format( num )
  169. {
  170. new stri[16], stro[16], i, v, p, d, l, n = num < 0;
  171.  
  172. format( stri, sizeof( stri ), "%d", num * ( n ? -1 : 1 ) );
  173.  
  174. l = strlen( stri ) - 1;
  175. d = ( l - ( l % 3 ) ) / 3;
  176. l = l + 1;
  177. i = l + d;
  178. p = l;
  179.  
  180. while ( i >= 0 )
  181. {
  182. v = l + d - i;
  183.  
  184. if ( v && !( v % 4 ) )
  185. stro[i + n] = ',';
  186. else
  187. stro[i + n] = stri[p--];
  188.  
  189. i--;
  190. }
  191.  
  192. stro[0] = n ? '-' : stro[0];
  193.  
  194. return stro;
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement