Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- __
- [ | _
- _ .--..--. _ .--..--. _ .--. | | / ]
- [ `.-. .-. | [ `.-. .-. | [ `/'`\]| '' <
- | | | | | | | | | | | | | | | |`\ \
- [___||__||__][___||__||__][___] [__| \_]
- Version 1.0.1
- */
- #include <a_samp>
- #include <a_mysql>
- #include <sscanf2>
- #include <zcmd>
- //= = = = = = = = = = = = = = = = = = =
- #define COLOR_GRAD1 0xB4B5B7FF
- #define COLOR_DBLUE 0x0073FFEB
- #define COLOR_GREEN 0x7BDDA5AA
- #define CHECKPOINT_RADIUS 2.0
- //= = = = = = = = = = = = = = = = = = =
- #define MYSQL_HOST "localhost"
- #define MYSQL_USER "root"
- #define MYSQL_PASS ""
- #define MYSQL_DB "samp"
- //= = = = = = = = = = = = = = = = = = =
- /*
- // Mysql table
- CREATE TABLE IF NOT EXISTS `m_gps` (
- `GPSID` int(11) NOT NULL auto_increment,
- `Asukoht` varchar(42) NOT NULL,
- `X` float NOT NULL,
- `Y` float NOT NULL,
- `Z` float NOT NULL,
- PRIMARY KEY (`GPSID`),
- UNIQUE KEY `Asukoht` (`Asukoht`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
- */
- public OnFilterScriptInit()
- {
- MySQLConnect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
- print("______________________________");
- print(" GPS system with mysql loaded");
- print("______________________________");
- return 1;
- }
- public OnFilterScriptExit() return 1;
- CMD:addloc(playerid, params[])
- {
- new
- g_Query[128],
- g_Escaped[24],
- Float:X,
- Float:Y,
- Float:Z
- ;
- if(!IsPlayerAdmin(playerid)) return 0;
- if(isnull(params)) return SendClientMessage(playerid, COLOR_GRAD1, "* USAGE: /addloc [locationname]");
- GetPlayerPos(playerid, X, Y, Z);
- //============================( Check if place already exists )=====================================
- mysql_real_escape_string(params, g_Escaped); // security
- format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
- mysql_query(g_Query);
- mysql_store_result();
- if(mysql_num_rows() == 1) return SendClientMessage(playerid, COLOR_GREEN, "* Location already exists!");
- mysql_free_result();
- //===================================================================================
- mysql_real_escape_string(params, g_Escaped); // security
- format(g_Query, sizeof(g_Query), "INSERT INTO `m_gps` (`GPSID`,`Asukoht`,`X`,`Y`,`Z`) VALUES (NULL, '%s', %f, %f, %f)", g_Escaped, X, Y, Z);
- mysql_query(g_Query);
- //============================( Display new location message )=======================================
- format(g_Query, sizeof(g_Query), "* GPS Location %s (ID: %d) added to database!", g_Escaped, mysql_insert_id());
- SendClientMessage(playerid, COLOR_DBLUE, g_Query);
- return true;
- }
- CMD:editloc(playerid, params[])
- {
- new
- g_Escaped[24],
- g_Query[128],
- newloc[24],
- sql[128],
- loc[10],
- Float:X,
- Float:Y,
- Float:Z
- ;
- if(!IsPlayerAdmin(playerid)) return 0;
- if(sscanf(params, "s[10]s[24]S(puudub)[24]",loc, params, newloc)) return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /editloc [coords | name] [locationname]");
- if(!strcmp(loc, "name", true)) if(!strcmp(newloc, "puudub", true)) return SendClientMessage(playerid, COLOR_GREEN, "USAGE: /editloc name [oldname] [newname]");
- if(!strcmp(loc, "coords", true))
- {
- if(!strcmp(newloc, "puudub", true))
- {
- GetPlayerPos(playerid, X, Y, Z);
- mysql_real_escape_string(params, g_Escaped); // security
- //=======================================================================================================
- format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
- mysql_query(g_Query);
- mysql_store_result();
- if(mysql_num_rows() == 1)
- {
- format(sql, sizeof(sql), "UPDATE `m_gps` SET `X` = '%f', `Y` = '%f', `Z` = '%f'", X, Y, Z);
- mysql_query(sql);
- }
- else return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
- mysql_fetch_row(g_Query);
- mysql_free_result();
- //=======================================================================================================
- format(g_Query, sizeof(g_Query), "* GPS location %s changed to %.3f, %.3f, %.3f", params, X, Y, Z);
- SendClientMessage(playerid, COLOR_GRAD1, g_Query);
- }
- }
- else if(!strcmp(loc, "name", true))
- {
- //=======================================================================================================
- mysql_real_escape_string(params, g_Escaped); // security
- format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
- mysql_query(g_Query);
- mysql_store_result();
- if(mysql_num_rows() == 1)
- {
- mysql_real_escape_string(newloc, g_Escaped); // security
- format(sql, sizeof(sql), "UPDATE `m_gps` SET `Asukoht` = '%s'", g_Escaped);
- mysql_query(sql);
- }
- else return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
- mysql_fetch_row(g_Query);
- mysql_free_result();
- //=======================================================================================================
- format(g_Query, sizeof(g_Query), "* GPS locationname %s changed to %s",params, g_Escaped);
- SendClientMessage(playerid, COLOR_GRAD1, g_Query);
- }
- return 1;
- }
- CMD:delloc(playerid, params[])
- {
- new
- g_Escaped[24],
- g_Query[128],
- sql[128]
- ;
- if(!IsPlayerAdmin(playerid)) return 0;
- if(isnull(params)) return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /delloc [locationname]");
- //=======================================================================================================
- mysql_real_escape_string(params, g_Escaped); // security
- format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
- mysql_query(g_Query);
- mysql_store_result();
- if(mysql_num_rows() == 1)
- {
- format(sql, sizeof(sql), "DELETE FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", params);
- mysql_query(sql);
- }
- else return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
- mysql_fetch_row(g_Query);
- mysql_free_result();
- //=======================================================================================================
- format(g_Query, sizeof(g_Query), "* GPS location %s deleted.", params);
- SendClientMessage(playerid, COLOR_GRAD1, g_Query);
- return 1;
- }
- CMD:find(playerid, params[])
- {
- new
- g_Escaped[24],
- g_Query[128],
- Float:X,
- Float:Y,
- Float:Z,
- gpsid
- ;
- if(isnull(params)) return SendClientMessage( playerid, COLOR_GRAD1, "* USAGE: /find [location name]" );
- mysql_real_escape_string(params, g_Escaped); // security
- format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
- mysql_query(g_Query);
- mysql_store_result();
- if(mysql_num_rows() == 0) return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
- mysql_fetch_row(g_Query);
- mysql_free_result();
- sscanf(g_Query, "p<|>is[42]fff", gpsid, params, X, Y, Z);
- SetPlayerCheckpoint(playerid, X, Y, Z, CHECKPOINT_RADIUS);
- format(g_Query, sizeof(g_Query), "* Location %s (id: %d) added to your minimap!", params, gpsid);
- SendClientMessage(playerid, COLOR_DBLUE, g_Query);
- return true;
- }
- forward MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[]);
- public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[])
- {
- print("MYSQL: Trying to connect to server...");
- mysql_connect(sqlhost, sqluser, sqldb,sqlpass);
- if(mysql_ping() == 1)
- {
- print("MYSQL: Connected.");
- return 1;
- }
- else
- {
- print("MYSQL: Error connecting to server, retrying...");
- mysql_connect(sqlhost, sqluser, sqldb,sqlpass);
- if(mysql_ping() == 1)
- {
- print("MYSQL: Reconnected.");
- return 1;
- }
- else
- {
- print("MYSQL: Could not reconnect to server, terminating server...");
- SendRconCommand("exit");
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment