Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <strlib>
  4. #include <sscanf2>
  5.  
  6. #define MAX_AUCTIONS (10)
  7.  
  8. enum E_AUCTION {
  9. bool: a_used,
  10. a_player,
  11. a_offeredPrice,
  12. a_startPrice,
  13. a_offerDelay,
  14. a_delayTimer
  15. }
  16. new g_AuctionData[MAX_AUCTIONS][E_AUCTION];
  17.  
  18.  
  19. stock CreateAuction(price, offerDelay = 10000)
  20. {
  21. new id = FindFreeAuctionID();
  22. if (id == -1) return 0;
  23.  
  24. g_AuctionData[id][a_used] = true;
  25. g_AuctionData[id][a_player] = INVALID_PLAYER_ID;
  26. g_AuctionData[id][a_offeredPrice] = 0;
  27. g_AuctionData[id][a_startPrice] = price < 1 ? 1 : price;
  28. g_AuctionData[id][a_offerDelay] = offerDelay;
  29.  
  30. printf("Auction %d has started");
  31. SendClientMessageToAll(-1, sprintf("Auction %d has started, with start price of %d$", id, price));
  32. return 1;
  33. }
  34.  
  35. stock DestroyAuction(id)
  36. {
  37. if (!g_AuctionData[id][a_used]) return 0; // Nema praznog slota za novu aukciju
  38. g_AuctionData[id][a_used] = false;
  39. return 1;
  40. }
  41.  
  42. static stock FindFreeAuctionID()
  43. {
  44. for (new i = 0; i < MAX_AUCTIONS; i++) if (!g_AuctionData[i][a_used]) {
  45. return i;
  46. }
  47.  
  48. return -1;
  49. }
  50.  
  51. stock OfferAuctionPrice(playerid, auctionId, price)
  52. {
  53. if (!g_AuctionData[auctionId][a_used]) return 0; // Aukcija nije aktivna vise
  54. if (price < g_AuctionData[auctionId][a_startPrice]) return 0; // Ne mozes ponuditi manje od pocetne ponude
  55. if (price <= g_AuctionData[auctionId][a_offeredPrice]) return 0; // Ne mozes ponuditi manje od zadnje ponude
  56. if (playerid == g_AuctionData[auctionId][a_player]) return 0; // Ne mozes ponuditi 2 ponude za redom
  57. if (GetPlayerMoney(playerid) < price) return 0; // Nema dovoljno novca
  58.  
  59. g_AuctionData[auctionId][a_player] = playerid;
  60. g_AuctionData[auctionId][a_offeredPrice] = price;
  61.  
  62. new name[MAX_PLAYER_NAME];
  63. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  64. SendClientMessageToAll(-1, sprintf("Player %s offered %d$ on auction %d, you have %d seconds to put new offer",
  65. name, price, auctionId, g_AuctionData[auctionId][a_offerDelay] / 1000));
  66.  
  67. KillTimer(g_AuctionData[auctionId][a_delayTimer]);
  68. g_AuctionData[auctionId][a_delayTimer] = SetTimerEx("AuctionDelay", g_AuctionData[auctionId][a_offerDelay], false, "i", auctionId);
  69. return 1;
  70. }
  71.  
  72. // Handle timer
  73. forward AuctionDelay(id);
  74. public AuctionDelay(id)
  75. {
  76. if (g_AuctionData[id][a_player] == INVALID_PLAYER_ID) {
  77. printf("Auction (%d) has been closed, noone offered", id);
  78. return 0;
  79. }
  80.  
  81. if (!IsPlayerConnected(g_AuctionData[id][a_player])) {
  82. printf("Auction (%d) has been closed, player who offered last offer has disconnected", id);
  83. return 0;
  84. }
  85.  
  86. GivePlayerMoney(g_AuctionData[id][a_player], -g_AuctionData[id][a_offeredPrice]);
  87. g_AuctionData[id][a_used] = false;
  88.  
  89. new buffer[128], name[MAX_PLAYER_NAME];
  90. GetPlayerName(g_AuctionData[id][a_player], name, MAX_PLAYER_NAME);
  91.  
  92. format (buffer, sizeof buffer, "Player %s got auction %d for %d$", name, id, g_AuctionData[id][a_offeredPrice]);
  93. SendClientMessageToAll(-1, buffer);
  94.  
  95. /*
  96. Das igracu sto je dobio, a njegov id je
  97. a_AuctionData[id][a_player]
  98. */
  99. return 1;
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. // Test
  107. CMD:createauction(playerid, arg[])
  108. {
  109. if (!CreateAuction(strval(arg))) {
  110. SendClientMessage(playerid, -1, "There's not free slots for new auction");
  111. }
  112. return 1;
  113. }
  114.  
  115. CMD:offer(playerid, arg[])
  116. {
  117. new auction, offer;
  118. if (sscanf(arg, "ii", auction, offer)) return SendClientMessage(playerid, -1, "usage: /offer <auction> <offer>");
  119.  
  120. OfferAuctionPrice(playerid, auction, offer);
  121. return 1;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement