SA-MP Forums Archive
Loading Something From A 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Loading Something From A File (/showthread.php?tid=265223)



Loading Something From A File - Tommy_Mandaz - 30.06.2011

Hello, I want to make it so that everytime I use a command a new set of coords is created and saved in a file, but my question is how can I make my script know to differentiate between two different set of coords? Like say one is x1,y1,z1 and another is x2,y2,z2 how can I make it look for x1,y1,z1 and spawn something there and then also look at x2,y2,z2 and spawn something there...? Thanks a lot for your help.


Re: Loading Something From A File - Shadoww5 - 30.06.2011

Which save system do you want use ?

Dini, Fini, ... ?


Re: Loading Something From A File - Tommy_Mandaz - 30.06.2011

I use yini as my saving and loading system .


Re: Loading Something From A File - Shadoww5 - 30.06.2011

Sorry, I did not really dominate Y_Ini and, therefore, I will use Dini.

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(
strcmp(cmdtext"/saveX"true) == 0)
    {
        new 
Float:Pos[3], str[64], n[24], str2[30];
        
GetPlayerName(playeridnsizeof n);
        
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
        if(!
fexist("File.txt")) { dini_Create("File.txt"); }
        
format(str2sizeof str2"%sX"n);
        
format(strsizeof str"%f"Pos[0]);
        
dini_Set("File.txt"str2str); 
        
format(str2sizeof str2"%sY"n);
        
format(strsizeof str"%f"Pos[1]);
        
dini_Set("File.txt"str2str); 
        
format(str2sizeof str2"%sZ"n);
        
format(strsizeof str"%f"Pos[2]);
        
dini_Set("File.txt"str2str); 
        return 
1;
    }
    if(
strcmp(cmdtext"/goX"true) == 0)
    {
        new 
str[64], n[24], str2[24], Float:Pos[3];
        
GetPlayerName(playeridnsizeof n);
        
format(str2sizeof str2"%sX"n);
        if(!
dini_Isset(str2))
            return 
SendClientMessage(playerid0xFF0000FF"No positions saved.");
        
Pos[0] = dini_Get("File.txt"str2str); 
        
format(str2sizeof str2"%sY"n);
        
Pos[1] = dini_Get("File.txt"str2); 
        
format(str2sizeof str2"%sZ"n);
        
Pos[2] = dini_Get("File.txt"str2);
        
SetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
        
SendClientMessage(playerid0xFFFF00FF"Teleported to saved positions.");
        return 
1;
    }
    return 
0;

Positions will be saved in File.txt this way:

Shadoww5X=Coordinate X
Shadoww5Y=Coordinate Y
Shadoww5Z=Coordinate Z



Re: Loading Something From A File - Tommy_Mandaz - 30.06.2011

What if I save each coord in a different file, how would I load that specific coord from that file?


Re: Loading Something From A File - Shadoww5 - 30.06.2011

Coordinate X will be in Scriptfiles/Accounts/File1.txt.
Y will be in Scriptfiles/Accounts/File2.txt.
Z will be in Scriptfiles/Accounts/File3.txt.

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(
strcmp(cmdtext"/goX"true) == 0)
    {
        new 
Float:Pos[3];
        
Pos[0] = dini_Float("Accounts/File1.txt""Coordinate"); 
        
Pos[1] = dini_Float("Accounts/File2.txt""Coordinate"); 
        
Pos[2] = dini_Float("Accounts/File3.txt""Coordinate"); 
        
SetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
        
SendClientMessage(playerid0xFFFF00FF"Teleported to saved positions.");
        return 
1;
    }
    return 
0;

It also could be like this:

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(
strcmp(cmdtext"/goX"true) == 0)
    {
        
SetPlayerPos(playeriddini_Float("Accounts/File1.txt""Coordinate"), dini_Float("Accounts/File2.txt""Coordinate"), dini_Float("Accounts/File3.txt""Coordinate"));
        
SendClientMessage(playerid0xFFFF00FF"Teleported to saved positions.");
        return 
1;
    }
    return 
0;




Re: Loading Something From A File - Tommy_Mandaz - 30.06.2011

Yea but what if file1, file2, file3 are already created? How can it make a file4 without me having to add file4 in the .pwn?


Re: Loading Something From A File - Shadoww5 - 30.06.2011

Quote:
Originally Posted by Tommy_Mandaz
Посмотреть сообщение
Yea but what if file1, file2, file3 are already created?
No, you have to create them.

But you can put this inside OnGameModeInit:

PHP код:
public OnGameModeInit()
{
    if(!
fexist("Accounts/File1.txt")) { dini_Create("Accounts/File1.txt"); }
    if(!
fexist("Accounts/File2.txt")) { dini_Create("Accounts/File2.txt"); }
    if(!
fexist("Accounts/File3.txt")) { dini_Create("Accounts/File3.txt"); }
    return 
1;

Quote:
Originally Posted by Tommy_Mandaz
Посмотреть сообщение
How can it make a file4 without me having to add file4 in the .pwn?
I didn't understand.


Re: Loading Something From A File - Tommy_Mandaz - 30.06.2011

Like have you seen those scripts where the person types something like: /createhouse and it creates a new file in scriptfiles and saves the coords of the house and then loads the coords and creates a pickup... How do they make it so that it keeps making houses without overwriting another file?


Re: Loading Something From A File - Sasino97 - 30.06.2011

Quote:
Originally Posted by Tommy_Mandaz
Посмотреть сообщение
Like have you seen those scripts where the person types something like: /createhouse and it creates a new file in scriptfiles and saves the coords of the house and then loads the coords and creates a pickup... How do they make it so that it keeps making houses without overwriting another file?
With djson and Y_INI it's easier to save all the users in one file.