Advertisement
Gireada

GPS Dynamic System

Jun 23rd, 2013
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.40 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3. #include <sscanf2>
  4. #include <zcmd>
  5.  
  6. #define MAX_LOCATIONS 50//cate locatii vrei
  7. #define DIALOG_GPS  90
  8.  
  9. enum GPSDATA
  10. {
  11.     ID,
  12.     Name[50],
  13.     Float:Posx,
  14.     Float:Posy,
  15.     Float:Posz,
  16. }
  17. new GPSInfo[MAX_LOCATIONS][GPSDATA];
  18.  
  19. public OnFilterScriptInit()
  20. {
  21.     LoadGPS();
  22.     print("\n--------------------------------------");
  23.     print(" GPS Dynamic System by Gireada");
  24.     print("--------------------------------------\n");
  25.     //SetTimer("SaveGPS", 2000, 1);
  26.     return 1;
  27. }
  28.  
  29. public OnFilterScriptExit()
  30. {
  31.     return 1;
  32. }
  33.  
  34.  
  35. main()
  36. {
  37.     print("\n----------------------------------");
  38.     print(" GPS Dynamic System by Gireada");
  39.     print("----------------------------------\n");
  40. }
  41.  
  42. CMD:addlocations(playerid, params[])
  43. {
  44.     new name[50],file[256];
  45.     if(!(IsPlayerAdmin(playerid))) return SendClientMessage(playerid, 0xFFFFFFFF, "You need to be RCON Admim to use this command.");
  46.     if(unformat(params, "s[50]", name)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /addlocations <name>");
  47.     new Float:x,Float:y,Float:z;
  48.     GetPlayerPos(playerid, x,y,z);
  49.     for(new i=0;i<MAX_LOCATIONS;i++)
  50.     {
  51.         format(file,sizeof(file), "GPS/%i.ini",i);
  52.         if(!(dini_Exists(file)))
  53.         {
  54.             dini_Create(file);
  55.             CreateGPSLocation(i,name, x,y,z);break;
  56.         }
  57.     }
  58.     return 1;
  59. }
  60.  
  61. forward ShowPlayerLocation(playerid);
  62. public ShowPlayerLocation(playerid)
  63. {
  64.     new string[1024],string2[256],file[256];
  65.     for(new i=0;i<MAX_LOCATIONS;i++)
  66.     {
  67.         format(file,sizeof(file), "GPS/%i.ini",i);
  68.         if(dini_Exists(file))
  69.         {
  70.             if(i==0)
  71.             {
  72.                 format(string2, sizeof(string2), "ID:%d | Location: %s",i,GPSInfo[i][Name]);
  73.                 strcat(string, string2);
  74.             }
  75.             else
  76.             {
  77.                 format(string2, sizeof(string2), "\nID:%d | Location: %s",i,GPSInfo[i][Name]);
  78.                 strcat(string, string2);
  79.             }
  80.         }
  81.         else break;
  82.     }
  83.     ShowPlayerDialog(playerid, DIALOG_GPS, DIALOG_STYLE_LIST, "GPS LOCATION", string, "Accept", "Cancel");
  84.     return 1;
  85. }
  86.  
  87. CMD:gps(playerid, params[])
  88. {
  89.     SetPlayerVirtualWorld(playerid, 0);
  90.     ShowPlayerLocation(playerid);
  91.     return 1;
  92. }
  93.  
  94. public OnPlayerEnterCheckpoint(playerid)
  95. {
  96.     for(new i=0;i<MAX_LOCATIONS;i++)
  97.     {
  98.         if(IsPlayerInRangeOfPoint(playerid, 2.0, GPSInfo[i][Posx], GPSInfo[i][Posy], GPSInfo[i][Posz]))
  99.         {
  100.             SendClientMessage(playerid, 0xFFFFFFFF,"Here is your locations");
  101.             DisablePlayerCheckpoint(playerid);
  102.         }
  103.     }
  104.     return 1;
  105. }
  106.  
  107. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  108. {
  109.     new string[256];
  110.     if(response)
  111.     {
  112.         switch(dialogid)
  113.         {
  114.             case DIALOG_GPS:
  115.             {
  116.                 SetPlayerCheckpoint(playerid, GPSInfo[listitem][Posx], GPSInfo[listitem][Posy], GPSInfo[listitem][Posz], 3.0);
  117.                 format(string, sizeof(string), "Checkpoint set to %s",GPSInfo[listitem][Name]);
  118.                 SendClientMessage(playerid, 0xFFFFFFFF,string);
  119.             }
  120.         }
  121.     }
  122.     return 0;
  123. }
  124.  
  125. forward CreateGPSLocation(i,const Nume[], Float:x,Float:y,Float:z);
  126. public CreateGPSLocation(i,const Nume[], Float:x,Float:y,Float:z)
  127. {
  128.     GPSInfo[i][ID] = i; format(GPSInfo[i][Name], 50, Nume);
  129.     GPSInfo[i][Posx] = x; GPSInfo[i][Posy] = y; GPSInfo[i][Posz] = z;
  130.     return 1;
  131. }
  132.  
  133. forward LoadGPS();
  134. public LoadGPS()
  135. {
  136.         new file[256];
  137.         for(new i=0;i<=MAX_LOCATIONS;i++)
  138.         {
  139.             format(file,sizeof(file), "GPS/%i.ini",i);
  140.             if(dini_Exists(file))
  141.             {
  142.                 GPSInfo[i][ID] = dini_Int(file,"ID");
  143.                 format(GPSInfo[i][Name], 50, dini_Get(file,"Name"));
  144.                 GPSInfo[i][Posx] = dini_Float(file,"Posx");
  145.                 GPSInfo[i][Posy] = dini_Float(file,"Posy");
  146.                 GPSInfo[i][Posz] = dini_Float(file,"Posz");
  147.             }
  148.         }
  149.         return 1;
  150. }
  151.  
  152. forward SaveGPS();
  153. public SaveGPS()
  154. {
  155.         new file[256];
  156.         for(new i=0;i<=MAX_LOCATIONS;i++)
  157.         {
  158.             format(file,sizeof(file), "GPS/%i.ini",i);
  159.             if(dini_Exists(file))
  160.             {
  161.                 dini_IntSet(file,"ID",GPSInfo[i][ID]);
  162.                 dini_Set(file,"Name", GPSInfo[i][Name]);
  163.                 dini_FloatSet(file,"Posx",GPSInfo[i][Posx]);
  164.                 dini_FloatSet(file,"Posy",GPSInfo[i][Posy]);
  165.                 dini_FloatSet(file,"Posz",GPSInfo[i][Posz]);
  166.             }
  167.         }
  168.         return 1;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement