Premium EnKor 42 Posted September 10, 2022 Premium Share Posted September 10, 2022 (edited) I have .txt file with values: 101 102 but i realy dont know how to get the all values from inside txt Spoiler FILE *fpr; char str[100]; fpr = fopen("test.txt", "r"); if (fpr == NULL) { return; } while (1) { if (fgets(str, 10, fpr) == NULL) break; else printf("%s", str); //file print 101 from inside .txt if (GetRace() == "%s", str) // and i need the value 101, 102 and all values from inside .txt in here { //so this function can work } } fclose(fpr); Any help please Edited September 10, 2022 by EnKor if pc.get_sex() == true and npc.get_sex() == false then npc.purge() end Link to comment Share on other sites More sharing options...
Premium WeedHex 635 Posted September 10, 2022 Premium Share Posted September 10, 2022 (edited) https://www.w3schools.com/python/ref_file_readlines.asp Just search. There are lot of ways, Python is beautiful for these things. Edited September 10, 2022 by WeedHex Link to comment Share on other sites More sharing options...
Premium EnKor 42 Posted September 10, 2022 Author Premium Share Posted September 10, 2022 1 minute ago, WeedHex said: https://www.w3schools.com/python/ref_file_readlines.asp im around this for 2 days now. I dont understand how to make: GetRace() == VALUE_FROM_INSIDE_TXT if pc.get_sex() == true and npc.get_sex() == false then npc.purge() end Link to comment Share on other sites More sharing options...
Premium WeedHex 635 Posted September 10, 2022 Premium Share Posted September 10, 2022 (edited) You want to load mob names from txt file? For doing what? Show it instead of mob_proto data or what, explain please xD Edited September 10, 2022 by WeedHex Link to comment Share on other sites More sharing options...
Premium EnKor 42 Posted September 10, 2022 Author Premium Share Posted September 10, 2022 (edited) to apply fSpecular = 1.0 in all vnums(mobs) from inside txt Spoiler while (1) { if (fgets(str, 10, fpr) == NULL) break; else printf("%s", str); //file print 101 from inside .txt if (GetRace() == "%s", str) // and i need the value 101,1022 etc.... from inside txt in there { fSpecular = 1.0; } } Edited September 10, 2022 by EnKor if pc.get_sex() == true and npc.get_sex() == false then npc.purge() end Link to comment Share on other sites More sharing options...
Premium WeedHex 635 Posted September 10, 2022 Premium Share Posted September 10, 2022 1 minute ago, EnKor said: to aplly fSpecular = 1.0; to all mobs from inside txt Idk, I would do it in c++ only. If there aren't lot of mobs I would skip also the txt reading making a const list/map. Link to comment Share on other sites More sharing options...
Premium EnKor 42 Posted September 10, 2022 Author Premium Share Posted September 10, 2022 Just now, WeedHex said: Idk, I would do it in c++ only. If there aren't lot of mobs I would skip also the txt reading making a const list/map. before and its 100% working. But ugly as hell lol Spoiler if ( GetRace() >= 491 && GetRace() <= 494 || GetRace() == 591 || GetRace() >= 691 && GetRace() <= 693 || GetRace() >= 791 && GetRace() <= 795 || GetRace() >= 1091 && GetRace() <= 1095 || GetRace() == 1304 || GetRace() == 1334 || GetRace() >= 1306 && GetRace() <= 1310 || GetRace() >= 1901 && GetRace() <= 1906 || GetRace() >= 2091 && GetRace() <= 2094 || GetRace() >= 2191 && GetRace() <= 2192 || GetRace() >= 2206 && GetRace() <= 2207 || GetRace() == 2291 || GetRace() >= 2306 && GetRace() <= 2307 || GetRace() >= 2491 && GetRace() <= 2492 || GetRace() >= 2494 && GetRace() <= 2495 || GetRace() >= 2591 && GetRace() <= 2598 || GetRace() >= 3090 && GetRace() <= 3091 || GetRace() >= 3190 && GetRace() <= 3191 || GetRace() >= 3290 && GetRace() <= 3291 || GetRace() >= 3390 && GetRace() <= 3391 || GetRace() >= 3490 && GetRace() <= 3491 || GetRace() >= 3590 && GetRace() <= 3591 || GetRace() >= 3595 && GetRace() <= 3596 || GetRace() >= 3690 && GetRace() <= 3691 || GetRace() >= 3790 && GetRace() <= 3791 || GetRace() >= 3890 && GetRace() <= 3891 || GetRace() >= 3960 && GetRace() <= 3964 || GetRace() >= 5161 && GetRace() <= 5163 || GetRace() == 6005 || GetRace() == 6009 || GetRace() == 6051 || GetRace() == 6109 || GetRace() == 6116 || GetRace() == 6151 || GetRace() == 6193 || GetRace() == 6207 || GetRace() >= 6391 && GetRace() <= 6392 || GetRace() >= 6407 && GetRace() <= 6408 || GetRace() >= 6415 && GetRace() <= 6419 || GetRace() >= 6430 && GetRace() <= 6438 || GetRace() >= 6500 && GetRace() <= 6504 || GetRace() >= 9002 && GetRace() <= 9003 || GetRace() == 9005 || GetRace() == 9008 || GetRace() >= 9012 && GetRace() <= 9014 || GetRace() == 20007 || GetRace() == 20009 || GetRace() >= 20015 && GetRace() <= 20016 || GetRace() >= 20047 && GetRace() <= 20059 || GetRace() == 20091 || GetRace() >= 20104 && GetRace() <= 20125 || GetRace() >= 20201 && GetRace() <= 20252 || GetRace() >= 20254 && GetRace() <= 20255 || GetRace() >= 20257 && GetRace() <= 20277 || GetRace() == 20422 || GetRace() >= 30301 && GetRace() <= 30306 || GetRace() >= 30309 && GetRace() <= 30313 || GetRace() >= 34001 && GetRace() <= 34037 || GetRace() == 34039 || GetRace() >= 34041 && GetRace() <= 34042 || GetRace() >= 34045 && GetRace() <= 34050 || GetRace() >= 34053 && GetRace() <= 34065 || GetRace() >= 34070 && GetRace() <= 34072 || GetRace() >= 34077 && GetRace() <= 34078 || GetRace() >= 34082 && GetRace() <= 34085 || GetRace() >= 34090 && GetRace() <= 34094 || GetRace() == 34097 || GetRace() == 34099 || GetRace() >= 34103 && GetRace() <= 34105 || GetRace() >= 34109 && GetRace() <= 34111 || GetRace() >= 34114 && GetRace() <= 34121 || GetRace() >= 34133 && GetRace() <= 34137 || GetRace() >= 34141 && GetRace() <= 34143 || GetRace() >= 34145 && GetRace() <= 34146 || GetRace() == 34148 || GetRace() >= 34150 && GetRace() <= 34155 ) { fSpecular = 1.0; } After if i get some some help: Spoiler FILE *fpr; char str[100]; fpr = fopen("test.txt", "r"); if (fpr == NULL) { return; } while (1) { if (fgets(str, 10, fpr) == NULL) break; else printf("%s", str); //file print 101 from inside .txt if (GetRace() == "%s", str) // and i need the value 101,1022 etc.... from inside txt in there { fSpecular = 1.0; } } fclose(fpr); if pc.get_sex() == true and npc.get_sex() == false then npc.purge() end Link to comment Share on other sites More sharing options...
Premium WeedHex 635 Posted September 10, 2022 Premium Share Posted September 10, 2022 (edited) 13 hours ago, EnKor said: before and its 100% working. But ugly as hell lol Reveal hidden contents if ( GetRace() >= 491 && GetRace() <= 494 || GetRace() == 591 || GetRace() >= 691 && GetRace() <= 693 || GetRace() >= 791 && GetRace() <= 795 || GetRace() >= 1091 && GetRace() <= 1095 || GetRace() == 1304 || GetRace() == 1334 || GetRace() >= 1306 && GetRace() <= 1310 || GetRace() >= 1901 && GetRace() <= 1906 || GetRace() >= 2091 && GetRace() <= 2094 || GetRace() >= 2191 && GetRace() <= 2192 || GetRace() >= 2206 && GetRace() <= 2207 || GetRace() == 2291 || GetRace() >= 2306 && GetRace() <= 2307 || GetRace() >= 2491 && GetRace() <= 2492 || GetRace() >= 2494 && GetRace() <= 2495 || GetRace() >= 2591 && GetRace() <= 2598 || GetRace() >= 3090 && GetRace() <= 3091 || GetRace() >= 3190 && GetRace() <= 3191 || GetRace() >= 3290 && GetRace() <= 3291 || GetRace() >= 3390 && GetRace() <= 3391 || GetRace() >= 3490 && GetRace() <= 3491 || GetRace() >= 3590 && GetRace() <= 3591 || GetRace() >= 3595 && GetRace() <= 3596 || GetRace() >= 3690 && GetRace() <= 3691 || GetRace() >= 3790 && GetRace() <= 3791 || GetRace() >= 3890 && GetRace() <= 3891 || GetRace() >= 3960 && GetRace() <= 3964 || GetRace() >= 5161 && GetRace() <= 5163 || GetRace() == 6005 || GetRace() == 6009 || GetRace() == 6051 || GetRace() == 6109 || GetRace() == 6116 || GetRace() == 6151 || GetRace() == 6193 || GetRace() == 6207 || GetRace() >= 6391 && GetRace() <= 6392 || GetRace() >= 6407 && GetRace() <= 6408 || GetRace() >= 6415 && GetRace() <= 6419 || GetRace() >= 6430 && GetRace() <= 6438 || GetRace() >= 6500 && GetRace() <= 6504 || GetRace() >= 9002 && GetRace() <= 9003 || GetRace() == 9005 || GetRace() == 9008 || GetRace() >= 9012 && GetRace() <= 9014 || GetRace() == 20007 || GetRace() == 20009 || GetRace() >= 20015 && GetRace() <= 20016 || GetRace() >= 20047 && GetRace() <= 20059 || GetRace() == 20091 || GetRace() >= 20104 && GetRace() <= 20125 || GetRace() >= 20201 && GetRace() <= 20252 || GetRace() >= 20254 && GetRace() <= 20255 || GetRace() >= 20257 && GetRace() <= 20277 || GetRace() == 20422 || GetRace() >= 30301 && GetRace() <= 30306 || GetRace() >= 30309 && GetRace() <= 30313 || GetRace() >= 34001 && GetRace() <= 34037 || GetRace() == 34039 || GetRace() >= 34041 && GetRace() <= 34042 || GetRace() >= 34045 && GetRace() <= 34050 || GetRace() >= 34053 && GetRace() <= 34065 || GetRace() >= 34070 && GetRace() <= 34072 || GetRace() >= 34077 && GetRace() <= 34078 || GetRace() >= 34082 && GetRace() <= 34085 || GetRace() >= 34090 && GetRace() <= 34094 || GetRace() == 34097 || GetRace() == 34099 || GetRace() >= 34103 && GetRace() <= 34105 || GetRace() >= 34109 && GetRace() <= 34111 || GetRace() >= 34114 && GetRace() <= 34121 || GetRace() >= 34133 && GetRace() <= 34137 || GetRace() >= 34141 && GetRace() <= 34143 || GetRace() >= 34145 && GetRace() <= 34146 || GetRace() == 34148 || GetRace() >= 34150 && GetRace() <= 34155 ) { fSpecular = 1.0; } After if i get some some help: Reveal hidden contents FILE *fpr; char str[100]; fpr = fopen("test.txt", "r"); if (fpr == NULL) { return; } while (1) { if (fgets(str, 10, fpr) == NULL) break; else printf("%s", str); //file print 101 from inside .txt if (GetRace() == "%s", str) // and i need the value 101,1022 etc.... from inside txt in there { fSpecular = 1.0; } } fclose(fpr); Ohhh I understood python ahahah Should be a thing like that: char str[buffSize]; FILE* fpr = fopen("test.txt", "r"); if (fpr) { while (fgets(str, buffSize, fpr)) { printf("%s", str); } } fclose(fpr); I don't have time to run the code now sorry, I'm using other formats for these things with new c++. Let me know the output ò_ò if (GetRace() == "%s", str) It's wrong. Edited September 11, 2022 by WeedHex Link to comment Share on other sites More sharing options...
Premium EnKor 42 Posted September 10, 2022 Author Premium Share Posted September 10, 2022 Just now, WeedHex said: Ohhh I understood python ahahah Should be a thing like that: FILE* fpr = fopen("test.txt", "r"); if (fpr) { while (fgets(str, buffSize, fpr)) { printf("%s", str); } } fclose(fpr); I don't have time to run the code now sorry, I'm using other formats for these things with new c++. Let me know the output ò_ò Back allway back to start I can print the value.... But i need to check GetRace() with value from inside .txt if (GetRace() == "%s", str) <<<< something like this if pc.get_sex() == true and npc.get_sex() == false then npc.purge() end Link to comment Share on other sites More sharing options...
Premium WeedHex 635 Posted September 10, 2022 Premium Share Posted September 10, 2022 (edited) 16 minutes ago, EnKor said: Back allway back to start I can print the value.... But i need to check GetRace() with value from inside .txt if (GetRace() == "%s", str) <<<< something like this https://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c GetRace to string, and go for a string comparation. Edited September 10, 2022 by WeedHex Link to comment Share on other sites More sharing options...
Endymion 319 Posted September 10, 2022 Share Posted September 10, 2022 (edited) CMappedFile File; LPCVOID pData; if (!CEterPackManager::Instance().Get(File, szFileName, &pData)) return; CMemoryTextFileLoader textFileLoader; textFileLoader.Bind(File.Size(), pData); for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i) { const std::string& c_rstLine = textFileLoader.GetLineString(i); vRaceSpecular.emplace_back(atoi(c_rstLine.c_str())); } if (vRaceSpecular.find(GetRace()) != vRaceSpecular.cend()) fSpecular = 1.f; Edited September 10, 2022 by Endymion 1 Link to comment Share on other sites More sharing options...
Premium WeedHex 635 Posted September 10, 2022 Premium Share Posted September 10, 2022 7 minutes ago, WeedHex said: https://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c Or you can copy from ItemData.cpp like Endy suggests. I like to solve problems I was following your idea xD Link to comment Share on other sites More sharing options...
Contributor Amun 1898 Posted September 11, 2022 Contributor Share Posted September 11, 2022 (edited) Why not just add specular to your client's and dump_proto's TMobTable and then just set it while building mob_proto? The client's going to load all of it anyway, so I guess that's the most sensical thing to do. Something like this Spoiler typedef struct SMobTable { [...] // mob specular float fSpecular; } TMobTable; Add the same thing to your dump_proto's TMobTable, and then, in bool Set_Proto_Mob_Table Add in the beginning char line[256]; FILE* fp; fopen_s(&fp, "myMobsWithSpecularFile.txt", "r"); if (!fp) return false; // using a map just so we don't have to loop over all mobs to see if we have one std::unordered_map<uint8_t, uint8_t> vMobWithSpecular; while (fgets(line, 256, fp)) { if(line[0] == '\n' || line[0] == '#')//skip empty lines and the ones starting with # continue; vMobWithSpecular.emplace(std::make_pair(atoi(line), 1)); } fclose(fp); And at the end, before return just add: if (vMobWithSpecular.find(mobTable->dwVnum) != vMobWithSpecular.end()) mobTable->fSpecular = 1.0f; else mobTable->fSpecular = 0.0f; Now your locale mob_proto has specular and your client will load all of it automatically when building m_NonPlayerDataMap. You'll just have to make a function to get that specular when you want to use it. Something like this: float CPythonNonPlayer::GetMonsterSpecular(DWORD dwVnum) { const TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->fSpecular; } Edited September 11, 2022 by Amun line[0] to line[0] == '\n' 2 Link to comment Share on other sites More sharing options...
Premium EnKor 42 Posted September 11, 2022 Author Premium Share Posted September 11, 2022 (edited) 56 minutes ago, Amun said: Why not just add specular to your client's and dump_proto's TMobTable and then just set it while building mob_proto? The client's going to load all of it anyway, so I guess that's the most sensical thing to do. Something like this Reveal hidden contents typedef struct SMobTable { [...] // mob specular float fSpecular; } TMobTable; Add the same thing to your dump_proto's TMobTable, and then, in bool Set_Proto_Mob_Table Add in the beginning char line[256]; FILE* fp; fopen_s(&fp, "myMobsWithSpecularFile.txt", "r"); if (!fp) return false; // using a map just so we don't have to loop over all mobs to see if we have one std::unordered_map<uint8_t, uint8_t> vMobWithSpecular; while (fgets(line, 256, fp)) { if(line[0] == '\n' || line[0] == '#')//skip empty lines and the ones starting with # continue; vMobWithSpecular.emplace(std::make_pair(atoi(line), 1)); } fclose(fp); And at the end, before return just add: if (vMobWithSpecular.find(mobTable->dwVnum) != vMobWithSpecular.end()) mobTable->fSpecular = 1.0f; else mobTable->fSpecular = 0.0f; Now your locale mob_proto has specular and your client will load all of it automatically when building m_NonPlayerDataMap. You'll just have to make a function to get that specular when you want to use it. Something like this: float CPythonNonPlayer::GetMonsterSpecular(DWORD dwVnum) { const TMobTable* c_pTable = GetTable(dwVnum); if (!c_pTable) return 0; return c_pTable->fSpecular; } help me understand this please! line[0] returns value inside .txt right? for exemple, if 491 is the only value inside .txt why client cant "convert" line[0] to 491? why this dont work: if (GetRace() == line[0]) Why binary cant see line[0] is 491 ? I only need to make this line... nothing more if (GetRace() == line[0]) ///// if (GetRace() == 491 ) <<<<< this is all i need... Edited September 11, 2022 by EnKor if pc.get_sex() == true and npc.get_sex() == false then npc.purge() end Link to comment Share on other sites More sharing options...
Contributor Amun 1898 Posted September 11, 2022 Contributor Share Posted September 11, 2022 (edited) 4 minutes ago, EnKor said: help me understand this please! line[0] returns value inside .txt right? for exemple, if 491 is the only value inside .txt why this dont work: if (GetRace() == line[0]) Why binary cant see line[0] is 491 ? I only need to make this line... nothing more if (GetRace() == line[0]) ///// if (GetRace() == 491 ) <<<<< this is all i need... Because line[0] isn't 491. Line[0] is 4(actualy, it is either "4", a string, or '4', a char, I didn't look it up), because 4 is the first character on that line. If you'd want it to work that way, you'd actually have to use it like this: if(GetRace() == atoi(line)) { do something } You have to convert the string(because that's what line is) to a number. Line is ALWAYS a string, no matter what the content of that line is. Edited September 11, 2022 by Amun missed small detail 1 Link to comment Share on other sites More sharing options...
Premium EnKor 42 Posted September 11, 2022 Author Premium Share Posted September 11, 2022 2 minutes ago, Amun said: Because line[0] isn't 491, line[0] is 4, because 4 is the first character on that line. If you'd want it to work that way, you'd actually have to use it like this: if(GetRace() == atoi(line)) { do something } You have to convert the string(because that's what line is) to a number. Line is ALWAYS a string, no matter what the content of that line is. "Because line[0] isn't 491, line[0] is 4, because 4 is the first character on that line. " Ok. i got it! if(GetRace() == atoi(line)) <<<< all i need! lol THANK YOU!!!!!! 1 if pc.get_sex() == true and npc.get_sex() == false then npc.purge() end Link to comment Share on other sites More sharing options...
Recommended Posts