Cassandra Posted February 17, 2013 Share Posted February 17, 2013 (edited) Does anyone know how to replicate this in MTA? enum fInfo { fName[40], fRanks[8] } new FactionInfo[MAX_FACTIONS][fInfo]; new bool:fCreated[MAX_FACTIONS]; stock FactionGetFreeSlot() { for(new i = 0; i < MAX_FACTIONS; i++) { if(!fCreated[i]) return i; } return -1; } stock FactionCreate(factionName[], factionRanks[]) { new factionid = FactionGetFreeSlot(); format(FactionInfo[factionid][fName], 40, factionName); //strcpy(FactionInfo[factionid][fName], factionName, 40); for(new i = 0; i < 8; i++) { FactionInfo[factionid][fRanks][i] = factionRanks[i]; } fCreated[factionid] = true; return factionid; } stock FactionLoad(factionID, file[]) { INI_ParseFile(file, "LoadFactionData", .bExtra = true, .extra = factionID); FactionCreate(FactionInfo[factionID][fName], FactionInfo[factionID][fRanks] ); } stock FactionLoadAll() { new index = 0; format(smallstrz, sizeof(smallstrz), #SERVER_NAME "/%s/%d.ini", FactionFolder, index); while(fexist(smallstrz)) { FactionLoad(index, smallstrz); index++; format(smallstrz, sizeof(smallstrz), #SERVER_NAME "/%s/%d.ini", FactionFolder, index); } printf("Factions Loaded: %d", index); } forward LoadFactionData(factionID, name[], value[]); public LoadFactionData(factionID, name[], value[]) { new rank_parse[165]; INI_String("name", FactionInfo[factionID][fName], 40); INI_String("ranks", rank_parse, 165); sscanf(rank_parse, "p<:>iiiiiiii", FactionInfo[factionID][fRanks][0], FactionInfo[factionID][fRanks][1], FactionInfo[factionID][fRanks][2], FactionInfo[factionID][fRanks][3], FactionInfo[factionID][fRanks][4], FactionInfo[factionID][fRanks][5], FactionInfo[factionID][fRanks][6], FactionInfo[factionID][fRanks][7] ); return 1; } stock FactionSave(factionID) { format(smallstrz, sizeof(smallstrz), #SERVER_NAME "/%s/%d.ini", FactionFolder, factionID); new INI:file = INI_Open(smallstrz); new rank_parse[165]; format(rank_parse, sizeof(rank_parse), "%s", FactionInfo[factionID][fRanks][0]); for(new i = 1; i < 8; i++) { format(rank_parse, sizeof(rank_parse), ":%s", FactionInfo[factionID][fRanks][i]); } INI_WriteString(file, "name", FactionInfo[factionID][fName]); INI_WriteString(file, "ranks", rank_parse); INI_Close(file); } stock FactionSaveAll() { new index = 0; for(new i = 0; i < MAX_FACTIONS; i++) { if(fCreated[i]) { FactionSave(index); index++; } } printf("Factions Saved: %d", index); } Edited February 17, 2013 by Guest Link to comment
Anderl Posted February 17, 2013 Share Posted February 17, 2013 - Basic LUA knowledge and.. fileCreate fileOpen fileRead fileWrite fileClose outputChatBox If you just don't have enough patience to create a basic interpreter to make something like INI files, use XML functions instead (if you're going to store a small amount of things). Link to comment
Cassandra Posted February 17, 2013 Author Share Posted February 17, 2013 - Basic LUA knowledge and.. fileCreate fileOpen fileRead fileWrite fileClose outputChatBox If you just don't have enough patience to create a basic interpreter to make something like INI files, use XML functions instead (if you're going to store a small amount of things). I want to know the LUA knowledge of doing that. For example, multi-dimensional array and normal arrays which reference id and stuff. Thanks for your response. Link to comment
Anderl Posted February 17, 2013 Share Posted February 17, 2013 http://www.lua.org/pil/11.2.html I guess that would explain everything. If you need to know something more, you can search on that website. If you don't find something, just come back. Link to comment
Cassandra Posted February 17, 2013 Author Share Posted February 17, 2013 Do you know how to do ENUMERATORS on LUA? Link to comment
Anderl Posted February 17, 2013 Share Posted February 17, 2013 That is not natively possible in LUA, but you can emulate it. Link to comment
Cassandra Posted February 17, 2013 Author Share Posted February 17, 2013 That is not natively possible in LUA, but you can emulate it. Could you show an example? Link to comment
Anderl Posted February 17, 2013 Share Posted February 17, 2013 function enum ( vars ) assert ( vars, "no values in enum declaration" ); for enum_name, int in pairs ( vars ) do _G[enum_name] = int; end end --Example: enum { COLOR_A = 1, COLOR_B = 2, COLOR_C = 3 }; local someValue; function setValue ( str ) if ( str:find ( "a", 0 ) ) then someValue = COLOR_A; elseif ( str:find ( "b", 0 ) ) then someValue = COLOR_B; elseif ( str:find ( "c", 0 ) ) then someValue = COLOR_C; end end setValue ( "b" ); --lets see: if ( someValue == COLOR_A ) then outputChatBox ( "COLOR_A" ); elseif ( someValue == COLOR_B ) then outputChatBox ( "COLOR_B" ); elseif ( someValue == COLOR_C ) then outputChatBox ( "COLOR_C" ); else outputChatBox ( "Something has gone wrong." ); end But you'll still need to add 1, 2, 3, 4, etc. in each value unless you use strings instead of just COLOR_A, COLOR_B and you'd also need to change the for loop in the "enum" function, unlike C/C++ where it automatically sets a number to each value (in order). Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now