Advertisement
kusehsup

Untitled

Dec 12th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.49 KB | None | 0 0
  1. #include <a_samp>
  2. #include <streamer>
  3. #include <dc_cmd>
  4. #include <a_mysql>
  5.  
  6. main(){}
  7.  
  8. #define MYSQL_HOST      "127.0.0.1"
  9. #define MYSQL_USER      "root"
  10. #define MYSQL_DATABASE  "test"
  11. #define MYSQL_PASSWORD  ""
  12.  
  13. new MySQL: db;
  14.  
  15. forward Database_connect();
  16. public Database_connect()
  17. {
  18.     db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
  19.     mysql_set_charset("cp1251");
  20.     return 1;
  21. }
  22.  
  23. #define BOX_ENABLED
  24. #define MAX_PRIZE_COUNT (6)
  25. #define MAX_BOXES_COUNT (3)
  26. #define MAX_LENGHT_NAME_ITEM_PRIZE (64)
  27. #define ITEM_MONEY (16)
  28.  
  29. new area;
  30.  
  31. enum E_BOX_STRUCT
  32. {
  33.     Float: BS_POS_X,
  34.     Float: BS_POS_Y,
  35.     Float: BS_POS_Z,
  36.     BS_AREA_ID
  37. };
  38.  
  39. new boxes[MAX_BOXES_COUNT][E_BOX_STRUCT] =
  40. {
  41.     { 1899.2340, 1177.8785, 30.0135, INVALID_STREAMER_ID },
  42.     { 1879.9230, 1168.1254, 30.0106, INVALID_STREAMER_ID },
  43.     { 1886.7753, 1182.9382, 30.0087, INVALID_STREAMER_ID }
  44. };
  45.  
  46. enum
  47. {
  48.     ITEM_TYPE_MONEY,
  49.     ITEM_TYPE_WEAPON,
  50.     ITEM_TYPE_VEHICLE
  51. }
  52.  
  53. enum E_PRIZE_STRUCT
  54. {
  55.     PS_ITEM_TYPE,
  56.     PS_ITEM_ID,
  57.     PS_ITEM_NAME[MAX_LENGHT_NAME_ITEM_PRIZE],
  58.     PS_ITEM_VALUE
  59. };
  60.  
  61. new prizes_list[MAX_PRIZE_COUNT][E_PRIZE_STRUCT] =
  62. {
  63.     { ITEM_TYPE_WEAPON,     24,     "Deagle",                       15          },
  64.     { ITEM_TYPE_WEAPON,     6,      "Лопата",                     1           },
  65.     { ITEM_TYPE_WEAPON,     10,     "Дилдо",                       1           },
  66.     { ITEM_TYPE_MONEY,      0,      "Деньги в размере 50 000",    50_000      },
  67.     { ITEM_TYPE_MONEY,      0,      "Деньги в размере 100 000",   100_000     },
  68.     { ITEM_TYPE_MONEY,      0,      "Деньги в размере 200 000",   200_000     },
  69.     { ITEM_TYPE_VEHICLE,    400,    "BMW X5",                       -1          }
  70. };
  71.  
  72. stock CreateBox(Float: x, Float: y, Float: z)
  73. {
  74.     new area_id = CreateDynamicSphere(x, y, z, 3.0, 0, 0);
  75.  
  76.     CreateDynamicObject(19056, x, y, z, 0, 0, 0, 0, 0);
  77.     CreateDynamic3DTextLabel("Нажмите alt чтобы открыть подарок", -1, x, y, z, 4.0, .worldid = 0, .interiorid = 0, .areaid = area_id);
  78.  
  79.     return area_id;
  80. }
  81.  
  82. stock BoxInit()
  83. {
  84.     for (new i = 0; i < MAX_BOXES_COUNT; i++)
  85.     {
  86.         new Float: x = boxes[i][BS_POS_X],
  87.             Float: y = boxes[i][BS_POS_Y],
  88.             Float: z = boxes[i][BS_POS_Z];
  89.  
  90.         new area_id = CreateBox(x, y, z);
  91.  
  92.         boxes[i][BS_AREA_ID] = area_id;
  93.  
  94.         printf("[Boxes] Box Init coord x: %f, y: %f, z: %f, area: %i", x, y, z, area_id);
  95.     }
  96. }
  97.  
  98. public OnGameModeInit()
  99. {
  100.     SetGameModeText("Test");
  101.  
  102.     BoxInit();
  103.  
  104.     return 1;
  105. }
  106.  
  107. public OnPlayerEnterDynamicArea(playerid, STREAMER_TAG_AREA: areaid)
  108. {
  109.     area = areaid;
  110.  
  111.     new string[144];
  112.     format(string, sizeof(string), "Player: %i, Area: %i", playerid, areaid);
  113.     SendClientMessage(playerid, -1, string);
  114.  
  115.     return 1;
  116. }
  117.  
  118. public OnPlayerLeaveDynamicArea(playerid, STREAMER_TAG_AREA: areaid)
  119. {
  120.     area = 0;
  121.     return 1;
  122. }
  123.  
  124. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  125. {
  126.     if (newkeys == 1024 && area != 0)
  127.     {
  128.         ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Подарок!", "Вы нашли подарок, открыв его обнаружили ", "Забрать", "Отказаться");
  129.     }
  130.     return 1;
  131. }
  132.  
  133. public OnGameModeExit()
  134. {
  135.     return 1;
  136. }
  137.  
  138. public OnPlayerConnect(playerid)
  139. {
  140.     return 1;
  141. }
  142.  
  143. public OnPlayerDisconnect(playerid, reason)
  144. {
  145.     return 1;
  146. }
  147.  
  148. public OnPlayerSpawn(playerid)
  149. {
  150.     SetPlayerPos(playerid, 1890.6500, 1167.9888, 29.6750);
  151.  
  152.     new player_name[MAX_PLAYER_NAME];
  153.     GetPlayerName(playerid, player_name, sizeof(player_name));
  154.  
  155.     new q_string[256];
  156.     mysql_format(db, q_string, sizeof(q_string), "INSERT INTO `users` (`nickname`) VALUES ('%e')", player_name);
  157.     mysql_query(db, q_string);
  158.  
  159.     return 1;
  160. }
  161.  
  162.  
  163. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  164. {
  165.     if (response)
  166.     {
  167.         new prize = random(MAX_PRIZE_COUNT);
  168.         new prize_item_name[64];
  169.         new prize_item_value = prizes_list[prize][PS_ITEM_VALUE];
  170.         new prize_item_id = prizes_list[prize][PS_ITEM_ID];
  171.  
  172.         new prize_item_type = prizes_list[prize][PS_ITEM_TYPE];
  173.        
  174.         format(prize_item_name, sizeof(prize_item_name), "%s", prizes_list[prize][PS_ITEM_NAME]);
  175.  
  176.         new query[256];
  177.         new player_name[MAX_PLAYER_NAME];
  178.         GetPlayerName(playerid, player_name, sizeof(player_name));
  179.        
  180.         mysql_format(
  181.             db, query, sizeof(query),
  182.             "INSERT INTO `prizes_history` (`player_name`, `item_id`, `item_name`, `item_value`) VALUES ('%e', '%i', '%e', '%i')",
  183.             player_name, prize_item_id, prize_item_name, prize_item_value
  184.         );
  185.         mysql_query(db, query);
  186.  
  187.         switch (prize_item_type)
  188.         {
  189.             case ITEM_MONEY: GivePlayerMoney(playerid, prize_item_value);
  190.  
  191.             case ITEM_TYPE_WEAPON: GivePlayerWeapon(playerid, prize_item_id, prize_item_value);
  192.  
  193.             case ITEM_TYPE_VEHICLE:
  194.             {
  195.                 new Float: x, Float: y, Float: z;
  196.                 GetPlayerPos(playerid, x, y, z);
  197.  
  198.                 AddStaticVehicle(prize_item_id, x + 2.0, y + 2.0, z + 1.0, 0, 1, 1);
  199.             }
  200.         }
  201.  
  202.         new string[144];
  203.         format(string, sizeof(string), "Вы забрали приз: %s", prize_item_name);
  204.         SendClientMessage(playerid, -1, string);
  205.     }
  206.     else
  207.     {
  208.         SendClientMessage(playerid, -1, "Вы отказались от приза");
  209.     }
  210.    
  211.     DestroyDynamicObject(area);
  212.     DestroyDynamic3DTextLabel(STREAMER_TAG_3D_TEXT_LABEL: area);
  213.     DestroyDynamicArea(area);
  214. }
  215.  
  216. CMD:show_prize(playerid)
  217. {
  218.     new player_name[MAX_PLAYER_NAME];
  219.     GetPlayerName(playerid, player_name, sizeof(player_name));
  220.  
  221.     printf("Player name: %s\n", player_name);
  222.  
  223.     new query[256];
  224.     mysql_format(db, query, 256, "SELECT * FROM prizes_history WHERE `player_name`='%s'", player_name);
  225.    
  226.     new Cache: result = mysql_query(db, query), rows = cache_num_rows(); rows--;
  227.  
  228.     for (new i; i <= rows; i++)
  229.     {
  230.         new prize_name[256], prize_value[24], prize_time[256];
  231.  
  232.         cache_get_value_name(i, "prize_name", prize_name, sizeof(prize_name));
  233.         cache_get_value_name(i, "prize_value", prize_value, sizeof(prize_value));
  234.         cache_get_value_name(i, "timestamp", prize_time, sizeof(prize_time));
  235.         new string[256]; format(string, sizeof(string), "Приз: %s, Количество: %i, Время: %s", prize_name, prize_value, prize_time);
  236.         printf("INFO: %s", string);
  237.     }
  238.     cache_delete(Cache: result);
  239.  
  240.  
  241.     return 1;
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement