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 INVALID_BOX_ID (-1)
- enum E_BOX_STRUCT
- {
- BS_ID,
- Float: BS_POS_X,
- Float: BS_POS_Y,
- Float: BS_POS_Z,
- BS_AREA_ID
- };
- new boxes[MAX_BOXES_COUNT][E_BOX_STRUCT] =
- {
- { 1899.2340, 1177.8785, 30.0135, INVALID_STREAMER_ID },
- { 1879.9230, 1168.1254, 30.0106, INVALID_STREAMER_ID },
- { 1886.7753, 1182.9382, 30.0087, INVALID_STREAMER_ID }
- };
- enum
- {
- ITEM_TYPE_MONEY,
- ITEM_TYPE_WEAPON,
- ITEM_TYPE_VEHICLE
- }
- enum E_PRIZE_STRUCT
- {
- PS_ITEM_TYPE,
- PS_ITEM_ID,
- PS_ITEM_NAME[MAX_LENGHT_NAME_ITEM_PRIZE],
- PS_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", 50_000 },
- { ITEM_TYPE_MONEY, 0, "Деньги в размере 100 000", 100_000 },
- { ITEM_TYPE_MONEY, 0, "Деньги в размере 200 000", 200_000 },
- { ITEM_TYPE_VEHICLE, 400, "BMW X5", -1 }
- };
- enum
- {
- DIALOG_PRIZE_LIST
- }
- public OnGameModeInit()
- {
- SetGameModeText("Test");
- Database_connect();
- BoxInit();
- return 1;
- }
- forward Database_connect();
- public Database_connect()
- {
- db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
- mysql_set_charset("cp1251");
- if (mysql_errno()) {
- printf("Произошла ошибка при подключении к базе данных.");
- SendRconCommand("exit");
- return 0;
- }
- return 1;
- }
- stock BoxInit()
- {
- for (new i = 0; i < MAX_BOXES_COUNT; i++)
- {
- new Float: x = boxes[i][BS_POS_X],
- Float: y = boxes[i][BS_POS_Y],
- Float: z = boxes[i][BS_POS_Z];
- new area_id = CreateBox(x, y, z);
- boxes[i][BS_ID] = i;
- boxes[i][BS_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(playerid, area_id)
- {
- for (new i = 0; i < MAX_BOXES_COUNT; i++)
- {
- new box_area_id = boxes[i][BS_AREA_ID];
- if (area_id == box_area_id)
- {
- return i;
- }
- }
- return INVALID_BOX_ID;
- }
- public OnPlayerLeaveDynamicArea(playerid, STREAMER_TAG_AREA: areaid)
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if (newkeys == 1024)
- {
- new player_area_id = GetPVarInt(playerid, "PLAYER_AREA_ID");
- if (player_area_id != 0)
- {
- new box_id = GetBoxByArea(playerid, 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);
- }
- }
- }
- 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;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch (dialogid)
- {
- case DIALOG_PRIZE_LIST:
- {
- if (response)
- {
- new box_id = GetPVarInt(playerid, "ACTIVE_BOX_ID"),
- prize = random(MAX_PRIZE_COUNT);
- new prize_item_name[MAX_LENGHT_NAME_ITEM_PRIZE],
- prize_item_value = prizes_list[prize][PS_ITEM_VALUE],
- prize_item_id = prizes_list[prize][PS_ITEM_ID],
- prize_item_type = prizes_list[prize][PS_ITEM_TYPE];
- format(prize_item_name, sizeof(prize_item_name), "%s", prizes_list[prize][PS_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`, `timestamp`) VALUES ('%s', %i, '%s', %i, %i)",
- player_name, prize_item_id, prize_item_name, prize_item_value, gettime()
- );
- 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(box_id);
- }
- }
- // case n: ...
- }
- }
- stock DestroyBox(box_id)
- {
- DestroyDynamicObject(boxes[box_id][BS_AREA_ID]);
- DestroyDynamic3DTextLabel(boxes[box_id][BS_AREA_ID]);
- DestroyDynamicArea(boxes[box_id][BS_AREA_ID]);
- DeletePVar(playerid, "ACTIVE_BOX_ID");
- return 1;
- }
- CMD:show_prize(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'", player_name);
- new Cache: result = mysql_query(db, query),
- rows = cache_num_rows() - 1;
- new prize_name[MAX_LENGHT_NAME_ITEM_PRIZE], prize_value, prize_time, string[256];
- for (new i; i <= rows; 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_int(i, "timestamp", prize_time);
- format(string, sizeof(string), "Приз: %s, Количество: %i, Время: %i", prize_name, prize_value, prize_time);
- printf("INFO: %s", string);
- }
- cache_delete(Cache: result);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement