Guest User

mmrk

a guest
Nov 26th, 2010
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.73 KB | None | 0 0
  1. /*
  2.                        __      
  3.                       [  |  _  
  4.      _ .--..--.   _ .--..--.   _ .--. | | / ]  
  5.     [ `.-. .-. | [ `.-. .-. | [ `/'`\]| '' <  
  6.      | | | | | |  | | | | | |  | |    | |`\ \  
  7.     [___||__||__][___||__||__][___]  [__|  \_]
  8.    
  9.     Version 1.0.1
  10.  */
  11.  
  12. #include <a_samp>
  13. #include <a_mysql>
  14. #include <sscanf2>
  15. #include <zcmd>
  16. //= = = = = = = = = = = = = = = = = = =
  17. #define COLOR_GRAD1         0xB4B5B7FF
  18. #define COLOR_DBLUE     0x0073FFEB
  19. #define COLOR_GREEN         0x7BDDA5AA
  20. #define CHECKPOINT_RADIUS   2.0
  21. //= = = = = = = = = = = = = = = = = = =
  22. #define MYSQL_HOST  "localhost"
  23. #define MYSQL_USER  "root"
  24. #define MYSQL_PASS  ""
  25. #define MYSQL_DB    "samp"
  26. //= = = = = = = = = = = = = = = = = = =
  27. /*
  28.     // Mysql table
  29.    
  30.     CREATE TABLE IF NOT EXISTS `m_gps` (
  31.       `GPSID` int(11) NOT NULL auto_increment,
  32.       `Asukoht` varchar(42) NOT NULL,
  33.       `X` float NOT NULL,
  34.       `Y` float NOT NULL,
  35.       `Z` float NOT NULL,
  36.       PRIMARY KEY  (`GPSID`),
  37.       UNIQUE KEY `Asukoht` (`Asukoht`)
  38.     ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  39.  
  40. */
  41. public OnFilterScriptInit()
  42. {
  43.     MySQLConnect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
  44.     print("______________________________");
  45.     print("     GPS system with mysql loaded");
  46.     print("______________________________");
  47.     return 1;
  48. }
  49. public OnFilterScriptExit() return 1;
  50.  
  51. CMD:addloc(playerid, params[])
  52. {
  53.     new
  54.         g_Query[128],
  55.         g_Escaped[24],
  56.         Float:X,
  57.         Float:Y,
  58.         Float:Z
  59.     ;
  60.     if(!IsPlayerAdmin(playerid)) return 0;
  61.     if(isnull(params)) return SendClientMessage(playerid, COLOR_GRAD1, "* USAGE: /addloc [locationname]");
  62.     GetPlayerPos(playerid, X, Y, Z);
  63.     //============================( Check if place already exists )=====================================
  64.     mysql_real_escape_string(params, g_Escaped); // security
  65.     format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
  66.         mysql_query(g_Query);
  67.         mysql_store_result();
  68.     if(mysql_num_rows() == 1) return SendClientMessage(playerid, COLOR_GREEN, "* Location already exists!");
  69.     mysql_free_result();
  70.     //===================================================================================
  71.     mysql_real_escape_string(params, g_Escaped); // security
  72.     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);
  73.     mysql_query(g_Query);
  74.     //============================( Display new location message )=======================================
  75.     format(g_Query, sizeof(g_Query), "* GPS Location %s (ID: %d) added to database!", g_Escaped, mysql_insert_id());
  76.     SendClientMessage(playerid, COLOR_DBLUE, g_Query);
  77.     return true;
  78. }
  79. CMD:editloc(playerid, params[])
  80. {
  81.     new
  82.         g_Escaped[24],
  83.         g_Query[128],
  84.         newloc[24],
  85.         sql[128],
  86.         loc[10],
  87.         Float:X,
  88.         Float:Y,
  89.         Float:Z
  90.     ;
  91.     if(!IsPlayerAdmin(playerid)) return 0;
  92.     if(sscanf(params, "s[10]s[24]S(puudub)[24]",loc, params, newloc)) return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /editloc [coords | name] [locationname]");
  93.    
  94.     if(!strcmp(loc, "name", true)) if(!strcmp(newloc, "puudub", true)) return SendClientMessage(playerid, COLOR_GREEN, "USAGE: /editloc name [oldname] [newname]");
  95.     if(!strcmp(loc, "coords", true))
  96.     {
  97.         if(!strcmp(newloc, "puudub", true))
  98.         {
  99.             GetPlayerPos(playerid, X, Y, Z);
  100.             mysql_real_escape_string(params, g_Escaped); // security
  101.             //=======================================================================================================
  102.             format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
  103.             mysql_query(g_Query);
  104.             mysql_store_result();
  105.             if(mysql_num_rows() == 1)
  106.             {
  107.                 format(sql, sizeof(sql), "UPDATE `m_gps` SET `X` = '%f', `Y` = '%f', `Z` = '%f'", X, Y, Z);
  108.                 mysql_query(sql);
  109.             }
  110.             else return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
  111.             mysql_fetch_row(g_Query);
  112.             mysql_free_result();
  113.             //=======================================================================================================
  114.             format(g_Query, sizeof(g_Query), "* GPS location %s changed to %.3f, %.3f, %.3f", params, X, Y, Z);
  115.             SendClientMessage(playerid, COLOR_GRAD1, g_Query);
  116.         }
  117.     }
  118.     else if(!strcmp(loc, "name", true))
  119.     {
  120.         //=======================================================================================================
  121.         mysql_real_escape_string(params, g_Escaped); // security
  122.         format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
  123.         mysql_query(g_Query);
  124.         mysql_store_result();
  125.         if(mysql_num_rows() == 1)
  126.         {
  127.             mysql_real_escape_string(newloc, g_Escaped); // security
  128.             format(sql, sizeof(sql), "UPDATE `m_gps` SET `Asukoht` = '%s'", g_Escaped);
  129.             mysql_query(sql);
  130.         }
  131.         else return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
  132.         mysql_fetch_row(g_Query);
  133.         mysql_free_result();
  134.         //=======================================================================================================
  135.         format(g_Query, sizeof(g_Query), "* GPS locationname %s changed to %s",params, g_Escaped);
  136.         SendClientMessage(playerid, COLOR_GRAD1, g_Query);
  137.     }
  138.     return 1;
  139. }
  140. CMD:delloc(playerid, params[])
  141. {
  142.     new
  143.         g_Escaped[24],
  144.         g_Query[128],
  145.         sql[128]
  146.     ;
  147.     if(!IsPlayerAdmin(playerid)) return 0;
  148.     if(isnull(params)) return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /delloc [locationname]");
  149.     //=======================================================================================================
  150.     mysql_real_escape_string(params, g_Escaped); // security
  151.     format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
  152.     mysql_query(g_Query);
  153.     mysql_store_result();
  154.     if(mysql_num_rows() == 1)
  155.     {
  156.         format(sql, sizeof(sql), "DELETE FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", params);
  157.         mysql_query(sql);
  158.     }
  159.     else return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
  160.     mysql_fetch_row(g_Query);
  161.     mysql_free_result();
  162.     //=======================================================================================================
  163.     format(g_Query, sizeof(g_Query), "* GPS location %s deleted.", params);
  164.     SendClientMessage(playerid, COLOR_GRAD1, g_Query);
  165.     return 1;
  166. }
  167. CMD:find(playerid, params[])
  168. {
  169.     new
  170.         g_Escaped[24],
  171.         g_Query[128],
  172.         Float:X,
  173.         Float:Y,
  174.         Float:Z,
  175.         gpsid
  176.     ;
  177.     if(isnull(params)) return SendClientMessage( playerid, COLOR_GRAD1, "* USAGE: /find [location name]" );
  178.     mysql_real_escape_string(params, g_Escaped); // security
  179.     format(g_Query, sizeof(g_Query), "SELECT * FROM `m_gps` WHERE LOWER(Asukoht) = LOWER('%s')", g_Escaped);
  180.     mysql_query(g_Query);
  181.     mysql_store_result();
  182.     if(mysql_num_rows() == 0) return SendClientMessage(playerid, COLOR_GREEN, "* Could not find that location!");
  183.     mysql_fetch_row(g_Query);
  184.     mysql_free_result();
  185.     sscanf(g_Query, "p<|>is[42]fff", gpsid, params, X, Y, Z);
  186.     SetPlayerCheckpoint(playerid, X, Y, Z, CHECKPOINT_RADIUS);
  187.     format(g_Query, sizeof(g_Query), "* Location %s (id: %d) added to your minimap!", params, gpsid);
  188.     SendClientMessage(playerid, COLOR_DBLUE, g_Query);
  189.     return true;
  190. }
  191.  
  192. forward MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[]);
  193. public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[])
  194. {
  195.     print("MYSQL: Trying to connect to server...");
  196.     mysql_connect(sqlhost, sqluser, sqldb,sqlpass);
  197.     if(mysql_ping() == 1)
  198.     {
  199.         print("MYSQL: Connected.");
  200.         return 1;
  201.     }
  202.     else
  203.     {
  204.         print("MYSQL: Error connecting to server, retrying...");
  205.         mysql_connect(sqlhost, sqluser, sqldb,sqlpass);
  206.         if(mysql_ping() == 1)
  207.         {
  208.             print("MYSQL: Reconnected.");
  209.             return 1;
  210.         }
  211.         else
  212.         {
  213.             print("MYSQL: Could not reconnect to server, terminating server...");
  214.             SendRconCommand("exit");
  215.             return 0;
  216.         }
  217.     }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment