Advertisement
Hirsw0w

[FS] HRCPcreator by Hirsw0w

Mar 1st, 2015
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.83 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6.  
  7. // Micro defines
  8. #define equali(%0,%1) !strcmp(%0,%1,true)
  9. #define GetPlayerPosEx(%0,%1) GetPlayerPos(%0,%1[0],%1[1],%1[2])
  10. #define GetAngle(%0,%1) \
  11.     if(IsPlayerInAnyVehicle(%0)) GetVehicleZAngle(GetPlayerVehicleID(%0),%1[3]); \
  12.     else GetPlayerFacingAngle(playerid,%1[3])
  13.  
  14. // Setup defines
  15. #define MAX_RACECPSAVE 150 // Max race checkpoints it can save
  16. #define DEGREES_CHANGE 75.0 // the degrees need to change for save
  17. #define PLAYER_RANGE 150.0 // range from the last pos to save again
  18.  
  19. // Parameters
  20. new Float:LastPos[4];
  21.  
  22. new Float:rCp[MAX_RACECPSAVE][4];
  23. new cpCount;
  24.  
  25. new Pickups[MAX_RACECPSAVE];
  26.  
  27. new string[256];
  28.  
  29. new SaveID = -1;
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     print("\n--------------------------------------");
  34.     print("Hirsw0w's RaceCheckPoint Creator v1.0 Created by Hirsw0w - Liran");
  35.     print("--------------------------------------\n");
  36.     return 1;
  37. }
  38.  
  39. public OnFilterScriptExit()
  40. {
  41.     // Destroy Created pickups
  42.     if(SaveID > -1) for(new i;i < cpCount;i++) DestroyPickup(Pickups[i]);
  43.     return 1;
  44. }
  45.  
  46. public OnPlayerCommandText(playerid, cmdtext[])
  47. {
  48.     new cmd[30],fn[35],type,idx;
  49.     cmd = strtok(cmdtext,idx);
  50.     fn = strtok(cmdtext,idx);
  51.     type = strval(strtok(cmdtext,idx));
  52.     if (equali(cmdtext,"/startsave"))
  53.     {
  54.         if(SaveID != -1) return 1; // Check
  55.        
  56.         // Delete previous
  57.         for(new i;i < MAX_RACECPSAVE;i++) rCp[i][0] = 0.0,rCp[i][1] = 0.0,rCp[i][2] = 0.0,rCp[i][3] = 0.0;
  58.         // Setup
  59.         GetPlayerPosEx(playerid,LastPos);
  60.         GetAngle(playerid,LastPos);
  61.         cpCount = 0;
  62.         SaveID = playerid;
  63.         //Messages
  64.         format(string,sizeof(string)-1,"Start to run/drive every %.1f xyz or %.1f degrees that will save RaceCheckPoint.",PLAYER_RANGE,DEGREES_CHANGE);
  65.         SendClientMessage(playerid,-1,string);
  66.         SendClientMessage(playerid,-1,"To end and save - /endsave [filename] [type id(0-Array | 1-SetPlayerRaceCheckpoint)]");
  67.         SendClientMessage(playerid,-1,"to pause - /pausesave");
  68.         SendClientMessage(playerid,-1,"to continue - /continuesave");
  69.         SendClientMessage(playerid,-1,"to manual save - /savemanual");
  70.         SendClientMessage(playerid,-1,"to undo save - /undosave");
  71.         SendClientMessage(playerid,-1,"to get Infernus - /v");
  72.         SendClientMessage(playerid,-1,"Good luck! Build by Hirsw0w");
  73.         return 1;
  74.     }
  75.     else if(equali(cmd,"/endsave")) {
  76.         if(playerid != SaveID) return 1; // Check
  77.         else if(fn[0] == EOS) return SendClientMessage(playerid,-1,"Usage: /endsave [filename] [type id(0-Array | 1-SetPlayerRaceCheckpoint)]");
  78.        
  79.         for(new i;i < cpCount;i++) DestroyPickup(Pickups[i]); // Destroy pickups
  80.  
  81.         // Create File and write him.
  82.         format(string,sizeof(string)-1,"%s.ini",fn);
  83.         new File:hFile = fopen(string,io_write);
  84.         if(!type) fwrite(hFile,"{\r\n");
  85.        
  86.         for(new i;i <= cpCount-1;i++) {
  87.             if(!type) format(string,sizeof(string),"{%.3f,%.3f,%.3f},\r\n",rCp[i][0],rCp[i][1],rCp[i][2]);
  88.             else format(string,sizeof(string),"SetPlayerRaceCheckpoint(playerid,%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,3.0);\r\n",i == cpCount ? 1:0,rCp[i][0],rCp[i][1],rCp[i][2],rCp[i+1][0],rCp[i+1][1],rCp[i+1][2]);
  89.             fwrite(hFile,string);
  90.         }
  91.  
  92.         if(!type) fwrite(hFile,"}\r\n");
  93.         fclose(hFile);
  94.         // Message and remove the controller id
  95.         SendClientMessage(playerid,-1,"The file has been created and saved, Enjoy!");
  96.         SaveID = -1;
  97.         return 1;
  98.     }
  99.     else if(equali(cmdtext,"/savemanual")) {
  100.         if(playerid != SaveID) return 1;
  101.        
  102.         GetPlayerPosEx(playerid,rCp[cpCount]);
  103.         GetAngle(playerid,rCp[cpCount]);
  104.         cpCount++;
  105.         format(string,sizeof(string)-1,"Checkpoint number %d has been saved",cpCount);
  106.         SendClientMessage(playerid,-1,string);
  107.         LastPos = rCp[cpCount-1];
  108.         Pickups[cpCount-1] = CreatePickup(1318,1,rCp[cpCount-1][0],rCp[cpCount-1][1],rCp[cpCount-1][2]); // Create Pickup
  109.         return 1;
  110.     }
  111.     else if(equali(cmdtext,"/undosave")) {
  112.         if(playerid != SaveID) return 1;
  113.        
  114.         rCp[cpCount][0] = 0.0;
  115.         rCp[cpCount][1] = 0.0;
  116.         rCp[cpCount][2] = 0.0;
  117.         rCp[cpCount][3] = 0.0;
  118.         DestroyPickup(Pickups[cpCount]);
  119.         cpCount--;
  120.         SendClientMessage(playerid,-1,"undo save has been done!");
  121.         return 1;
  122.     }
  123.     else if(equali(cmdtext,"/pausesave")) SaveID = -1,SendClientMessage(playerid,-1,"The save has been paused"); // paused save
  124.     else if(equali(cmdtext,"/continuesave")) SaveID = playerid,SendClientMessage(playerid,-1,"The save has been continued"); // continued save
  125.     else if(equali(cmdtext,"/v")) {
  126.         GetPlayerPosEx(playerid,LastPos);
  127.         new num = CreateVehicle(411,LastPos[0],LastPos[1],LastPos[2],0.0,6,6,60);
  128.         PutPlayerInVehicle(playerid,num,0);
  129.         return 1;
  130.     }
  131.     return 1;
  132. }
  133.  
  134. public OnPlayerUpdate(playerid) {
  135.     if(SaveID != playerid) return 1; // Check
  136.    
  137.     // Setup
  138.     GetPlayerPosEx(playerid,rCp[cpCount]);
  139.     GetAngle(playerid,rCp[cpCount]);
  140.     // Check if need to create cp
  141.     if(!IsPlayerInRangeOfPoint(playerid,PLAYER_RANGE,LastPos[0],LastPos[1],LastPos[2]) || (rCp[cpCount][3] >= LastPos[3]+DEGREES_CHANGE || rCp[cpCount][3] <= LastPos[3]-DEGREES_CHANGE) && !IsPlayerInRangeOfPoint(playerid,20.0,LastPos[0],LastPos[1],LastPos[2])) {
  142.         cpCount++;
  143.         format(string,sizeof(string)-1,"Checkpoint number %d has been saved",cpCount);
  144.         SendClientMessage(playerid,-1,string);
  145.         LastPos = rCp[cpCount-1];
  146.         Pickups[cpCount-1] = CreatePickup(1318,1,rCp[cpCount-1][0],rCp[cpCount-1][1],rCp[cpCount-1][2]); // Create Pickup
  147.     }
  148.     return 1;
  149. }
  150.  
  151. strtok(const string2[], &index) // Strtok by SA-MP wiki
  152. {
  153.     new length = strlen(string2);
  154.     while ((index < length) && (string2[index] <= ' '))
  155.     {
  156.         index++;
  157.     }
  158.  
  159.     new offset = index;
  160.     new result[20];
  161.     while ((index < length) && (string2[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  162.     {
  163.         result[index - offset] = string2[index];
  164.         index++;
  165.     }
  166.     result[index - offset] = EOS;
  167.     return result;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement