SA-MP Forums Archive
Saving Code in Notepad file - 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)
+--- Thread: Saving Code in Notepad file (/showthread.php?tid=436173)



Saving Code in Notepad file - [DX]Aru12345 - 10.05.2013

Hello.
I have made a script in which when you type /addweapon <Name> <Ammo>, it creates that weapon pickup. Now I want to save that code somewhere. Whenever a player uses that command it creates a notepad file and saves the pickup code there so I can use it later to add the code in my script. How can I do that?


Re: Saving Code in Notepad file - Konewka - 10.05.2013

Use dini or something similar to this include. I also recommend you to play around with SQL, it's way better.


Re: Saving Code in Notepad file - [DX]Aru12345 - 10.05.2013

That's the problem. I don't know how to use it.


Re: Saving Code in Notepad file - Konewka - 10.05.2013

So learn it, it's not that hard as it looks like.


Re: Saving Code in Notepad file - Kwarde - 10.05.2013

You can simply create files.. Here's an example command (using ZCMD!)

pawn Код:
CMD:testfile(playerid, params[])
{
    if (!IsPlayerAdmin(playerid)) return 0; //Only RCON admins can use this command
    new str[128];
    GetPlayerName(playerid, str, MAX_PLAYER_NAME);
    format(str, 30, "%s.txt", str); //username.txt
    new File:usrFile = fopen(str, io_write); //'io_write' : If you use the command again, all previous text will be destroyed
    fwrite(usrFile, "Hello world!\nThis is just some kind of file that doesn't make sense"); //Write into 'usrFile'
    fclose(usrFile); //Close file!!!
    new File:tmpFile = fopen("allcreatedfiles.txt", io_append); //Also create 'allcreatedfiles.txt' ('io_append': When writing, no text will be removed!
    GetPlayerName(playerid, str, MAX_PLAYER_NAME);
    format(str, 128, "%s created a file!\r\n", str); //playername created a file!
    fwrite(tmpFile, str);
    fclose(tmpFile);
    return 1;
}
If 'Kwarde' and 'Player' would use this command (both admins), this would happen (considering that 'scriptfiles' folder exist and that both players are admin:

* 3 files get created: 'Kwarde.txt', 'Player.txt' and 'allcreatedfiles.txt'
* 'Kwarde.txt' and 'Player.txt' would contain:
Hello world!
This is just some kind of file that doesn't make sense
* 'allcreatedfiles.txt' would contain:
Kwarde created a file!
Player created a file!

I hope it makes sense to you


Re: Saving Code in Notepad file - [DX]Aru12345 - 10.05.2013

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
You can simply create files.. Here's an example command (using ZCMD!)

pawn Код:
CMD:testfile(playerid, params[])
{
    if (!IsPlayerAdmin(playerid)) return 0; //Only RCON admins can use this command
    new str[128];
    GetPlayerName(playerid, str, MAX_PLAYER_NAME);
    format(str, 30, "%s.txt", str); //username.txt
    new File:usrFile = fopen(str, io_write); //'io_write' : If you use the command again, all previous text will be destroyed
    fwrite(usrFile, "Hello world!\nThis is just some kind of file that doesn't make sense"); //Write into 'usrFile'
    fclose(usrFile); //Close file!!!
    new File:tmpFile = fopen("allcreatedfiles.txt", io_append); //Also create 'allcreatedfiles.txt' ('io_append': When writing, no text will be removed!
    GetPlayerName(playerid, str, MAX_PLAYER_NAME);
    format(str, 128, "%s created a file!\r\n", str); //playername created a file!
    fwrite(tmpFile, str);
    fclose(tmpFile);
    return 1;
}
If 'Kwarde' and 'Player' would use this command (both admins), this would happen (considering that 'scriptfiles' folder exist and that both players are admin:

* 3 files get created: 'Kwarde.txt', 'Player.txt' and 'allcreatedfiles.txt'
* 'Kwarde.txt' and 'Player.txt' would contain:
Hello world!
This is just some kind of file that doesn't make sense
* 'allcreatedfiles.txt' would contain:
Kwarde created a file!
Player created a file!

I hope it makes sense to you
Very helpful. Thanks