Closed Thread
Results 1 to 10 of 10

Thread: Script Generator

  1. #1
    Victor is offline Programmer
    Join Date
    May 2007
    Location
    The boondocks
    Posts
    116
    Rep Power
    0

    Script Generator

    Hi again everyone! Just need a bit of help with a simple script generator for AA. I have the basic program finished, I just need to figure out how to get the program to write to a txt file on a loop. For example (it's an admin script writer), the user would input "VSS" (Vinturo, a Russian deer rifle on the game lol), the program would then write "admin forceclass 1 VSS", 35 times adding 1 to the number each time, (admin forceclass 1, 2, 3, 4 etc...) I've tried using 'mystr' but i just can't get it to work. Also I'm not sure how or which loop to use. Thanks in advance!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    I'm not sure about this, but I've tried to make a little program, that does what do want to do - or at least, what I think you're trying to do.
    Code:
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <string>
    
    template<typename Type>
    bool GetInput(Type &destination, std::istream &stream = std::cin)
    {
    	std::string temporaryHolder;
    	std::stringstream stringStream;
    	
    	std::getline(stream, temporaryHolder);
    	stringStream << temporaryHolder;
    	
    	return (stringStream >> destination);
    }
    
    template<typename Type>
    std::string Convert(Type value)
    {
    	std::stringstream stringStream;
    	stringStream << value;
    	return stringStream.str();
    }
    
    int main()
    {
    	std::string userInput;
    	std::string finalInput;
    	std::ofstream outputFile;
    	
    	std::cout << "Weapon: ";
    	if(GetInput(userInput))
    	{
    		outputFile.open("admin.cfg");
    		if(outputFile.is_open())
    		{
    			for(int number = 1; number <= 35; number++)
    			{
    				finalInput = "admin forceclass " + Convert(number) + " " + userInput;
    				outputFile << finalInput << std::endl;
    			}
    			outputFile.close();
    		}
    	}
    	
    	return 0;
    }
    If I'm running this script, and typing "VSS" at the prompt...
    Code:
    Weapon: VSS
    ... then the output file looks like this...
    Code:
    admin forceclass 1 VSS
    admin forceclass 2 VSS
    admin forceclass 3 VSS
    admin forceclass 4 VSS
    admin forceclass 5 VSS
    admin forceclass 6 VSS
    admin forceclass 7 VSS
    admin forceclass 8 VSS
    admin forceclass 9 VSS
    admin forceclass 10 VSS
    admin forceclass 11 VSS
    admin forceclass 12 VSS
    admin forceclass 13 VSS
    admin forceclass 14 VSS
    admin forceclass 15 VSS
    admin forceclass 16 VSS
    admin forceclass 17 VSS
    admin forceclass 18 VSS
    admin forceclass 19 VSS
    admin forceclass 20 VSS
    admin forceclass 21 VSS
    admin forceclass 22 VSS
    admin forceclass 23 VSS
    admin forceclass 24 VSS
    admin forceclass 25 VSS
    admin forceclass 26 VSS
    admin forceclass 27 VSS
    admin forceclass 28 VSS
    admin forceclass 29 VSS
    admin forceclass 30 VSS
    admin forceclass 31 VSS
    admin forceclass 32 VSS
    admin forceclass 33 VSS
    admin forceclass 34 VSS
    admin forceclass 35 VSS

  4. #3
    Victor is offline Programmer
    Join Date
    May 2007
    Location
    The boondocks
    Posts
    116
    Rep Power
    0
    Thanks, your program works, still workin' on how to integrate into mine! Will upload final release when done! Thanks

  5. #4
    Victor is offline Programmer
    Join Date
    May 2007
    Location
    The boondocks
    Posts
    116
    Rep Power
    0
    Alright, I got the program to work, final release is attached. I decided to further develop it making it a bit easier to use, for instance, putting it in the default AA directory so you don't have to move it and can just go ahead and use it as soon as it's generated. The program writes to the correct directory (c:/program files/america's army/system), but when I added a feature to open the script after its written, the program refuses to open it.

    Code:
    system("c:/program files/america's army/system/nasg.txt");
    is what I'm using, but nothing happens... I get the error message (from the prompt):
    Code:
    'c:/program' is not recognized as an internal or external command, operable program or batch file
    When I write the file to the current dir and open it with
    Code:
    system("nasg.txt");
    It works fine.

    I've tried with \ in the path, with double of both / and \. What am I doing wrong?
    Attached Files Attached Files
    Last edited by Victor; 07-16-2007 at 08:59 AM.

  6. #5
    Victor is offline Programmer
    Join Date
    May 2007
    Location
    The boondocks
    Posts
    116
    Rep Power
    0
    Hi again, just a quick question. I've tried programming a new feature into the pre-existing program and I've hit a small problem.

    Code:
    std::cout << " Message: ";
    	if(GetInput(userInput))
    	{
    		if(outputFile.is_open())
    		{
    			finalInput = "admin message " + userInput + "\n" + "admin say " + userInput;
    			outputFile << finalInput << std::endl;
    			outputFile.close();
    		}
    	}
    This is supposed to be able to take a string (intended as a message) from the user to make a message in the script. It addes the code fine, but only the first characters, it stops at the spaces in the message. Ex. If I type in 'RPGs! Watch for back blast!', it will print:
    Code:
    admin say RPGs!
    admin message RPGs!
    I think the problem is with the std::cout() command (not sure if right term), probably simple mistake. Thanks in advance!
    Last edited by Victor; 07-27-2007 at 08:47 PM.

  7. #6
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    It's not std::cout there's failing, because you don't even use it. It's in the GetInput it's "failing." It doesn't actually fails, it just doesn't fits your needs. When I made that code I targeted it to fit your needs for the weapons, and now you need to modify it a bit, to match your new needs.

    You're getting the strings without spaces simply because when you're using the std::stringstream, it cuts off all the spaces. If you leave out the std::stringstream your problem will be solved.

    So a new GetInput function could look like the following:
    Code:
    template<typename Type>
    bool GetInput(Type &destination, std::istream &stream = std::cin)
    {
    	return std::getline(stream, destination);
    }

  8. #7
    Victor is offline Programmer
    Join Date
    May 2007
    Location
    The boondocks
    Posts
    116
    Rep Power
    0
    Alright, 1 last question, then I swear I'll post on a different forum lol. I tried the template (worked great), just wondering where to put it in the source. MSVC++ says that I have to declare on global, namespace or class scope.
    Code:
    #include "Headers.h"
    
    template<typename Type>
    bool GetInput(Type &destination, std::istream &stream = std::cin)
    {
    	std::string temporaryHolder;
    	std::stringstream stringStream;
    	
    	std::getline(stream, temporaryHolder);
    	stringStream << temporaryHolder;
    	
    	return (stringStream >> destination);
    }
    
    template<typename Type>
    std::string Convert(Type value)
    {
    	std::stringstream stringStream;
    	stringStream << value;
    	return stringStream.str();
    }
    
    int main()
    {
    	std::string userInput;
    	std::string finalInput;
    	std::ofstream outputFile;
    	
    	printf("Welcome to Neo's Admin Script Generator 0.3\n");
    	printf("-------------------------------------------\n");
    	printf(" INSTRUCTIONS\n\n");
    	printf("1. Input the class you want to apply to players, (R,G,AR,VSS,RPG etc...)\n");
    	printf("   Please note: must be correct class or it won't work\n");
    	printf("2. NASG will output a script called 'nasg.txt' to the default\n");
    	printf("   Americas Army Folder: 'C:/Program Files/America's Army/System'\n");
    	printf("   This program will generate a script for 50 players\n");
    	printf("   This program will NOT alert you if you enter an invalid class\n\n");
    	std::cout << " Weapon: ";
    	if(GetInput(userInput))
    	{
    		outputFile.open("nasg.txt");
    		if(outputFile.is_open())
    		{
    			for(int number = 0; number <= 50; number++)
    			{
    				finalInput = "admin forceclass " + Convert(number) + " " + userInput;
    				outputFile << finalInput << std::endl;
    			}
    		}
    	}
    	template<typename Type>
    	bool GetInput(Type &destination, std::istream &stream = std::cin)
    	{
    		return std::getline(stream, destination);
    	}
    
    	std::cout << "Message: ";
    	if (GetInput(userInput))
    	{
    		outputFile.open("nasg.txt");
    		if(outputFile.is_open())
    		{
    			finalInput = "admin message " + userInput + "\n" + "admin say " + userInput;
    			outputFile << finalInput << std::endl;
    			outputFile.close();
    			system("nasg.txt");
    		}
    	}
    }

  9. #8
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    As you see, you already have one with that name (i.e. GetInput), so you need to call it something else. Let's just say GetInput2. Then it will look like this:
    Code:
    #include "Headers.h"
    
    template<typename Type>
    bool GetInput(Type &destination, std::istream &stream = std::cin)
    {
    	std::string temporaryHolder;
    	std::stringstream stringStream;
    	
    	std::getline(stream, temporaryHolder);
    	stringStream << temporaryHolder;
    	
    	return (stringStream >> destination);
    }
    
    template<typename Type>
    bool GetInput2(Type &destination, std::istream &stream = std::cin)
    {
    	return std::getline(stream, destination);
    }
    
    template<typename Type>
    std::string Convert(Type value)
    {
    	std::stringstream stringStream;
    	stringStream << value;
    	return stringStream.str();
    }
    
    int main()
    {
    	std::string userInput;
    	std::string finalInput;
    	std::ofstream outputFile;
    	
    	printf("Welcome to Neo's Admin Script Generator 0.3\n");
    	printf("-------------------------------------------\n");
    	printf(" INSTRUCTIONS\n\n");
    	printf("1. Input the class you want to apply to players, (R,G,AR,VSS,RPG etc...)\n");
    	printf("   Please note: must be correct class or it won't work\n");
    	printf("2. NASG will output a script called 'nasg.txt' to the default\n");
    	printf("   Americas Army Folder: 'C:/Program Files/America's Army/System'\n");
    	printf("   This program will generate a script for 50 players\n");
    	printf("   This program will NOT alert you if you enter an invalid class\n\n");
    	std::cout << " Weapon: ";
    	if(GetInput(userInput))
    	{
    		outputFile.open("nasg.txt");
    		if(outputFile.is_open())
    		{
    			for(int number = 0; number <= 50; number++)
    			{
    				finalInput = "admin forceclass " + Convert(number) + " " + userInput;
    				outputFile << finalInput << std::endl;
    			}
    		}
    	}
    
    	std::cout << "Message: ";
    	if (GetInput2(userInput))
    	{
    		outputFile.open("nasg.txt");
    		if(outputFile.is_open())
    		{
    			finalInput = "admin message " + userInput + "\n" + "admin say " + userInput;
    			outputFile << finalInput << std::endl;
    			outputFile.close();
    			system("nasg.txt");
    		}
    	}
    }

  10. #9
    Victor is offline Programmer
    Join Date
    May 2007
    Location
    The boondocks
    Posts
    116
    Rep Power
    0
    Thx a bunch v0id. I found a bug in your code, but I fixed it . When I ran your code, it would only put in the script either the weapon or the message. Fixed by taking out the second outputFile.open. Just thought you'd like to know! But thanks for all of your help. I couldn't have done it w/o you.

  11. #10
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    Oh, thanks about pointing the little error out.
    I was unable to test the code at the time I made GetInput2, but I took the chance and posted it in here. But nice to see you fixed it yourself, good job!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [HELP] convert Perl script to Bash shell script
    By Egypte in forum Linux Programming and Scripting
    Replies: 2
    Last Post: 04-24-2011, 05:37 PM
  2. Weekday generator
    By taabistan in forum Python
    Replies: 1
    Last Post: 12-02-2010, 02:49 PM
  3. What is the difference between VB script and Java script?
    By newage123 in forum JavaScript and CSS
    Replies: 8
    Last Post: 11-14-2008, 10:49 AM
  4. Random Name Generator
    By DevilsCharm in forum C and C++
    Replies: 1
    Last Post: 11-07-2007, 09:38 PM
  5. Number Generator
    By Beginning-now in forum General Programming
    Replies: 3
    Last Post: 11-03-2007, 04:36 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts