Loading Something From A File
#1

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.
Reply
#2

Which save system do you want use ?

Dini, Fini, ... ?
Reply
#3

I use yini as my saving and loading system .
Reply
#4

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
Reply
#5

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

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;

Reply
#7

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?
Reply
#8

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.
Reply
#9

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)