Guest User

HireMe's saveplace system

a guest
Nov 8th, 2010
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.10 KB | None | 0 0
  1. //========================================================================================================================
  2. //-------------------------CopyRight by HireMe (PPSV)---------------------------------------------------------------------
  3. //------------------------------------------------------------------------------------------------------------------------
  4. //This script saves X Y Z positions and the angle to.---------------------------------------------------------------------
  5. //Because this script saves the Angle it is very usefull for saving positions for vehicles.-------------------------------
  6. //USAGE: go to the place you want to save and put your char in the right angle then type: /saveplace [Locationname]-------
  7. //------------------------------------------------------------------------------------------------------------------------
  8. //------------------------------------------------------------------------------------------------------------------------
  9. //========================================================================================================================
  10.  
  11. #include <a_samp>
  12. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  13.  
  14. //========================================================================================================================
  15. //-------------------------Definitions that you may change----------------------------------------------------------------
  16. //------------------------------------------------------------------------------------------------------------------------
  17. #define MAX_POSITION_LOCATIONS 200     // Change this if you have more.
  18. #define MAX_POSITION_NAME 100         // This is the Maximum lenght of the Position name. Changing is not advised.
  19. #define PRINT_ON               // Add the "//" infront of it, to disable the printed message when a Position is created.
  20. //------------------------------------------------------------------------------------------------------------------------
  21. //-------------------------End of the Definitions-------------------------------------------------------------------------
  22. //========================================================================================================================
  23.  
  24. new PositionID;
  25. new Float:Position_X[MAX_POSITION_LOCATIONS];
  26. new Float:Position_Y[MAX_POSITION_LOCATIONS];
  27. new Float:Position_Z[MAX_POSITION_LOCATIONS];
  28. new Float:Position_Ang[MAX_POSITION_LOCATIONS];
  29. new Position_Int[MAX_POSITION_LOCATIONS];
  30. new Position_Name[MAX_POSITION_LOCATIONS][MAX_POSITION_NAME];
  31. new Position_Exists[MAX_POSITION_LOCATIONS];
  32.  
  33. //===========The Commands============================================================================================================================================
  34. dcmd_saveplace(playerid,params[])
  35. {
  36.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You need to be a RCON-Admin to save Position-Locations.");
  37.         if(!strlen(params)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /saveplace [Locationname]");
  38.         new string[128], name[MAX_POSITION_NAME], Index;
  39.         name=strtok(params, Index);
  40.         new Float:px,Float:py,Float:pz, Float:A, Int, File:SaveLog;
  41.         GetPlayerPos(playerid,px,py,pz);
  42.         GetPlayerFacingAngle(playerid, A);
  43.         Int=GetPlayerInterior(playerid);
  44.         format(string,sizeof(string),"Position %d added:  Name: %s | X: %0.4f | Y: %0.4f | Z: %0.4f | Angle: %0.4f | Interior: %d", PositionID, params[0], px, py, pz, A, Int);
  45.         SendClientMessage(playerid, 0xFF9900AA, string);
  46.         format(string,sizeof(string),"Position %d saved to ''Saved_Position_Locs.txt''. Add it to Position.pwn !", PositionID);
  47.         SendClientMessage(playerid, 0xFFFFFFFF, string);
  48.         format(string, sizeof(string), "Position(\"%s\", %0.4f, %0.4f, %0.4f, %0.4f, %d);\r\n", params[0], px, py, pz, A, Int);
  49.         SaveLog=fopen("Saved_Position_Locs.txt", io_append);
  50.         fwrite(SaveLog, string);
  51.         fclose(SaveLog);
  52.         AddPosition(name, px, py, pz, A, Int);
  53.         return 1;
  54. }
  55. //==================================================================================================================================================================
  56.  
  57. public OnPlayerCommandText(playerid, cmdtext[])
  58. {
  59.     dcmd(saveplace,9,cmdtext);
  60.     return 0;
  61. }
  62.  
  63. stock IsNumeric(const string[]) {
  64.     new length=strlen(string);
  65.     if (length==0) return false;
  66.     for (new i = 0; i < length; i++) {
  67.         if (
  68.         (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
  69.         || (string[i]=='-' && i!=0)                                             // A '-' but not at first.
  70.         || (string[i]=='+' && i!=0)                                             // A '+' but not at first.
  71.         ) return false;
  72.     }
  73.     if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  74.     return true;
  75. }
  76.  
  77. AddPosition(Name[MAX_POSITION_NAME], Float:PositionX, Float:PositionY, Float:PositionZ, Float:PositionAng, PositionInt)
  78. {
  79.     Position_Name[PositionID]=Name;
  80.     Position_X[PositionID]=PositionX;
  81.     Position_Y[PositionID]=PositionY;
  82.     Position_Z[PositionID]=PositionZ;
  83.     Position_Ang[PositionID]=PositionAng;
  84.     Position_Int[PositionID]=PositionInt;
  85.     Position_Exists[PositionID]=1;
  86.     #if defined PRINT_ON
  87.     print("------------------------------Position--------------------------------------");
  88.     printf("Position %d (%s) sucessfully created!", PositionID, Name);
  89.     printf("X: %0.4f | Y: %0.4f | Z: %0.4f | Angle: %0.4f | Interior: %d", PositionX, PositionY, PositionZ, PositionAng, PositionInt);
  90.     print("------------------------------------------------------------------------");
  91.     print(" ");
  92.     #endif
  93.     PositionID++;
  94. }
  95.  
  96. strtok(const string[], &index)
  97. {
  98.     new length = strlen(string);
  99.     while ((index < length) && (string[index] <= ' '))
  100.     {
  101.         index++;
  102.     }
  103.  
  104.     new offset = index;
  105.     new result[20];
  106.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  107.     {
  108.         result[index - offset] = string[index];
  109.         index++;
  110.     }
  111.     result[index - offset] = EOS;
  112.     return result;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment