Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <streamer>
- #include <dc_cmd>
- #include <a_mysql>
- main(){}
- #define MYSQL_HOST "127.0.0.1"
- #define MYSQL_USER "root"
- #define MYSQL_DATABASE "test"
- #define MYSQL_PASSWORD ""
- new MySQL: db;
- #define BOX_ENABLED
- #define MAX_BOXES_COUNT (3)
- #define MAX_PRIZE_COUNT (7)
- #define MAX_LENGHT_NAME_ITEM_PRIZE (64)
- #define MAX_PRIZE_COUNT_ON_PAGE (10)
- #define INVALID_BOX_ID (-1)
- enum BOX_STRUCT
- {
- ID,
- Float: POS_X,
- Float: POS_Y,
- Float: POS_Z,
- AREA_ID
- };
- new boxes[MAX_BOXES_COUNT][BOX_STRUCT] =
- {
- { INVALID_BOX_ID, 1899.2340, 1177.8785, 30.0135, INVALID_STREAMER_ID },
- { INVALID_BOX_ID, 1879.9230, 1168.1254, 30.0106, INVALID_STREAMER_ID },
- { INVALID_BOX_ID, 1886.7753, 1182.9382, 30.0087, INVALID_STREAMER_ID }
- };
- enum
- {
- ITEM_TYPE_MONEY,
- ITEM_TYPE_WEAPON,
- ITEM_TYPE_VEHICLE
- }
- enum PRIZE_STRUCT
- {
- ITEM_TYPE,
- ITEM_ID,
- ITEM_NAME[MAX_LENGHT_NAME_ITEM_PRIZE],
- ITEM_VALUE
- };
- new prizes_list[MAX_PRIZE_COUNT][E_PRIZE_STRUCT] =
- {
- { ITEM_TYPE_WEAPON, 24, "Deagle", 15 },
- { ITEM_TYPE_WEAPON, 6, "Лопата", 1 },
- { ITEM_TYPE_WEAPON, 10, "Дилдо", 1 },
- { ITEM_TYPE_MONEY, 0, "Деньги", 50_000 },
- { ITEM_TYPE_MONEY, 0, "Деньги", 100_000 },
- { ITEM_TYPE_MONEY, 0, "Деньги", 200_000 },
- { ITEM_TYPE_VEHICLE, 400, "BMW X5", -1 }
- };
- new current_page_prizes[MAX_PLAYERS];
- enum
- {
- DIALOG_PRIZE_LIST,
- DIALOG_TAKE_PRIZE
- }
- public OnGameModeInit()
- {
- DataBaseConnect();
- BoxInit();
- return 1;
- }
- forward DataBaseConnect();
- public DataBaseConnect()
- {
- db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
- mysql_set_charset("cp1251");
- if (mysql_errno())
- {
- printf("Произошла ошибка при подключении к базе данных.");
- return 0;
- }
- return 1;
- }
- stock BoxInit()
- {
- for (new i = 0; i < MAX_BOXES_COUNT; i++)
- {
- new Float: x = boxes[i][POS_X],
- Float: y = boxes[i][POS_Y],
- Float: z = boxes[i][POS_Z];
- new area_id = CreateBox(x, y, z);
- boxes[i][ID] = i;
- boxes[i][AREA_ID] = area_id;
- printf("[Boxes] Box Init coord x: %f, y: %f, z: %f, area: %i", x, y, z, area_id);
- }
- }
- stock CreateBox(Float: x, Float: y, Float: z)
- {
- new area_id = CreateDynamicSphere(x, y, z, 3.0, 0, 0);
- CreateDynamicObject(19056, x, y, z, 0, 0, 0, 0, 0);
- CreateDynamic3DTextLabel("Нажмите alt чтобы открыть подарок", -1, x, y, z, 4.0, .worldid = 0, .interiorid = 0, .areaid = area_id);
- return area_id;
- }
- public OnPlayerEnterDynamicArea(playerid, STREAMER_TAG_AREA: areaid)
- {
- new string[144];
- format(string, sizeof(string), "Player: %i, Area: %i", playerid, areaid);
- SendClientMessage(playerid, -1, string);
- SetPVarInt(playerid, "PLAYER_AREA_ID", areaid + 1);
- return 1;
- }
- stock GetBoxByArea(area_id)
- {
- for (new i = 0; i < MAX_BOXES_COUNT; i++)
- {
- new box_area_id = boxes[i][AREA_ID];
- if (area_id == box_area_id)
- {
- return i;
- }
- }
- return INVALID_BOX_ID;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch (dialogid)
- {
- case DIALOG_TAKE_PRIZE:
- {
- if (response)
- {
- new box_id = GetPVarInt(playerid, "ACTIVE_BOX_ID") - 1,
- prize = random(MAX_PRIZE_COUNT);
- new prize_item_name[MAX_LENGHT_NAME_ITEM_PRIZE],
- prize_item_value = prizes_list[prize][ITEM_VALUE],
- prize_item_id = prizes_list[prize][ITEM_ID],
- prize_item_type = prizes_list[prize][ITEM_TYPE];
- format(prize_item_name, sizeof(prize_item_name), "%s", prizes_list[prize][ITEM_NAME]);
- new query[256], player_name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, player_name, sizeof(player_name));
- format
- (
- query, sizeof(query),
- "INSERT INTO prizes_history (player_name, item_id, item_name, item_value) VALUES ('%s', %i, '%s', %i)",
- player_name, prize_item_id, prize_item_name, prize_item_value
- );
- mysql_query(db, query);
- switch (prize_item_type)
- {
- case ITEM_TYPE_MONEY: GivePlayerMoney(playerid, prize_item_value);
- case ITEM_TYPE_WEAPON: GivePlayerWeapon(playerid, prize_item_id, prize_item_value);
- case ITEM_TYPE_VEHICLE:
- {
- new Float: x, Float: y, Float: z;
- GetPlayerPos(playerid, x, y, z);
- AddStaticVehicle(prize_item_id, x + 2.0, y + 2.0, z + 1.0, 0, 1, 1);
- }
- }
- new string[144];
- format(string, sizeof(string), "Вы забрали приз: %s из коробки №%i", prize_item_name, box_id);
- SendClientMessage(playerid, -1, string);
- DestroyBox(playerid, box_id);
- }
- }
- case DIALOG_PRIZE_LIST:
- {
- if (response == 1)
- {
- current_page_prizes[playerid]--;
- DialogShowPrizesList(playerid);
- }
- else if (response == 0)
- {
- current_page_prizes[playerid]++;
- DialogShowPrizesList(playerid);
- }
- }
- }
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if (newkeys == 1024)
- {
- new player_area_id = GetPVarInt(playerid, "PLAYER_AREA_ID") -1;
- if (player_area_id != 0)
- {
- new box_id = GetBoxByArea(player_area_id);
- printf("BOX_ID: %i, player_area_id: %i", box_id, player_area_id);
- if (box_id != INVALID_BOX_ID)
- {
- ShowPlayerDialog(playerid, DIALOG_TAKE_PRIZE, DIALOG_STYLE_MSGBOX, "Подарок!", "Вы нашли подарок, открыв его обнаружили ", "Забрать", "Отказаться");
- DeletePVar(playerid, "PLAYER_AREA_ID");
- SetPVarInt(playerid, "ACTIVE_BOX_ID", box_id + 1);
- }
- }
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- SetPlayerPos(playerid, 1890.6500, 1167.9888, 29.6750);
- new player_name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, player_name, sizeof(player_name));
- new query[256];
- mysql_format(db, query, sizeof(query), "INSERT INTO `users` (`nickname`) VALUES ('%e')", player_name);
- mysql_query(db, query);
- return 1;
- }
- stock DestroyBox(playerid, box_id)
- {
- DestroyDynamicObject(STREAMER_TAG_OBJECT: boxes[box_id][AREA_ID]);
- DestroyDynamic3DTextLabel(STREAMER_TAG_3D_TEXT_LABEL: boxes[box_id][AREA_ID]);
- DestroyDynamicArea(boxes[box_id][AREA_ID]);
- DeletePVar(playerid, "ACTIVE_BOX_ID");
- return 1;
- }
- stock DialogShowPrizesList(playerid)
- {
- new player_name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, player_name, sizeof(player_name));
- new query[256];
- format(query, 256, "SELECT `item_name`, `item_value`, `timestamp` FROM prizes_history WHERE `player_name` = '%s' ORDER BY `timestamp` DESC", player_name);
- new Cache: result = mysql_query(db, query);
- new rows = cache_num_rows() - 1;
- new prize_name[MAX_LENGHT_NAME_ITEM_PRIZE], prize_value, prize_time[32], string[1024];
- new page = current_page_prizes[playerid] + 1;
- new start_row = (page -1) * MAX_PRIZE_COUNT_ON_PAGE,
- end_row = start_row + MAX_PRIZE_COUNT_ON_PAGE - 1;
- if (end_row > rows) end_row = rows;
- for (new i = start_row; i <= end_row; i++)
- {
- cache_get_value_name(i, "item_name", prize_name, sizeof(prize_name));
- cache_get_value_name_int(i, "item_value", prize_value);
- cache_get_value_name(i, "timestamp", prize_time, sizeof(prize_time));
- format(string, sizeof(string), "%s%s\t%i\t%s\n", string, prize_name, prize_value, prize_time);
- }
- new max_page = (rows / MAX_PRIZE_COUNT_ON_PAGE) + (rows % MAX_PRIZE_COUNT_ON_PAGE != 0 ? 1 : 0);
- if (page > max_page)
- {
- page = max_page;
- }
- new buttons[24], buttons2[24];
- if (page == max_page)
- {
- format(buttons, sizeof(buttons), "Предыдущая");
- format(buttons2, sizeof(buttons2), "Закрыть");
- }
- else if (page == 1)
- {
- format(buttons, sizeof(buttons), "Закрыть");
- format(buttons2, sizeof(buttons2), "Следующая");
- }
- else
- {
- format(buttons, sizeof(buttons), "Предыдущая");
- format(buttons2, sizeof(buttons2), "Следующая");
- }
- strins(string, "Приз\tКоличество\tВремя\n", 0);
- ShowPlayerDialog(playerid, DIALOG_PRIZE_LIST, DIALOG_STYLE_TABLIST_HEADERS, "Лист призов", string, buttons, buttons2);
- cache_delete(Cache: result);
- return 1;
- }
- CMD:show_prize(playerid)
- {
- DialogShowPrizesList(playerid);
- return 1;
- }
- CMD:spawn_box(playerid)
- {
- BoxInit();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement