• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Item Generation Help

FoxGaming

Exalted Member
lol so Tommy has kinda been helping me with this little project however I'm now at point where I'm completely lost.

It compiles and runs however when it comes time to generate the files it does not, I'm not sure if it's due to the fact that the program hasn't read the file correctly or what exactly I'm doing wrong.
I know the code is sloppy and rather noobish(No use of Arrays, and some other things) but it compiles right? haha

anyway, this Program was hopefully written to read a file, Base.txt, and extra data from it, you will have to read Base.txt to really understand what it is. Once it has read the data from the Base file it will prompt the user asking, "How much would you like to increase the stats?"
also, "How many items are to be created?" It will then run a loop and calculate each stat as they are ever increasing, in the loop it will call a function to Write each pass to a file so that it will be able to be executed by the database. Which would be nice as it could create 10+ items with balanced stats in seconds.

The error I'm getting right now is that It opens, It says that the opening of Base.txt was successful however it does not ever say that the read was successful, It will then ask me the questions, which I will answer, It will then crash. I'm not sure what is wrong.

Here are the Files:
Header
Main File
Base.txt
 

Tommy

Founder
Cleaned it up:

qhkl.png


You had a LOT, I mean a lot of pointless crap going on there. If you want to define a function as if it was in a class, use a class... Those functions you had were pointless, they can easily be a 'void' to handle what you're doing. You had too many variables that didn't have a purpose. One last thing is that you didn't have open/close brackets where the for loop is.

I still highly recommend using an array for the column stuff.

Anyway, here is the code:

Code:
#include "stdafx.h"
using namespace std;

double entry;
    int Class;
    int subclass;
    int SoundOverrideSubclass;
    char name;
    int displayid;
    int Quality;    
    int    Flags;
    int FlagsExtra;
    int BuyCount;    
    int BuyPrice;
    int SellPrice;
    int InventoryType;
    int AllowableClass;
    int AllowableRace;
    double ItemLevel;    
    int RequiredLevel;
    int RequiredSkill;    
    int RequiredSkillRank;
    int requiredspell;    
    int requiredhonorrank;
    int RequiredCityRank;    
    int RequiredReputationFaction;
    int RequiredReputationRank;
    int maxcount;    
    int stackable;    
    int ContainerSlots;
    int StatsCount;
    int stat_type1;    
    double stat_value1;
    int stat_type2;
    double stat_value2;
    int stat_type3;
    double stat_value3;    
    int stat_type4;
    double stat_value4;
    int stat_type5;
    double stat_value5;
    int stat_type6;    
    double stat_value6;    
    int stat_type7;    
    double stat_value7;
    int stat_type8;
    double stat_value8;
    int stat_type9;
    double stat_value9;
    int stat_type10;
    double stat_value10;
    int ScalingStatDistribution;
    int ScalingStatValue;
    double dmg_min1;
    double dmg_max1;
    int dmg_type1;
    double dmg_min2;
    double dmg_max2;
    int dmg_type2;
    double armor;    
    int holy_res;
    int fire_res;
    int nature_res;
    int frost_res;    
    int shadow_res;    
    int arcane_res;    
    int delay;    
    int ammo_type;
    int RangedModRange;
    int spellid_1;    
    int spelltrigger_1;    
    int spellcharges_1;
    int spellppmRate_1;
    int spellcooldown_1;
    int spellcategory_1;
    int spellcategorycooldown_1;    
    int spellid_2;    
    int spelltrigger_2;    
    int spellcharges_2;    
    int spellppmRate_2;    
    int spellcooldown_2;    
    int spellcategory_2;
    int spellcategorycooldown_2;    
    int spellid_3;
    int spelltrigger_3;
    int spellcharges_3;
    int spellppmRate_3;
    int spellcooldown_3;
    int spellcategory_3;
    int spellcategorycooldown_3;
    int spellid_4;
    int spelltrigger_4;
    int spellcharges_4;
    int spellppmRate_4;
    int spellcooldown_4;
    int spellcategory_4;
    int spellcategorycooldown_4;    
    int spellid_5;
    int spelltrigger_5;    
    int spellcharges_5;
    int spellppmRate_5;    
    int spellcooldown_5;
    int spellcategory_5;    
    int spellcategorycooldown_5;
    int bonding;
    char description;
    int PageText;    
    int LanguageID;
    int PageMaterial;
    int startquest;
    int lockid;    
    int Material;
    int sheath;    
    int RandomProperty;    
    int RandomSuffix;    
    double block;    
    int itemset;
    int MaxDurability;
    int area;    
    int Map;
    int BagFamily;
    int TotemCategory;    
    int socketColor_1;
    int socketContent_1;
    int socketColor_2;    
    int socketContent_2;
    int socketColor_3;    
    int socketContent_3;
    int socketBonus;
    int GemProperties;
    int RequiredDisenchantSkill;
    int ArmorDamageModifier;    
    int duration;    
    int ItemLimitCategory;    
    int HolidayId;
    char ScriptName;    
    int DisenchantID;
    int FoodType;    
    int minMoneyLoot;
    int maxMoneyLoot;
    int flagsCustom;
    int WDBVerified;

void WriteToFile(double Enter, double ItemL, double stat1, double stat2, double stat3, double stat4, double stat5, double stat6, double stat7, double stat8, double stat9, double stat10, double dmgmin1, double dmgmax1, double dmgmin2, double dmgmax2, double arm, double blk)
{
    ofstream fout;
    fout.open("Output.sql", ios::out, ios::app);
    fout << "INSERT INTO `item_template` " << "("<< Enter << ", " << Class << ", " << subclass << ", ";
    fout << SoundOverrideSubclass << ", `" << name << "`, " << displayid << ", " << Quality << ", ";
    fout << Flags << ", " << FlagsExtra << ", " << BuyCount << ", " << BuyPrice << ", ";
    fout << SellPrice << ", " << InventoryType << ", " << AllowableClass << ", " << AllowableRace << ", ";
    fout << ItemL << ", " << RequiredLevel << ", " << RequiredSkill << ", " << RequiredSkillRank << ", ";    
    fout << requiredspell << ", " << requiredhonorrank << ", " << RequiredCityRank << ", ";    
    fout << RequiredReputationFaction << ", " << RequiredReputationRank << ", " << maxcount << ", ";
    fout << stackable << ", " << ContainerSlots << ", " << StatsCount << ", " << stat_type1 << ", ";    
    fout << stat1 << ", " << stat_type2 << ", " << stat2 << ", " << stat_type3 << ", ";
    fout << stat3 << ", " << stat_type4 << ", " << stat4 << ", " << stat_type5 << ", ";    
    fout << stat5 << ", " << stat_type6 << ", " << stat6 << ", " << stat_type7 << ", ";
    fout << stat7 << ", " << stat_type8 << ", " << stat8 << ", " << stat_type9 << ", ";
    fout << stat9 << ", " << stat_type10 << ", " << stat10 << ", ";
    fout << ScalingStatDistribution << ", " << ScalingStatValue << ", " << dmgmin1 << ", ";
    fout << dmgmax1 << ", " << dmg_type1 << ", " << dmgmin2 << ", " << dmgmax2 << ", ";
    fout << dmg_type2 << ", " << arm << ", " << holy_res << ", " << fire_res << ", ";
    fout << nature_res << ", " << frost_res << ", " << shadow_res << ", " << arcane_res << ", ";
    fout << delay << ", " << ammo_type << ", " << RangedModRange << ", " << spellid_1 << ", ";    
    fout << spelltrigger_1 << ", " << spellcharges_1 << ", " << spellppmRate_1 << ", ";    
    fout << spellcooldown_1 << ", " << spellcategory_1 << ", " << spellcategorycooldown_1 << ", ";    
    fout << spellid_2 << spelltrigger_2 << ", " << spellcharges_2 << ", " << spellppmRate_2 << ", ";    
    fout << spellcooldown_2 << ", " << spellcategory_2 << ", " << spellcategorycooldown_2 << ", ";    
    fout << spellid_3 << spelltrigger_3 << ", " << spellcharges_3 << ", " << spellppmRate_3 << ", ";    
    fout << spellcooldown_3 << ", " << spellcategory_3 << ", " << spellcategorycooldown_3 << ", ";    
    fout << spellid_4 << spelltrigger_4 << ", " << spellcharges_4 << ", " << spellppmRate_4 << ", ";    
    fout << spellcooldown_4 << ", " << spellcategory_4 << ", " << spellcategorycooldown_4 << ", ";
    fout << spellid_5 << spelltrigger_5 << ", " << spellcharges_5 << ", " << spellppmRate_5 << ", ";    
    fout << spellcooldown_5 << ", " << spellcategory_5 << ", " << spellcategorycooldown_5 << ", ";        
    fout << bonding << ", `" << description << "`, " << PageText << ", " << LanguageID << ", ";
    fout << PageMaterial << ", " << startquest << ", " << lockid << ", " << Material << ", " << sheath << ", ";
    fout << RandomProperty  << ", " << RandomSuffix << ", " << blk << ", " << itemset << ", ";
    fout << MaxDurability << ", " << area << ", " << Map << ", " << BagFamily << ", ";
    fout << TotemCategory << ", " << socketColor_1 << ", " << socketContent_1  << ", ";    
    fout << socketColor_2 << ", " << socketContent_2 << ", " << socketColor_3 << ", ";    
    fout << socketContent_3 << ", " << socketBonus << ", " << GemProperties << ", ";
    fout << RequiredDisenchantSkill << ", " << ArmorDamageModifier << ", " << duration << ", ";
    fout << ItemLimitCategory << ", " << HolidayId << ", `" << ScriptName << "`, ";    
    fout << DisenchantID << ", " << FoodType << ", " << minMoneyLoot << ", " << maxMoneyLoot << ", ";
    fout << flagsCustom << ", " << WDBVerified << ");";
    fout << endl << endl << endl;
}

void Calculate()
{
    double increase;
    double generate;
    cout << "What are we increasing the stats by? ";
    cin >> increase;
    cout << "How many items should be generated? ";
    cin >> generate;

    for (generate; generate >= 0; generate--)
    {
        double ItemL = (ItemLevel * increase);
        double stat1 = (stat_value1 * pow(increase, generate--));
        double stat2 = (stat_value2 * pow(increase, generate--));
        double stat3 = (stat_value3 * pow(increase, generate--));
        double stat4 = (stat_value4 * pow(increase, generate--));
        double stat5 = (stat_value5 * pow(increase, generate--));
        double stat6 = (stat_value6 * pow(increase, generate--));
        double stat7 = (stat_value7 * pow(increase, generate--));
        double stat8 = (stat_value8 * pow(increase, generate--));
        double stat9 = (stat_value9 * pow(increase, generate--));
        double stat10 = (stat_value10 * pow(increase, generate--));
        double dmgmin1 = (dmg_min1 * pow(increase, generate--));
        double dmgmax1 = (dmg_max1 * pow(increase, generate--));
        double dmgmin2 = (dmg_min2 * pow(increase, generate--));
        double dmgmax2 = (dmg_max2 * pow(increase, generate--));
        double arm = (armor * pow(increase, generate--));
        double blk = (block * pow(increase, generate--));
        double Enter = (entry + (1 + generate--));
        WriteToFile(Enter, ItemL, stat1, stat2, stat3, stat4, stat5, stat6, stat7, stat8, stat9, stat10, dmgmin1, dmgmax1, dmgmin2, dmgmax2, arm, blk);
    }
}

void GetIncrease()
{
    ofstream read;
    read.open("Base.txt", ios::in);
    if (read.fail())
        cout << "Could not read Base.txt\n";
    if (read.is_open())
        cout << "File Is Open!\n";
    read << entry; 
    read << Class;
    read << subclass;
    read << SoundOverrideSubclass;
    read << name;
    read << displayid;
    read << Quality;    
    read << Flags;
    read << FlagsExtra;
    read << BuyCount;    
    read << BuyPrice;
    read << SellPrice;
    read << InventoryType;
    read << AllowableClass;
    read << AllowableRace;
    read << ItemLevel;    
    read << RequiredLevel;
    read << RequiredSkill;    
    read << RequiredSkillRank;
    read << requiredspell;    
    read << requiredhonorrank;
    read << RequiredCityRank;    
    read << RequiredReputationFaction;
    read << RequiredReputationRank;
    read << maxcount;    
    read << stackable;    
    read << ContainerSlots;
    read << StatsCount;
    read << stat_type1;    
    read << stat_value1;
    read << stat_type2;
    read << stat_value2;
    read << stat_type3;
    read << stat_value3;    
    read << stat_type4;
    read << stat_value4;
    read << stat_type5;
    read << stat_value5;
    read << stat_type6;    
    read << stat_value6;    
    read << stat_type7;    
    read << stat_value7;
    read << stat_type8;
    read << stat_value8;
    read << stat_type9;
    read << stat_value9;
    read << stat_type10;
    read << stat_value10;
    read << ScalingStatDistribution;
    read << ScalingStatValue;
    read << dmg_min1;
    read << dmg_max1;
    read << dmg_type1;
    read << dmg_min2;
    read << dmg_max2;
    read << dmg_type2;
    read << armor;    
    read << holy_res;
    read << fire_res;
    read << nature_res;
    read << frost_res;    
    read << shadow_res;    
    read << arcane_res;    
    read << delay;    
    read << ammo_type;
    read << RangedModRange;
    read << spellid_1;    
    read << spelltrigger_1;    
    read << spellcharges_1;
    read << spellppmRate_1;
    read << spellcooldown_1;
    read << spellcategory_1;
    read << spellcategorycooldown_1;    
    read << spellid_2;    
    read << spelltrigger_2;    
    read << spellcharges_2;    
    read << spellppmRate_2;    
    read << spellcooldown_2;    
    read << spellcategory_2;
    read << spellcategorycooldown_2;    
    read << spellid_3;
    read << spelltrigger_3;
    read << spellcharges_3;
    read << spellppmRate_3;
    read << spellcooldown_3;
    read << spellcategory_3;
    read << spellcategorycooldown_3;
    read << spellid_4;
    read << spelltrigger_4;
    read << spellcharges_4;
    read << spellppmRate_4;
    read << spellcooldown_4;
    read << spellcategory_4;
    read << spellcategorycooldown_4;    
    read << spellid_5;
    read << spelltrigger_5;    
    read << spellcharges_5;
    read << spellppmRate_5;    
    read << spellcooldown_5;
    read << spellcategory_5;    
    read << spellcategorycooldown_5;
    read << bonding;
    read << description;
    read << PageText;    
    read << LanguageID;
    read << PageMaterial;
    read << startquest;
    read << lockid;    
    read << Material;
    read << sheath;    
    read << RandomProperty;    
    read << RandomSuffix;    
    read << block;    
    read << itemset;
    read << MaxDurability;
    read << area;    
    read << Map;
    read << BagFamily;
    read << TotemCategory;    
    read << socketColor_1;
    read << socketContent_1;
    read << socketColor_2;    
    read << socketContent_2;
    read << socketColor_3;    
    read << socketContent_3;
    read << socketBonus;
    read << GemProperties;
    read << RequiredDisenchantSkill;
    read << ArmorDamageModifier;    
    read << duration;    
    read << ItemLimitCategory;    
    read << HolidayId;
    read << ScriptName;    
    read << DisenchantID;
    read << FoodType;    
    read << minMoneyLoot;
    read << maxMoneyLoot;
    read << flagsCustom;
    read << WDBVerified;
    if (read.eof())
        cout << "The Base Data has been read successfully" << endl;
    read.close();
    Calculate();
}

