Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a comment
- // uncomment the line below if you want to write a filterscript
- //#define FILTERSCRIPT
- #include <a_samp>
- // Micro defines
- #define equali(%0,%1) !strcmp(%0,%1,true)
- #define GetPlayerPosEx(%0,%1) GetPlayerPos(%0,%1[0],%1[1],%1[2])
- #define GetAngle(%0,%1) \
- if(IsPlayerInAnyVehicle(%0)) GetVehicleZAngle(GetPlayerVehicleID(%0),%1[3]); \
- else GetPlayerFacingAngle(playerid,%1[3])
- // Setup defines
- #define MAX_RACECPSAVE 150 // Max race checkpoints it can save
- #define DEGREES_CHANGE 75.0 // the degrees need to change for save
- #define PLAYER_RANGE 150.0 // range from the last pos to save again
- // Parameters
- new Float:LastPos[4];
- new Float:rCp[MAX_RACECPSAVE][4];
- new cpCount;
- new Pickups[MAX_RACECPSAVE];
- new string[256];
- new SaveID = -1;
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print("Hirsw0w's RaceCheckPoint Creator v1.0 Created by Hirsw0w - Liran");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- // Destroy Created pickups
- if(SaveID > -1) for(new i;i < cpCount;i++) DestroyPickup(Pickups[i]);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[30],fn[35],type,idx;
- cmd = strtok(cmdtext,idx);
- fn = strtok(cmdtext,idx);
- type = strval(strtok(cmdtext,idx));
- if (equali(cmdtext,"/startsave"))
- {
- if(SaveID != -1) return 1; // Check
- // Delete previous
- 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;
- // Setup
- GetPlayerPosEx(playerid,LastPos);
- GetAngle(playerid,LastPos);
- cpCount = 0;
- SaveID = playerid;
- //Messages
- format(string,sizeof(string)-1,"Start to run/drive every %.1f xyz or %.1f degrees that will save RaceCheckPoint.",PLAYER_RANGE,DEGREES_CHANGE);
- SendClientMessage(playerid,-1,string);
- SendClientMessage(playerid,-1,"To end and save - /endsave [filename] [type id(0-Array | 1-SetPlayerRaceCheckpoint)]");
- SendClientMessage(playerid,-1,"to pause - /pausesave");
- SendClientMessage(playerid,-1,"to continue - /continuesave");
- SendClientMessage(playerid,-1,"to manual save - /savemanual");
- SendClientMessage(playerid,-1,"to undo save - /undosave");
- SendClientMessage(playerid,-1,"to get Infernus - /v");
- SendClientMessage(playerid,-1,"Good luck! Build by Hirsw0w");
- return 1;
- }
- else if(equali(cmd,"/endsave")) {
- if(playerid != SaveID) return 1; // Check
- else if(fn[0] == EOS) return SendClientMessage(playerid,-1,"Usage: /endsave [filename] [type id(0-Array | 1-SetPlayerRaceCheckpoint)]");
- for(new i;i < cpCount;i++) DestroyPickup(Pickups[i]); // Destroy pickups
- // Create File and write him.
- format(string,sizeof(string)-1,"%s.ini",fn);
- new File:hFile = fopen(string,io_write);
- if(!type) fwrite(hFile,"{\r\n");
- for(new i;i <= cpCount-1;i++) {
- if(!type) format(string,sizeof(string),"{%.3f,%.3f,%.3f},\r\n",rCp[i][0],rCp[i][1],rCp[i][2]);
- 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]);
- fwrite(hFile,string);
- }
- if(!type) fwrite(hFile,"}\r\n");
- fclose(hFile);
- // Message and remove the controller id
- SendClientMessage(playerid,-1,"The file has been created and saved, Enjoy!");
- SaveID = -1;
- return 1;
- }
- else if(equali(cmdtext,"/savemanual")) {
- if(playerid != SaveID) return 1;
- GetPlayerPosEx(playerid,rCp[cpCount]);
- GetAngle(playerid,rCp[cpCount]);
- cpCount++;
- format(string,sizeof(string)-1,"Checkpoint number %d has been saved",cpCount);
- SendClientMessage(playerid,-1,string);
- LastPos = rCp[cpCount-1];
- Pickups[cpCount-1] = CreatePickup(1318,1,rCp[cpCount-1][0],rCp[cpCount-1][1],rCp[cpCount-1][2]); // Create Pickup
- return 1;
- }
- else if(equali(cmdtext,"/undosave")) {
- if(playerid != SaveID) return 1;
- rCp[cpCount][0] = 0.0;
- rCp[cpCount][1] = 0.0;
- rCp[cpCount][2] = 0.0;
- rCp[cpCount][3] = 0.0;
- DestroyPickup(Pickups[cpCount]);
- cpCount--;
- SendClientMessage(playerid,-1,"undo save has been done!");
- return 1;
- }
- else if(equali(cmdtext,"/pausesave")) SaveID = -1,SendClientMessage(playerid,-1,"The save has been paused"); // paused save
- else if(equali(cmdtext,"/continuesave")) SaveID = playerid,SendClientMessage(playerid,-1,"The save has been continued"); // continued save
- else if(equali(cmdtext,"/v")) {
- GetPlayerPosEx(playerid,LastPos);
- new num = CreateVehicle(411,LastPos[0],LastPos[1],LastPos[2],0.0,6,6,60);
- PutPlayerInVehicle(playerid,num,0);
- return 1;
- }
- return 1;
- }
- public OnPlayerUpdate(playerid) {
- if(SaveID != playerid) return 1; // Check
- // Setup
- GetPlayerPosEx(playerid,rCp[cpCount]);
- GetAngle(playerid,rCp[cpCount]);
- // Check if need to create cp
- 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])) {
- cpCount++;
- format(string,sizeof(string)-1,"Checkpoint number %d has been saved",cpCount);
- SendClientMessage(playerid,-1,string);
- LastPos = rCp[cpCount-1];
- Pickups[cpCount-1] = CreatePickup(1318,1,rCp[cpCount-1][0],rCp[cpCount-1][1],rCp[cpCount-1][2]); // Create Pickup
- }
- return 1;
- }
- strtok(const string2[], &index) // Strtok by SA-MP wiki
- {
- new length = strlen(string2);
- while ((index < length) && (string2[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string2[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string2[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement