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;
- forward Database_connect();
- public Database_connect()
- {
- db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
- mysql_set_charset("cp1251");
- return 1;
- }
- #define BOX_ENABLED
- #define MAX_PRIZE_COUNT (6)
- #define MAX_BOXES_COUNT (3)
- #define MAX_LENGHT_NAME_ITEM_PRIZE (64)
- #define ITEM_MONEY (16)
- new area;
- enum E_BOX_STRUCT
- {
- 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 }
- };
- 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;
- }
- 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_AREA_ID] = area_id;
- printf("[Boxes] Box Init coord x: %f, y: %f, z: %f, area: %i", x, y, z, area_id);
- }
- }
- public OnGameModeInit()
- {
- SetGameModeText("Test");
- BoxInit();
- return 1;
- }
- public OnPlayerEnterDynamicArea(playerid, STREAMER_TAG_AREA: areaid)
- {
- area = areaid;
- new string[144];
- format(string, sizeof(string), "Player: %i, Area: %i", playerid, areaid);
- SendClientMessage(playerid, -1, string);
- return 1;
- }
- public OnPlayerLeaveDynamicArea(playerid, STREAMER_TAG_AREA: areaid)
- {
- area = 0;
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if (newkeys == 1024 && area != 0)
- {
- ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Подарок!", "Вы нашли подарок, открыв его обнаружили ", "Забрать", "Отказаться");
- }
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- 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 q_string[256];
- mysql_format(db, q_string, sizeof(q_string), "INSERT INTO `users` (`nickname`) VALUES ('%e')", player_name);
- mysql_query(db, q_string);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if (response)
- {
- new prize = random(MAX_PRIZE_COUNT);
- new prize_item_name[64];
- new prize_item_value = prizes_list[prize][PS_ITEM_VALUE];
- new prize_item_id = prizes_list[prize][PS_ITEM_ID];
- new 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];
- new player_name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, player_name, sizeof(player_name));
- mysql_format(
- db, query, sizeof(query),
- "INSERT INTO `prizes_history` (`player_name`, `item_id`, `item_name`, `item_value`) VALUES ('%e', '%i', '%e', '%i')",
- player_name, prize_item_id, prize_item_name, prize_item_value
- );
- mysql_query(db, query);
- switch (prize_item_type)
- {
- case ITEM_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", prize_item_name);
- SendClientMessage(playerid, -1, string);
- }
- else
- {
- SendClientMessage(playerid, -1, "Вы отказались от приза");
- }
- DestroyDynamicObject(area);
- DestroyDynamic3DTextLabel(STREAMER_TAG_3D_TEXT_LABEL: area);
- DestroyDynamicArea(area);
- }
- CMD:show_prize(playerid)
- {
- new player_name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, player_name, sizeof(player_name));
- printf("Player name: %s\n", player_name);
- new query[256];
- mysql_format(db, query, 256, "SELECT * FROM prizes_history WHERE `player_name`='%s'", player_name);
- new Cache: result = mysql_query(db, query), rows = cache_num_rows(); rows--;
- for (new i; i <= rows; i++)
- {
- new prize_name[256], prize_value[24], prize_time[256];
- cache_get_value_name(i, "prize_name", prize_name, sizeof(prize_name));
- cache_get_value_name(i, "prize_value", prize_value, sizeof(prize_value));
- cache_get_value_name(i, "timestamp", prize_time, sizeof(prize_time));
- new string[256]; format(string, sizeof(string), "Приз: %s, Количество: %i, Время: %s", 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