Advertisement
Guest User

SA-MP Mover v0.1

a guest
May 4th, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.02 KB | None | 0 0
  1. // basic file operations
  2. #include <iostream>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <sstream>
  7. #include <iomanip>
  8. #include <Windows.h>
  9.  
  10. using namespace std;
  11.  
  12. int main ()
  13. {
  14. //===== VARIJABLE ========================================================
  15.     ifstream input_file;//iz ovog fajla program cita
  16.     string loaded_file;//lokacija za ucitavanje fajla
  17.     string getlinestring;
  18.     float change;//velicina pomjeranja 
  19.     int side = 0;//koordinata pomjeranja
  20. //===== PROGRAM ========================================================
  21.     cout << "SA-MP MAP MOVER - v0.1 (Gigi Falcone)" << endl;
  22.     cout << "=====================================================" << endl;
  23.     cout << endl;
  24.     cout << "Unesite koordinatu koju zelite da pomjerate, X - 1, Y - 2, Z - 3:";
  25.     cin >> side;
  26.     cout << "Unesite velicinu pomjeranja (Primjer: 150.0): ";
  27.     cin >> change;
  28.     cout << "Unesite ime fajla iz kojeg zelite da ucitate objekte: ";
  29.     cin >> loaded_file;
  30.     cout << "-----------------------------------------------------" << endl;
  31.     cout << "- Ucitavanje objekata iz fajla: " << loaded_file << endl;
  32.     string temp_loaded_file = loaded_file + ".txt";
  33.     input_file.open(temp_loaded_file);
  34.     string output_file = loaded_file + "_converted.txt";
  35.     if(input_file.is_open())
  36.     {
  37.         int timer1 = GetTickCount();
  38.         //varijable
  39.         int bracketpos[2];
  40.         int commapos[4];
  41.         int modelid;
  42.         string coordvar1;
  43.         string coordvar2;
  44.         string coordvar3;
  45.         string reststring;
  46.  
  47.        
  48.         ofstream outfile(output_file);
  49.  
  50.         //ostalo
  51.         cout << "- Ucitavanje fajla je uspjesno, pomjeranje mape je u toku..." << endl;
  52.         cout << "-----------------------------------------------------" << endl;
  53.         while(getline(input_file,getlinestring))
  54.         {
  55.  
  56.             //Prva Zagrada
  57.             string tempstring1;
  58.             bracketpos[0] = getlinestring.find("(");//pronalazak prve zagrade posle CreateObject ili CreateDynamicObject
  59.             commapos[0] = getlinestring.find(",");//pronalazak prvog zareza
  60.             tempstring1 = getlinestring.substr(bracketpos[0] + 1,commapos[0] - (bracketpos[0] + 1));//izvlacenje modela objekta izmedju zagrade "(" i prvog zareza ","
  61.             stringstream(tempstring1) >> modelid;//konvertovanje stringa modela u broj modelid
  62.  
  63.             //Prvi Zarez
  64.             commapos[0]++;
  65.             commapos[1] = getlinestring.find(",",commapos[0]);
  66.             coordvar1 = getlinestring.substr(commapos[0],commapos[1] - commapos[0]);
  67.             double coord1 = stod(coordvar1);
  68.  
  69.             //Drugi Zarez
  70.             commapos[1]++;
  71.             commapos[2] = getlinestring.find(",",commapos[1]);
  72.             coordvar2 = getlinestring.substr(commapos[1],commapos[2] - commapos[1]);
  73.             double coord2 = stod(coordvar2);
  74.  
  75.             //Treci Zarez
  76.             commapos[2]++;
  77.             commapos[3] = getlinestring.find(",",commapos[2]);
  78.             coordvar3 = getlinestring.substr(commapos[2],commapos[3] - commapos[2]);
  79.             double coord3 = stod(coordvar3);
  80.  
  81.             //Ostatak koda do kraja reda
  82.             bracketpos[1] = getlinestring.find(")");
  83.             reststring = getlinestring.substr(commapos[3],bracketpos[1]);
  84.  
  85.             if(side == 1)//Koordinata X
  86.             {
  87.                 coord1 = coord1 + change;
  88.             }
  89.             else if(side == 2)//Koordinata Y
  90.             {
  91.                 coord2 = coord2 + change;
  92.             }
  93.             else if(side == 3)//Koordinata Z
  94.             {
  95.                 coord3 = coord3 + change;
  96.             }
  97.  
  98.  
  99.  
  100.  
  101.             outfile << "CreateObject(" << modelid << "," << setprecision(9) << coord1 << "," << setprecision(9) << coord2 << "," << setprecision(9) << coord3 << reststring << "\n";
  102.             cout << "CreateObject(" << modelid << "," << setprecision(9) << coord1 << "," << setprecision(9) << coord2 << "," << setprecision(9) << coord3 << reststring << "\n";
  103.        
  104.  
  105.         }
  106.         outfile.close();
  107.  
  108.         cout << endl;
  109.         cout << endl;
  110.         int timer2 = GetTickCount() - timer1;
  111.         cout << "- Konvertovanje mape je uspjesno zavrseno!" << endl;
  112.         cout << "Vrijeme konvertovanja: " << timer2 << "ms" << endl;
  113.     }
  114.     else
  115.     {
  116.         cout << "- Ucitavanje fajla nije uspjesno! ((fajl '" << temp_loaded_file << "' ne postoji))" << endl;
  117.         cin.ignore();
  118.     }
  119.  
  120.         int a;
  121.     cin >> a;
  122.     //printanje u fajl
  123.     //output_file.open ("converted.pwn");
  124.     //output_file << getlinestring << "\n";
  125.     //output_file.close();
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement