Crow13 0 Newbie Poster

Hello.
Here is da story why i wanna make this script. Play CS, and on the server theres this Math mod. In short it gives ya a 3 number equation, 1st to type in the answer get 1500$. And if your alive hard to count =\. So decided to make this script for it. There might be an esier way to make a script for CS for the mod, but havent really tweaked CS before, so no clue.

What i want:
Get CS to print CONSOLE info to text file(bind to a key) --> read from file --> find line that i need --> take line --> cut all cept equation --> Solve --> put answer into file --> script reads to console

Heres what i have so far. Might be a tad sloppy for some people , so sorry in advance. ))
Also its 2 programs atm, but will glue en together if all works.
Mostly need help with the MATH part...


This here is a sample of what the Colsole looks like

stdump
[MATH] (-4)+(-34)+2
Joe: HahA! die noob!

Equations always have 3 numbers, so i understand i should get liek a,b,c. But how to get past the '(' and ')' when there might be a '-' in front or after. Main question really...
Also, there a dump console to txt file in CS. then just clear it.


Code to make this program run in the background, when i press 'E', 'L' if i wanna quit.
When 'E' pressed gets file from CS folder.
Then write answer to file that will be the script command for CS. So i dont have to type in the asnwer myself.
Then delete the old CS Colsole dump file. Since every time CS make a dump file it goes... condumpxxx - where xxx = i++; so if no dump file, will always be condump000

#include <iostream>
#include <fstream>
#include <Windows.h>

using namespace std;

int main () {
    
     cout << "CS 1.6 Math Solver =D" << endl << endl;

      cout << "Press 'E ' to solve" << endl;
      cout << "Press 'L ' to Quit" << endl << endl;
      
      bool running = true;
      while(running){
                     
    ////////////////////////////////////////// get from log
  if(GetAsyncKeyState(69)){                        // CHANGE  69 - to another value ASCII
     string line;
  ifstream myfile ("C:/Games/cspro48/cstrike/condump000.txt");             // change to own game directory (condumpxxx    - xxx = numbers( condump000))
  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 
    
  ///////////////////////////////////////// write to script
    
    int answer = 0;
    
  ofstream myfile1;
  myfile1.open ("script.txt");               //  channge to own game directory
  myfile1 << "say "<< answer << endl << "clear";
  myfile1.close();
  
  //////////////////////////////////////  remove old log file
  
    if( remove( "C:/Games/cspro48/cstrike/condump000.txt" ) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
}
   if (GetAsyncKeyState(76)) /*  L  */
   running = false;

}

  return 0;
}

Here is the fild the needed line in the Dump file, then remove the unneeded part, put equation into an array or string, not sure whats better...

The line iam looking for WILL always be like: [MATH] (-4)+(-34)+2 or [MATH] (equation here), can even be -(-13)-(-23)*(-2). The math consists of 3 numbers(can be '-' or '+'), they can be '+', '-' or '*' between each other.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){

   int answer = 0;
   string line;

    char* search = "[MATH]"; // search pattern
    int offset;

    ifstream Myfile;
    Myfile.open ("test.txt");

    if(Myfile.is_open()){

    while(!Myfile.eof()){
    getline(Myfile,line);

    if ((offset = line.find(search, 0)) != string::npos) {
  //  cout << line << endl;
    Myfile.close();
                    }
                   }
    Myfile.close();
    }
    else
    cout<<"Unable to open this file."<<endl;

    // cout << line.length() << endl << endl;



        char *form1;
        form1 = new char[line.length()];
        char *form2;
        form2 = new char[line.length()-7];
        form1 = new char[line.length()];

     for(size_t i = 0; i < line.length(); i++){
               form1[i] = line[i];
              // cout << form1[i] << "\n";
                }

     int sk=0;
     for(int i = 0; i < line.length(); i++){
             if(form1[i] != '[' && form1[i] != ']' && form1[i] != 'M' && form1[i] != 'A' && form1[i] != 'T' && form1[i] != 'H' && form1[i] != ' ' ){
             form2[sk] = form1[i];
             cout << form2[sk];
             sk++;
                  }
             }
     cout << endl;


    return 0;
}

This is for the CS scirpt, so i dont have to type, just button press.

say (answer goes here)
clear

If you have any advice for the already made code, tell me how i might improve it ))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.