Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Filterscript: Dynamic Gates - MySQL
- * Author: YumikoJR
- * Date: 29th February
- * Copyright (C) 2020
- * Download: github.com/YumikoJR/Dynamic-Gates
- */
- #include <a_samp>
- #include <a_mysql>
- #include <sscanf2>
- #include <easyDialog>
- #include <Pawn.CMD>
- #define YSI_YES_HEAP_MALLOC
- #include <YSI_Coding\y_timers>
- #include <YSI_Data\y_iterate>
- // > MySQL
- static
- MySQL:dbHandler;
- stock const SQL_HOST[20] = "localhost";
- stock const SQL_USER[20] = "root";
- stock const SQL_DB[20] = "gates_db";
- #define TABLE_GATES "gates"
- // > Constant
- const
- MAX_GATES = (2000);
- enum e_GATES_DATA
- {
- gSQLID,
- gObject,
- Float:gX,
- Float:gY,
- Float:gZ,
- Float:gRX,
- Float:gRY,
- Float:gRZ
- };
- static
- e_GATE_INFO[MAX_GATES][e_GATES_DATA],
- Iterator:GatesIter<MAX_GATES char>;
- public OnGameModeInit()
- {
- new
- MySQLOpt: option_id = mysql_init_options();
- dbHandler = mysql_connect(SQL_HOST, SQL_USER, "", SQL_DB, option_id);
- if (dbHandler == MYSQL_INVALID_HANDLE || mysql_errno(dbHandler) != 0)
- {
- print("[MySQL]: Can't connect to database!");
- SendRconCommand("exit");
- return 1;
- }
- printf(
- "[MySQL]: Connection successfully - [%s/%s/%s]",
- SQL_HOST, SQL_USER, SQL_DB
- );
- mysql_tquery(dbHandler, "SELECT * FROM `"TABLE_GATES"`", "g_loadGates");
- return 1;
- }
- // > Load gates
- forward g_loadGates();
- public g_loadGates()
- {
- if (!cache_num_rows())
- return print("0 gates in db!");
- for (new i; i < cache_num_rows(); ++i)
- {
- new
- id = Iter_Free(GatesIter);
- cache_get_value_name_int(i, "gSQLID", e_GATE_INFO[id][gSQLID]);
- cache_get_value_name_int(i, "gObject", e_GATE_INFO[id][gObject]);
- cache_get_value_name_float(i, "gX", e_GATE_INFO[id][gX]);
- cache_get_value_name_float(i, "gY", e_GATE_INFO[id][gY]);
- cache_get_value_name_float(i, "gZ", e_GATE_INFO[id][gZ]);
- cache_get_value_name_float(i, "gRX", e_GATE_INFO[id][gRX]);
- cache_get_value_name_float(i, "gRY", e_GATE_INFO[id][gRY]);
- cache_get_value_name_float(i, "gRZ", e_GATE_INFO[id][gRZ]);
- CreateObject(
- e_GATE_INFO[id][gObject], e_GATE_INFO[id][gX], e_GATE_INFO[id][gY], e_GATE_INFO[id][gZ], e_GATE_INFO[id][gRX], e_GATE_INFO[id][gRY], e_GATE_INFO[id][gRZ], 300.0);
- Iter_Add(GatesIter, id);
- }
- return 1;
- }
- // > Delete gates
- stock g_destroyGates()
- {
- foreach (new i: MAX_GATES)
- {
- DestroyDynamicObject(e_GATE_INFO[i][gObject]);
- }
- return 1;
- }
- // > Commands
- CMD:gate(playerid)
- {
- if (!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, 0xFF0000AA, "Niste ovlasceni!");
- Dialog_Show(playerid, "DialogGates", DIALOG_STYLE_LIST,
- "Gates >> Select",
- "Create gate\n\
- Edit gate\n\
- Delete gate",
- "Select", "Close"
- );
- return 1;
- }
- // > Dialogs
- Dialog:DialogGates(const playerid, response, listitem, inputtext[])
- {
- if (!response)
- return 1;
- switch (listitem)
- {
- case 0:
- {
- Dialog_Show(playerid, "DialogCGate", DIALOG_STYLE_INPUT,
- "Gates >> Create",
- "Enter: Gate Object ID",
- "Input", "Close"
- );
- }
- case 1:
- SelectObject(playerid);
- case 2:
- {
- Dialog_Show(playerid, "DialogDGate", DIALOG_STYLE_INPUT,
- "Gates >> Delete",
- "Enter: Gate SQL ID",
- "Input", "Close"
- );
- }
- }
- return 1;
- }
- Dialog:DialogCGate(const playerid, response, listitem, inputtext[])
- {
- if (!response)
- return 1;
- new
- Float:x,
- Float:y,
- Float:z,
- i = Iter_Free(GatesIter);
- GetPlayerPos(playerid, x, y, z);
- // pp-mysql :(
- static query[200];
- mysql_format(dbHandler, query, sizeof query, "\
- INSERT INTO `"TABLE_GATES"` \
- (`gObject`, `gX`, `gY`, `gZ`) \
- VALUES ('%d', '%f', '%f', '%f')", strval(inputtext), x, y, z
- );
- mysql_tquery(dbHandler, query);
- e_GATE_INFO[i][gSQLID] = (cache_insert_id());
- e_GATE_INFO[i][gObject] = (strval(inputtext));
- e_GATE_INFO[i][gX] = (x);
- e_GATE_INFO[i][gY] = (y);
- e_GATE_INFO[i][gZ] = (z);
- e_GATE_INFO[i][gRX] = (0.0);
- e_GATE_INFO[i][gRY] = (0.0);
- e_GATE_INFO[i][gRZ] = (0.0);
- e_GATE_INFO[i][gObject] = CreateObject(
- strval(inputtext), x, y, z, 0.0, 0.0, 0.0, 300.0);
- EditObject(playerid, e_GATE_INFO[i][gObject]);
- Iter_Add(GatesIter, i);
- return 1;
- }
- // > Editing gate
- public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
- {
- if(type == SELECT_OBJECT_GLOBAL_OBJECT)
- {
- EditObject(playerid, objectid);
- }
- else
- {
- EditPlayerObject(playerid, objectid);
- }
- return 1;
- }
- public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ )
- {
- if(response == EDIT_RESPONSE_CANCEL)
- return 1;
- if(response == EDIT_RESPONSE_FINAL)
- {
- MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
- e_GATE_INFO[objectid][gX] = (fX);
- e_GATE_INFO[objectid][gY] = (fY);
- e_GATE_INFO[objectid][gZ] = (fZ);
- e_GATE_INFO[objectid][gRX] = (fRotX);
- e_GATE_INFO[objectid][gRY] = (fRotY);
- e_GATE_INFO[objectid][gRZ] = (fRotZ);
- static query[200];
- mysql_format(dbHandler, query, sizeof query, "\
- UPDATE `"TABLE_GATES"` SET \
- `gX` = '%f', `gY` = '%f', `gZ` = '%f', `gRX` = '%f', `gRY` = '%f', `gRZ` = '%f' WHERE `gSQLID` = '%d'",
- fX, fY, fZ, fRotX, fRotY, fRotZ, e_GATE_INFO[objectid][gSQLID]
- );
- mysql_tquery(dbHandler, query);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement