SHARE
TWEET

GPS System

a guest Jun 20th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define MAX_GPS_LOCATIONS (20)
  2. new LocationData[MAX_PLAYERS][MAX_GPS_LOCATIONS][locationData];
  3.  
  4.     {"GPS System", 18875},//Inventory
  5.  
  6.  
  7. Location_Add(playerid, name[], Float:x, Float:y, Float:z)
  8. {
  9.     new
  10.         query[192];
  11.  
  12.     for (new i = 0; i != MAX_GPS_LOCATIONS; i ++) if (!LocationData[playerid][i][locationExists])
  13.     {
  14.         LocationData[playerid][i][locationExists] = true;
  15.         format(LocationData[playerid][i][locationName], 32, name);
  16.  
  17.         LocationData[playerid][i][locationPos][0] = x;
  18.         LocationData[playerid][i][locationPos][1] = y;
  19.         LocationData[playerid][i][locationPos][2] = z;
  20.  
  21.         format(query, sizeof(query), "INSERT INTO `gps` (`ID`, `locationName`, `locationX`, `locationY`, `locationZ`) VALUES('%d', '%s', '%.4f', '%.4f', '%.4f')", PlayerData[playerid][pID], SQL_ReturnEscaped(name), x, y, z);
  22.         mysql_tquery(g_iHandle, query, "OnLocationCreated", "dd", playerid, i);
  23.  
  24.         return i;
  25.     }
  26.     return -1;
  27. }
  28.  
  29. Location_GetID(playerid, name[])
  30. {
  31.     for (new i = 0; i != MAX_GPS_LOCATIONS; i ++) if (LocationData[playerid][i][locationExists] && !strcmp(LocationData[playerid][i][locationName], name, true)) {
  32.         return i;
  33.     }
  34.     return -1;
  35. }
  36.  
  37. Location_Delete(playerid, name[])
  38. {
  39.     new
  40.         query[96];
  41.  
  42.     for (new i = 0; i != MAX_GPS_LOCATIONS; i ++) if (LocationData[playerid][i][locationExists] && !strcmp(LocationData[playerid][i][locationName], name))
  43.     {
  44.         LocationData[playerid][i][locationExists] = false;
  45.  
  46.         LocationData[playerid][i][locationPos][0] = 0.0;
  47.         LocationData[playerid][i][locationPos][1] = 0.0;
  48.         LocationData[playerid][i][locationPos][2] = 0.0;
  49.  
  50.         format(query, sizeof(query), "DELETE FROM `gps` WHERE `ID` = '%d' AND `locationID` = '%d'", PlayerData[playerid][pID], LocationData[playerid][i][locationID]);
  51.         mysql_tquery(g_iHandle, query);
  52.         return 1;
  53.     }
  54.     return 0;
  55. }
  56.  
  57. //Under ResetStatistics(playerid) (if you have one)
  58.     for (new i = 0; i != MAX_GPS_LOCATIONS; i ++) {
  59.         LocationData[playerid][i][locationExists] = false;
  60.         LocationData[playerid][i][locationID] = 0;
  61.     }
  62.  
  63. //Under public OnQueryFinished(extraid, threadid)
  64.         case THREAD_LOAD_LOCATIONS:
  65.         {
  66.             cache_get_data(rows, fields, g_iHandle);
  67.  
  68.             for (new i = 0; i < rows && i < MAX_GPS_LOCATIONS; i ++) {
  69.                 cache_get_field_content(i, "locationName", LocationData[extraid][i][locationName], g_iHandle, 32);
  70.  
  71.                 LocationData[extraid][i][locationExists] = true;
  72.                 LocationData[extraid][i][locationID] = cache_get_field_int(i, "locationID");
  73.                 LocationData[extraid][i][locationPos][0] = cache_get_field_float(i, "locationX");
  74.                 LocationData[extraid][i][locationPos][1] = cache_get_field_float(i, "locationY");
  75.                 LocationData[extraid][i][locationPos][2] = cache_get_field_float(i, "locationZ");
  76.             }
  77.         }
  78.  
  79. //Under public OnDeleteCharacter(playerid, name[])
  80.         format(query, sizeof(query), "DELETE FROM `gps` WHERE `ID` = '%d'", id);
  81.         mysql_tquery(g_iHandle, query);
  82.  
  83.  
  84. Dialog:MainGPS(playerid, response, listitem, inputtext[])
  85. {
  86.     if (response)
  87.     {
  88.         switch (listitem)
  89.         {
  90.             case 0:
  91.             {
  92.                 static
  93.                     string[MAX_GPS_LOCATIONS * 32];
  94.  
  95.                 string = "Add Location\n";
  96.  
  97.                 for (new i = 0; i != MAX_GPS_LOCATIONS; i ++) if (LocationData[playerid][i][locationExists]) {
  98.                     format(string, sizeof(string), "%s%s\n", string, LocationData[playerid][i][locationName]);
  99.                 }
  100.                 Dialog_Show(playerid, CustomLocations, DIALOG_STYLE_LIST, "Custom Locations", string, "Select", "Back");
  101.             }
  102.         }
  103.     }
  104.     return 1;
  105. }
  106.  
  107. Dialog:CustomLocations(playerid, response, listitem, inputtext[])
  108. {
  109.     if (response)
  110.     {
  111.         if (!listitem) {
  112.             Dialog_Show(playerid, AddLocation, DIALOG_STYLE_INPUT, "Add Location", "Please enter the desired name of the location below:", "Submit", "Cancel");
  113.         }
  114.         else
  115.         {
  116.             new id = Location_GetID(playerid, inputtext);
  117.  
  118.             if (id != -1) {
  119.                 PlayerData[playerid][pSelectedSlot] = id;
  120.  
  121.                 Dialog_Show(playerid, LocationInfo, DIALOG_STYLE_LIST, inputtext, "Set Waypoint\nDelete Location", "Select", "Back");
  122.             }
  123.         }
  124.     }
  125.     else cmd_gps(playerid, "\1");
  126.     return 1;
  127. }
  128.  
  129. Dialog:AddLocation(playerid, response, listitem, inputtext[])
  130. {
  131.     if (response)
  132.     {
  133.         if (isnull(inputtext))
  134.             return Dialog_Show(playerid, AddLocation, DIALOG_STYLE_INPUT, "Add Location", "Please enter the desired name of the location below:", "Submit", "Cancel");
  135.  
  136.         if (strlen(inputtext) > 32)
  137.             return Dialog_Show(playerid, AddLocation, DIALOG_STYLE_INPUT, "Add Location", "Error: The name can't exceed 32 characters.\n\nPlease enter the desired name of the location below:", "Submit", "Cancel");
  138.  
  139.         static
  140.             Float:fX,
  141.             Float:fY,
  142.             Float:fZ,
  143.             id = -1;
  144.  
  145.         if ((id = House_Inside(playerid)) != -1) {
  146.             fX = HouseData[id][housePos][0];
  147.             fY = HouseData[id][housePos][1];
  148.             fZ = HouseData[id][housePos][2];
  149.         }
  150.         else if ((id = Business_Inside(playerid)) != -1) {
  151.             fX = BusinessData[id][bizPos][0];
  152.             fY = BusinessData[id][bizPos][1];
  153.             fZ = BusinessData[id][bizPos][2];
  154.         }
  155.         else if ((id = Entrance_Inside(playerid)) != -1) {
  156.             fX = EntranceData[id][entrancePos][0];
  157.             fY = EntranceData[id][entrancePos][1];
  158.             fZ = EntranceData[id][entrancePos][2];
  159.         }
  160.         else GetPlayerPos(playerid, fX, fY, fZ);
  161.  
  162.         Location_Add(playerid, inputtext, fX, fY, fZ);
  163.         SendServerMessage(playerid, "You have added \"%s\" to your GPS.", inputtext);
  164.     }
  165.     else cmd_gps(playerid, "\1");
  166.     return 1;
  167. }
  168.  
  169. Dialog:LocationInfo(playerid, response, listitem, inputtext[])
  170. {
  171.     if (response)
  172.     {
  173.         new id = PlayerData[playerid][pSelectedSlot];
  174.  
  175.         switch (listitem)
  176.         {
  177.             case 0:
  178.             {
  179.                 Waypoint_Set(playerid, LocationData[playerid][id][locationName], LocationData[playerid][id][locationPos][0], LocationData[playerid][id][locationPos][1], LocationData[playerid][id][locationPos][2]);
  180.                 SendServerMessage(playerid, "Waypoint set to \"%s\" (marked on radar).", LocationData[playerid][id][locationName]);
  181.             }
  182.             case 1:
  183.             {
  184.                 SendServerMessage(playerid, "You have removed \"%s\" from your GPS.", LocationData[playerid][id][locationName]);
  185.  
  186.                 Location_Delete(playerid, LocationData[playerid][id][locationName]);
  187.                 dialog_MainGPS(playerid, 1, 4, "\1");
  188.             }
  189.         }
  190.     }
  191.     else dialog_MainGPS(playerid, 1, 4, "\1");
  192.     return 1;
  193. }
  194.  
  195. CMD:creategps(playerid, params[])
  196. {
  197.     if (!Inventory_HasItem(playerid, "GPS System"))
  198.         return SendErrorMessage(playerid, "You must have a GPS system to use this.");
  199.  
  200.     if (PlayerData[playerid][pInjured])
  201.         return SendErrorMessage(playerid, "You can't use this command at the moment.");
  202.  
  203.     Dialog_Show(playerid, MainGPS, DIALOG_STYLE_LIST, "GPS System", "Locations", "Select", "Cancel");
  204.     return 1;
  205. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top