SA-MP Forums Archive
fwrite help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: fwrite help (/showthread.php?tid=212787)



fwrite help - yarrum3 - 17.01.2011

Hi im trying to make a system that i type /leaveanote [TEXT HERE]. And it will save what you have type into a .txt but i get 1 error here is my command:

Код:
	if(strcmp(cmd, "/leaveanote", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] >= 1337)
			{
				tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /leaveanote [Note(TEXT)]");
					return 1;
				}
				new note;
				note = strvalEx(tmp);
				{
					new File:log = fopen("/adminnotes.txt", io_write);
				    fwrite(log, note);// this is line 27006 the line with the error
    				fclose(log);
					format(string, sizeof(string), "   You have left the note %s", note);
					SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
				}
			}
		}
		return 1;
	}
and here is my error:
Код:
C:\Users\Ryan\Desktop\World Wide RolePlay\gamemodes\WWRP.pwn(27006) : error 035: argument type mismatch (argument 2)



Re: fwrite help - Jefff - 18.01.2011

fwrite writes text so u must convert value to text
pawn Код:
new vstr[64];
valstr(vstr,note);
fwrite(log, vstr);// this is line 27006 the line with the error



Re: fwrite help - yarrum3 - 18.01.2011

Quote:
Originally Posted by Jefff
Посмотреть сообщение
fwrite writes text so u must convert value to text
pawn Код:
new vstr[64];
valstr(vstr,note);
fwrite(log, vstr);// this is line 27006 the line with the error
well i try what you said here is the command:
Код:
	if(strcmp(cmd, "/leaveanote", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] >= 1337)
			{
				tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /leaveanote [Note(TEXT)]");
					return 1;
				}
				new vstr[64];
				new note;
				note = strvalEx(tmp);
				{
					new File:log = fopen("/adminnotes.txt", io_write);
					valstr(vstr,note);
					fwrite(log, vstr);
    				fclose(log);
					format(string, sizeof(string), "   You have left the note %s", vstr);
					SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
				}
			}
		}
		return 1;
	}
and all it dose when i have a look in the .txt file it puts a 0 not the text i type in. how do i fix this.


Re: fwrite help - Grim_ - 18.01.2011

pawn Код:
if( strcmp( cmdtext, "/leavenote", true ) == 0 )
{
   if( PlayerInfo[ playerid ][ pAdmin ] >= 1337 )
   {
      new
         string[ 128 ],
         File: open = fopen( "adminnotes.txt", io_append );
      ;

      format( string, sizeof( string ), "%s", cmdtext[ 11 ] );
      fwrite( open, string );
      fclose( open );
   }
   return 1;
}
This is just the basics of what you need, and doesn't need strtok!

Please note that this is just a sample. You will need to make sure the file exists before writing to it ( in this case ). I would also suggest adding a check to make sure the file is valid.


Re: fwrite help - yarrum3 - 18.01.2011

i still can't get this to work please help


Re: fwrite help - Grim_ - 18.01.2011

Explain the problem you are having in-depth. I cannot magically fix your problem with no background information.