View Single Post
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 12-11-2006 , 13:27   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #10

Based on your plugin in another help thread i have make the example for it.

WARNING:This example read ONLY 1 line,if you want read more you need a for or while loop.

I have make 2 plugins,how you can use it,but i prior the second.
I have add some things and have comments some out,which can be removed or uncomment.
Both plugins are tested and work,but are not optimized.

Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> new g_Switch; //new g_TransportAccess; new filename[256]; /*------------------------------------------------------------------------------------------------*/ enum ORIGIN_DATA {  ADMIN_ID[32],  MAP_NAME[32],  Float:ORIGIN[3],    END_DATA } new MSP_Data[33][ORIGIN_DATA]; /*------------------------------------------------------------------------------------------------*/ public plugin_init() {  register_plugin("Multi-Server Portal","0.1","The Specialist");  g_Switch = register_cvar("msp_switch","1");  //g_TransportAccess = register_cvar("msp_jump_access","0");  get_configsdir(filename,255);  format(filename,255,"%s/msp_origins.txt",filename);  register_concmd("msp_create_jump","create_jump_point",ADMIN_LEVEL_A,"Creates An Origin For Portal Where Admin Is");  //register_concmd("msp_add_server","add_server",ADMIN_LEVEL_A,"Adds A Server To The List By IP");  register_clcmd("say /menu","showmenu")     } /*------------------------------------------------------------------------------------------------*/ public showmenu(id){     new menuBody[512],Float:origin[3]         new fp = fopen(filename,"r")         if (fp)     {         fread_raw(fp,MSP_Data[id][ORIGIN_DATA:0],sizeof(MSP_Data[]),1)                 //you can use to copy to another variable(as example here "Float:origin[3]") or use it direct(see in the formatex)         origin[0] = MSP_Data[id][ORIGIN][0]         origin[1] = MSP_Data[id][ORIGIN][1]         origin[2] = MSP_Data[id][ORIGIN][2]                 formatex(menuBody, 511, "This show your origins %f,%f,%f ,%f,%f,%f",origin[0],origin[1],origin[2],MSP_Data[id][ORIGIN][0],MSP_Data[id][ORIGIN][1],MSP_Data[id][ORIGIN][2])         fclose(fp)     }     else formatex(menuBody, 511, "Oh an error with filename: %s",filename)     show_menu(id, MENU_KEY_0, menuBody) } public create_jump_point(id,level,cid) {  if(cmd_access(id , level , cid , 0) && get_pcvar_num(g_Switch))  {   pev(id,pev_origin,MSP_Data[id][ORIGIN]);   get_mapname(MSP_Data[id][MAP_NAME],31);   get_user_authid(id,MSP_Data[id][ADMIN_ID],31);     new FP = fopen(filename,"a+");     if( FP)   {    fwrite_raw(FP,MSP_Data[id][ORIGIN_DATA:0],sizeof(MSP_Data[]),BLOCK_INT)    fclose(FP);    client_print(id,print_chat,"Done")    return 0;   }  }  return 1; }

The second way:
Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> new g_Switch; //new g_TransportAccess; new filename[256]; /*------------------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------------------*/ public plugin_init() {  register_plugin("Multi-Server Portal","0.1","The Specialist");  g_Switch = register_cvar("msp_switch","1");  //g_TransportAccess = register_cvar("msp_jump_access","0");  get_configsdir(filename,255);  format(filename,255,"%s/msp_origins.txt",filename);  register_concmd("msp_create_jump","create_jump_point",ADMIN_LEVEL_A,"Creates An Origin For Portal Where Admin Is");  //register_concmd("msp_add_server","add_server",ADMIN_LEVEL_A,"Adds A Server To The List By IP");  register_clcmd("say /menu","showmenu")     } /*------------------------------------------------------------------------------------------------*/ public showmenu(id){     new menuBody[512],Float:origin[3],origin0[16],origin1[16],origin2[16]         new fp = fopen(filename,"r")         if (fp)     {         fgets(fp,menuBody,511)//I use menuBody,so i not need a second array                 parse(menuBody,origin0,15,origin1,15,origin2,15)         origin[0] = str_to_float(origin0)         origin[1] = str_to_float(origin1)         origin[2] = str_to_float(origin2)                 formatex(menuBody, 511, "This show your origins %f,%f,%f",origin[0],origin[1],origin[2])         fclose(fp)     }     else formatex(menuBody, 511, "Oh an error with filename: %s",filename)     show_menu(id, MENU_KEY_0, menuBody)     } public create_jump_point(id,level,cid) {  if(cmd_access(id , level , cid , 0) && get_pcvar_num(g_Switch))  {   new Float:origin[3],Mapname[32],Authid[32]   pev(id,pev_origin,origin);   get_mapname(Mapname,31);   get_user_authid(id,Authid,31);     new FP = fopen(filename,"a+");     if( FP)   {    fprintf(FP,"%f %f %f %s %s^n",origin[0],origin[1],origin[2],Mapname,Authid)    fclose(FP);    client_print(id,print_chat,"Done")    return 0;   }  }  return 1; }
__________________

Last edited by schnitzelmaker; 12-11-2006 at 13:33.
schnitzelmaker is offline