Thread: Having a problem with my RPG Bot.

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    4

    Having a problem with my RPG Bot.

    Hey, all. I'm pretty much fairly new to the C++ scene, and just starting to learn most of the ropes. The program I'm making is for an RPG on a forum board we play. It's to help out the GMs/including myself, figure out the chance of a character missing, or evading an attack.

    Basically. You're either attacking or defending. So I wanted it to ask you if you're going to att/def.

    If you pick att or def, it doesn't matter. It'll say press any key to continue and just stop there. THen it closes out.

    At the moment, it's supposed to use the main formula to get a number, which I can't really turn into an actual percentage.. so it's basically up to us for now to figure out what it would be.

    Also. If you get 100%+, the program is supposed to tell you that you've gotten 99%, because in the game you can't ever have a perfect 100 or more, there's always a 1% chance you might miss, or not evade.

    Here's the current source code.

    Code:
    //  Program to determine chance of missing.
    //  It can also determine the chance of evading.
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    
    // AGI / DEX = sum converted to % / 2 = final result
    // 3 AGI, 1 DEX: 3 / 1 = 3(300%) / 2 = 150% chance to miss, cut down to 99%
    // DEX/AGI is attacking.
    // AGI/DEX is defending.
    
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    {
    cout
         <<"***************************\n"
         <<"***Parma III Stat Roller***\n"
         <<"***************************\n\n"
         <<"This Program was created by the Android Hunter\n"
         <<"Cyrus. It's used to quickly determine your chance\n"
         <<"of missing. Enjoy!\n\n";
    bool quit = false;
    while(!quit)
    {        
    double bam;
    double att;
    cout<<"Are you Attacking/Defending? (att/def) ";
    cin>>bam;
    if(bam == att)
    if(true)
    {
    double DEX;          
    cout << "Enter Defender's DEX:";
    cin >> DEX;
    
    // Now we have to get the ATP!
    
    double AGI;
    cout << "Enter Attacker's AGI:";
    cin >> AGI;
          
    // Now we'll figure out the chance of missing.
    
    double thelastone;
    
    thelastone = (AGI/DEX)/2 * 100;
    
    //This will give the player 99% if it's above 100%
    
    if (thelastone >= 100)
    
    cout<<"Your chance of missing is: 99%"<<endl;
    
    cout << "Your chance of missing is: ";
    cout << thelastone << "%\n" << endl;
    
    system("Pause");
    return 0;
    }
    else {
    
    double block;
    cout << "Enter Defender's DEX:";
    cin >> block;
    
    // Now for the Attacker.
    
    double slam;
    cout << "Enter the Attackers AGI:";
    cin >> slam;
    
    double thefirstone;
    
    thefirstone = (block/slam)/2 * 100;
    
    //This will give the player 99% if it's above 100%.
    
    if (thefirstone >= 100)
    
    cout<<"Your chance of evading is: 99%"<<endl;
    
    cout << "Your chance of evading is: ";
    cout << thefirstone << "%/n" <<endl;
    }
    system("Pause");
    return 0;
    }
    }
    Thanks.

  2. #2
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    uh... this reminds me of another post i just saw, and somebody said something like "this isn't a forum where you dump code and have us fix it or something." looks like you might need to do just a tad bit more learning about if statements, like WHEN to use them, or maybe just explain to me what you're trying to do here:
    Code:
    cout<<"Are you Attacking/Defending? (att/def) ";
    cin>>bam;
    if(bam == att)
    if(true)
    i'm not trying to be mean, just trying to help out a little. don't expect that code to work, because you obviously don't understand how to use if statements, not to mention it looks like you have no clue how to get valid user input. you declared a type double variable, and then had the user input either "att" or "def" into a decimal number. what is that supposed to do? you'd probably just want to create a type char variable and input into that, just a single character. then use what you learn about if statements and code something that at least makes some sense. here you're trying to compare bam which is a decimal number to "att" which isn't even initialized, so you're never gonna get any results that make any sense.
    if(true) is pointless in c++ because it is always true. so its almost like telling the computer "if you WANT to" which will ALWAYS happen, unless the computer crashes.

    not that i really know that much about what i'm talking about. but come on... seriously...
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    4
    Gah, okay.. sorry about that then. I wasn't trying to dump it and make you fix it, I just thought it'd help if you saw everything just to make sure it wasn't somewhere else.

    I already tried using char * bam, etc.

    Okay. So I'll be taking out that if(true) part, and I'll start working on fixing

    Sorry if it seemed like I was asking for it all to get done. I'm just really confused by the part where I need to get the person to choose if they'll attack or defend.

    So I should make it

    char * att.. or just char att, and then that way if they actually use att, it'll recognize it. And if they used def, it'd just go to the else part? If that's no either, I'll just have to get back to re-reading a few things.

    Thanks though, that's the one part that was really confusing me.

  4. #4
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    hey i didn't mean to be slamming your code. it was just... fun i guess lol. anyway i'm pretty much a newbie too, i've only been learning for about 2 years, but the first year was mostly C. so the second year was... well, c++. duh.

    ok about your question, getting the input: well there's two really easy ways to do it. what it looks like you'd prefer to do is have the user input "att" or "def", so it might be a good idea to go with a string. since you're using c++, just include the <string> header file (#include <string>) and then your "bam" variable will be a string. so just say "string bam;"
    then you can go cin >> bam; and it will store the user's input into the bam string.
    then you just test bam to see if it equals "att" or "def". if statements will do, but make sure you test for strings, not other variables. like what you were trying to do was "if (bam == att)..." and that looks right at first, but then you realize that you're telling the computer to compare bam with another variable, called att, and if you still declare att as a double, well it just won't let you compare a string with a double. so put some little quotes around "att" (if (bam == "att")..." and you should be all set. and you don't need that second if statement,
    if(true)... it's just
    Code:
    if(bam == "att")
    {
       do this code
    }
    and another thing i think would be good to note is that when you tested to see if your percentage was over 100, you wanted to change it to 99. but really all you did in your code was tell the user that it was 99. you didn't actually change it. so pretty much you just lied. heh. so either before or after you tell the user that its 99, you have to change that variable and make it equal to 99. otherwise the program isn't doing what it's supposed to do. if you actually used that variable, even though you told the user it was 99, in your game it'd still use the 110% or whatever it was at. and that's no good at all. so... anyway good luck, looks like you almost got it under control. just a couple minor changes and you should be all set
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  5. #5
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by linucksrox
    uh... this reminds me of another post i just saw, and somebody said something like "this isn't a forum where you dump code and have us fix it or something."
    That would be the tic tac toe topic in the game section, and I believe that was commented because the person put the code to a working (I believe) program, and then said "if you find any bugs please tell me, thanks". It doesnt seem, like you said, that this topics code would even work, and hes obviously unsure why, so its appropriate to have all the code.

    You seem to be using 'double' for the dex, and such, which is fine, because those are number values. 'double' is a longer version of 'float', and 'float' stores numbers (in decimal form). When you say select att or def, you must store that in a 'string' (holds characterS) , if you were asking for A or D you would store that in a 'char' (holds 1 character). Seems like thats the only real problem you had.

    The funny thing is that the way you used your if statements there is.. undoubtably odd, but still legal.. just pointless.

    I was going to explain how to use a string here, but I tabbed out of this window and forgot about it for 2 hours, and linucksrox has seemed to explained that part already
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    4
    Alright. Thanks for all of the help.

    When I pick att/def, it goes with the correct side, thanks to the STRINGs.

    I've also added this..

    Code:
    if (thefirstone >= 100)
    thefirstone = 99;
    So it'll show up as 99, instead of giving me both of the numbers.. thanks for mentioning that to me.

    Now I just need to throw in a message asking if you want another number, tell the program how to change something into a percentage (unless that's already possible?) and bam!

    Thanks alot, this is all making sense to me now.

  7. #7
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Quote Originally Posted by linucksrox
    since you're using c++, just include the <string> header file (#include <string>) and then your "bam" variable will be a string. so just say "string bam;"
    then you can go cin >> bam;

    well if he gonna go that far, he might as well learn about

    getline(cin, string, '\n');

    for getting strings, it will let youg et all the input up
    until the newline ( '\n' ) which would be the delimiter
    in the statment above, cin, is where your getting the info
    from it will work on many other type of streams.
    and string is your string variable.

  8. #8
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    sure, why not. i figured since its his first time ever doing anything with strings, he might as well start really easy, just doing cin. but yea getline is definitely useful, i remember not knowing about the getline and having a heck of a time trying to figure out how to enter my first AND last name into a single string. so yea, just to make sure it's really really clear, the reason getline is useful is because it doesn't stop reading input at the first whitespace character (a space or tab or whatever else), it just keeps reading until the newline, even if you type a sentence with all kinds of spaces in it. with cin it just reads in the first word or set of characters, and stops as soon as it hits a space or whatever. so if you input my name cin >> name as "eric daly" it would store "eric" to name. with getline(cin, name, '\n') using "eric daly" it stores "eric daly" to name.
    bla bla bla anyway i talk to much...
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    4
    Ohh, that's pretty cool. Thanks for letting me know that, I'm pretty sure I'll end up using that soon too. Haha. Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM