AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   only wrote one line (https://forums.alliedmods.net/showthread.php?t=240189)

Porta0123 05-10-2014 14:26

only wrote one line
 
hey, i have one problem with my code and... the problem is :

when write some line in commandsdetected only wrote one line and replace the others :|

code
Code:
new filex[930] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTOR)     data() } data() {  new datadir[64];  get_configsdir(datadir, 63);  formatex(filex, charsmax(filex) , "%s/commandsdetected.ini", datadir);  new fileopen = fopen(filex, "r");  if(!fileopen)  {   server_print("[ERROR] El Server No Ha Encontrado [ - %s - ] ; Se Esta Creando una nueva database..", filex);           write_file(filex, "//Commands Detected |name|command");  }  fclose(fileopen); }
Code:
    new name[32], INI[256];     get_user_name(player, name, 31);     formatex( INI , charsmax(INI),"Player Name: %s Command Detected: UpSpeed" , name);     new file = fopen(filex, "wt+");     write_file(filex, INI);     fclose(file);     set_hudmessage(255, 0, 0, -1.0, 0.01)     get_user_name(player, name, 31)     show_hudmessage(0,"Player (%s) UPSpeed commands",  name)

sorry for my enlgish but im spanish and i cant write any post in spanis section

Black Rose 05-10-2014 14:35

Re: only wrote one line
 
write_file() is not part of the C style file functions. It is used alone, without fopen() and fclose().
Take a look at fprintf() instead.

"wt+" (if even supported in AMX Mod X, I don't know since there's nothing about it in the include.) will destroy all contents of the file before writing anything new.
If you want to append to a file that may or may not exist you may use "a".

Quote:

Originally Posted by wt+
Open a text file for both reading and writing. If the file already exists, its contents are destroyed.


Porta0123 05-10-2014 14:52

Re: only wrote one line
 
fixed this :D one problem more... how to make other line , because every time write but no in a new line :S

Quote:

Player Name: Porta0123 Command Detected: SideSpeedPlayer Name: Porta0123 Command Detected: SideSpeed
and i want this:
Quote:

Player Name: Porta0123 Command Detected: SideSpeed
Player Name: Porta0123 Command Detected: SideSpeed

Black Rose 05-10-2014 16:23

Re: only wrote one line
 
Just add ^n to the string to add a newline wherever you want it.


All times are GMT -4. The time now is 09:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.