Senior Member
|
06-18-2014
, 02:27
Re: Writing into a file
|
#5
|
None of them are working...
PHP Code:
#include <amxmodx> #include <amxmisc> #include <regsysnat>
#define NAME "Weekly question" #define VERSION "1.0" #define AUTHOR "Marius"
new file1[64], file2[64], file3[64], file4[64]; new question[128], answer[16][64], c = 0, point[16], total = 0, percent[16];
public plugin_init() { register_plugin(NAME, VERSION, AUTHOR); exec_files(); }
public exec_files() { get_configsdir(file1, 63); get_configsdir(file2, 63); get_configsdir(file3, 63); get_configsdir(file4, 63); add(file1, sizeof(file1) - 1, "/qofw/questions.ini"); add(file2, sizeof(file2) - 1, "/qofw/answers.txt"); add(file3, sizeof(file3) - 1, "/qofw/stats.log"); add(file4, sizeof(file4) - 1, "/qofw/names.log"); new fHandle = fopen(file1, "rt"); if(!file_exists(file1)) { log_to_file("Questions.log", "%s nu exista", file1); return PLUGIN_HANDLED } if(!file_exists(file2)) { log_to_file("Questions.log", "%s nu exista", file2); return PLUGIN_HANDLED } if(!file_exists(file3)) { log_to_file("Questions.log", "%s nu exista", file3); return PLUGIN_HANDLED } if(!file_exists(file4)) { log_to_file("Questions.log", "%s nu exista", file4); return PLUGIN_HANDLED } fgets(fHandle, question, 127); while(!feof(fHandle)) { c++; fgets(fHandle, answer[c], 63); //Work away comments if(answer[c][0] == ';' || !answer[c][0] || answer[c][0] == ' ' || answer[c][0] == 10) { c--; continue; } } fclose(fHandle) return 1 }
public rs_logged_in(id) { new name[64], name2[64], j = 0; get_user_name(id, name, charsmax(name)); new fHandle = fopen(file4, "rt") while(fgets(fHandle, name2, charsmax(name2))) { if(equali(name2, name)) j++; } if(!j) set_task(10.0, "menu_app", id + 31) fclose(fHandle) }
public menu_app(id) { id = id - 31; new menu, text1[256], text2[256], len; formatex(text1, charsmax(text1), "\rQuestion of week:\w %s", question); text1[strlen(text1) - 1] = 0; text1[strlen(text1) - 2] = 0; menu = menu_create(text1, "menu_handler"); for(new i = 1; i <= c; i++) { len = formatex(text2, charsmax(text2), "\w%s", answer[i]); text2[len - 1] = 0; text2[len - 2] = 0; menu_additem(menu, text2, "", 0); } menu_additem(menu, "I'm indifferent, close this menu", "", 0); menu_display(id, menu, 0); return }
public read_info() { new fHandle = fopen(file3, "rt"); new i = 0, readData[16]; while(!feof(fHandle)) { i++; fgets(fHandle, readData, 15); point[i] = str_to_num(readData); total = total + point[i]; } fclose(fHandle) }
public write_info() { new fHandle = fopen(file2, "w"); new CurrentTime[64], text1[256], text2[256]; get_time("%d.%m.%Y - %H:%M:%S",CurrentTime,63) formatex(text1, charsmax(text1), "###################################### %s ######################################", CurrentTime) //write_file(fHandle, text1, line); //fprintf(fHandle, "%s^n", text1); fputs(fHandle, text1) for(new i = 1; i <= c; i++) { if(point[i] != 0) percent[i] = point[i] * 100 / total; } new len = 0; for(new i = 1; i <= c; i++) { len = formatex(text2, charsmax(text2), answer[i]) len = len + formatex(text2[len], charsmax(text2) - len, " - %i%%%%^n") //write_file(file2, text2, 1); //fprintf(fHandle, "%s^n", text2); fputs(fHandle, text2) } fclose(fHandle) }
public menu_handler(id, menu, item) { new name[64] read_info(); get_user_name(id, name, charsmax(name)) switch(item) { case 0: { if(1 <= c) point[1]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 1: { if(2 <= c) point[2]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 2: { if(3 <= c) point[3]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 3: { if(4 <= c) point[4]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 4: { if(5 <= c) point[5]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 5: { if(6 <= c) point[6]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 6: { if(7 <= c) point[7]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 7: { if(8 <= c) point[8]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } case 8: { if(9 <= c) point[9]++; else { menu_destroy( menu ); return PLUGIN_HANDLED; } } } new fHandle = fopen(file4, "w") add(name, charsmax(name), "^n") //fprintf(fHandle, "%s^n", name) fputs(fHandle, name) menu_destroy(menu); write_info(); info_refresh(); fclose(fHandle) return PLUGIN_HANDLED; }
public info_refresh() { new fHandle = fopen(file3, "w"), text[64]; new line = 0, i = 1; for(i = 1; i <= c; i++) { formatex(text, charsmax(text), "%i^n") fputs(fHandle, text) } fclose(fHandle) }
I checked the permissions of file, is 777, I don't know why isn't working. It's interesting that if I check what's the date when the file was last time modified, it show me that it was modified after plugin execution. Also, formatex is used right, because I used log_to_file to check it... still don't know what is the problem.
Later edit: I tested this plugin locally to, same result..
Last edited by Bladell; 06-18-2014 at 02:40.
|
|