int main()
{
    GetIncrease();

    system("Pause");
    return 0;
}
 

FoxGaming

Exalted Member
I figured as such, now the only error I'm getting is the file portion.
Ve3j5Bx.png

I'm sure it has something to do with my base.txt as it's probably not getting the values entered.
The only reason I've narrowed it down to base.txt is it never display the EoF message.
 

FoxGaming

Exalted Member
I debugged it, it is failing when trying to open Output.sql.

That's definitely interesting, before when i couldn't get it to open Base.txt when I would run the program it would generate Output.sql but not put any data into it since it wasn't opening the Base file. Any guesses why?
 

Tommy

Founder
That's definitely interesting, before when i couldn't get it to open Base.txt when I would run the program it would generate Output.sql but not put any data into it since it wasn't opening the Base file. Any guesses why?

I haven't looked at it, been doing other stuff, lol. I only debugged it to see what was wrong and it stopped at fstream "open failed" if statement check. Well, one reason the Base file couldn't be opened for me is that it didn't automatically create the file if it didn't exist. You should have that code in the source so it doesn't fail if the file doesn't exist.

I thought that was it, so I created Output.sql and it still did the same error when debugging.
 

FoxGaming

Exalted Member
Got it, if it opens the Base.txt but won't open Output.sql even when it's created then I'm not sure what to do. Is there anyway to check if it is reading the basefile properly? like it's actually returning numerical values. And I'm not sure why it won't open Output.sql, my other thought is to write base.txt into a header file and include that header but that would mean those values wouldn't be changeable like they are as .txt file.

Edit:

I did a test to see if it was properly reading the values,

Code:
entry=8
	Class=2
	subclass=8
	SoundOverrideSubclass=-1
	name = SharpenedLongSword
	displayid=4129
	Quality	Flags=2
	FlagsExtra = 0

Code:
 read << entry;
	if (entry == 8)
		cout << "Read Entry Successfully\n";

it did not read the correct value, not only that it changed the top of the basefile to this:
Code:
0000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000 000000
	BuyCount = 1	
	BuyPrice = 0
I really just don't understand what it is doing :Cry:
 
Last edited:

FoxGaming

Exalted Member
Update:

I've updated the code to use arrays and as such I have different errors haha
Updated Code

now here is the Error.

When I debug the program I'm getting this error, though I'm not sure what it's referring too.
If it helps, the function double Calculate is not ever called as it never prompts me for my inputs. Also, it used to be void Calculate. Changed it to double just to see what it did differently

Debug Error:
Code:
First-chance exception at 0x637e1174 in AutoItem V. 2.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x637e1174 in AutoItem V. 2.exe: 0xC0000005: Access violation reading location 0x00000000.
 
Top